Skip to content

Commit

Permalink
Expose span_id in Span constructor (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored Nov 29, 2022
1 parent a62fb2d commit fa98335
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

### Features

- Expose `span_id` in `Span` constructor [#1945](https://github.com/getsentry/sentry-ruby/pull/1945)
- Add OpenTelemetry support with new `sentry-opentelemetry` gem
- Add `config.instrumenter` to switch between sentry and otel instrumentation [#1944](https://github.com/getsentry/sentry-ruby/pull/1944)
- Add `config.instrumenter` to switch between `:sentry` and `:otel` instrumentation [#1944](https://github.com/getsentry/sentry-ruby/pull/1944)

## 5.6.0

Expand Down
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ def initialize(
op: nil,
status: nil,
trace_id: nil,
span_id: nil,
parent_span_id: nil,
sampled: nil,
start_timestamp: nil,
timestamp: nil
)
@trace_id = trace_id || SecureRandom.uuid.delete("-")
@span_id = SecureRandom.hex(8)
@span_id = span_id || SecureRandom.hex(8)
@parent_span_id = parent_span_id
@sampled = sampled
@start_timestamp = start_timestamp || Sentry.utc_now.to_f
Expand Down
8 changes: 8 additions & 0 deletions sentry-ruby/spec/sentry/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@
expect(span_2.transaction).to eq(subject.transaction)
end

it "initializes a new child Span with explicit span id" do
span_id = SecureRandom.hex(8)
new_span = subject.start_child(op: "foo", span_id: span_id)

expect(new_span.op).to eq("foo")
expect(new_span.span_id).to eq(span_id)
end

context "when the parent span has a span_recorder" do
subject do
# inherits the span recorder from the transaction
Expand Down

0 comments on commit fa98335

Please sign in to comment.