From fa9833521c76c83bce901822e0ef03b1def6afa8 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Tue, 29 Nov 2022 13:52:42 +0100 Subject: [PATCH] Expose span_id in Span constructor (#1945) --- CHANGELOG.md | 3 ++- sentry-ruby/lib/sentry/span.rb | 3 ++- sentry-ruby/spec/sentry/span_spec.rb | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9462778ef..74aec6d1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sentry-ruby/lib/sentry/span.rb b/sentry-ruby/lib/sentry/span.rb index fc41c4d37..9ca450e16 100644 --- a/sentry-ruby/lib/sentry/span.rb +++ b/sentry-ruby/lib/sentry/span.rb @@ -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 diff --git a/sentry-ruby/spec/sentry/span_spec.rb b/sentry-ruby/spec/sentry/span_spec.rb index 6758ed67e..b9518a570 100644 --- a/sentry-ruby/spec/sentry/span_spec.rb +++ b/sentry-ruby/spec/sentry/span_spec.rb @@ -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