Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sentry-rails/spec/sentry/rails/capture_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ def self.captured_trace_ids
@captured_trace_ids ||= []
end

def self.captured_span_ids
@captured_span_ids ||= []
end

def initialize(app)
@app = app
end

def call(env)
self.class.captured_trace_ids << Sentry.get_current_scope.get_trace_context[:trace_id]
trace_context = Sentry.get_current_scope.get_trace_context
self.class.captured_trace_ids << trace_context[:trace_id]
self.class.captured_span_ids << trace_context[:span_id]
@app.call(env)
end
end
Expand Down Expand Up @@ -47,6 +53,7 @@ def propagation_context_in_app(env)
context "when composed with CaptureExceptions", type: :request do
before do
CaptureContextSpecProbe.captured_trace_ids.clear
CaptureContextSpecProbe.captured_span_ids.clear
end

context "without tracing enabled" do
Expand Down Expand Up @@ -78,6 +85,15 @@ def propagation_context_in_app(env)
end
end

it "points a span_id captured before CaptureExceptions at the started transaction" do
get "/world"

transaction = transport.events.last
early_span_id = CaptureContextSpecProbe.captured_span_ids.first

expect(early_span_id).to eq(transaction.contexts.dig(:trace, :span_id))
end

it "keeps the same trace_id from before CaptureExceptions through the started transaction" do
get "/world"

Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/lib/sentry/propagation_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def initialize(scope, env = nil)
def transaction_options
{
trace_id: trace_id,
span_id: span_id,
parent_span_id: parent_span_id,
parent_sampled: parent_sampled,
baggage: baggage,
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def propagation_context_in_app(stack_env)

expect(transaction.type).to eq("transaction")
expect(transaction.contexts.dig(:trace, :trace_id)).to eq(context_in_app.trace_id)
expect(transaction.contexts.dig(:trace, :span_id)).to eq(context_in_app.span_id)
expect(transaction.contexts.dig(:trace, :parent_span_id)).to be_nil
end
end
Expand Down
8 changes: 8 additions & 0 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,14 @@
expect(transaction.baggage.mutable).to eq(false)
end

it "gives the Transaction the propagation context's span_id" do
Sentry.configuration.traces_sample_rate = 1.0

transaction = described_class.continue_trace(env, name: "foobar")

expect(transaction.span_id).to eq(Sentry.get_current_scope.propagation_context.span_id)
end

describe "sample_rand propagation" do
before do
Sentry.configuration.traces_sample_rate = 1.0
Expand Down
7 changes: 7 additions & 0 deletions spec/features/trace_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def request_transaction
.to eq(request_transaction.dig("contexts", "trace", "trace_id"))
end

it "points a log emitted before CaptureExceptions at the transaction's span" do
without_trace_propagation { make_request("/trace_context") }

expect(early_middleware_logs.first["span_id"])
.to eq(request_transaction.dig("contexts", "trace", "span_id"))
end

it "continues an incoming distributed trace in a log emitted before CaptureExceptions" do
incoming_trace_id = propagated_trace_id

Expand Down
Loading