|
3 | 3 | require "spec_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe Sentry::Rails::CaptureContext do |
6 | | - # Records the current scope's trace_id every time it's called, so specs can |
| 6 | + # Records the current scope's trace context every time it's called, so specs can |
7 | 7 | # compare what a piece of middleware would see at different points in the stack. |
8 | 8 | class CaptureContextSpecProbe |
9 | 9 | def self.captured_trace_ids |
10 | 10 | @captured_trace_ids ||= [] |
11 | 11 | end |
12 | 12 |
|
| 13 | + def self.captured_span_ids |
| 14 | + @captured_span_ids ||= [] |
| 15 | + end |
| 16 | + |
13 | 17 | def initialize(app) |
14 | 18 | @app = app |
15 | 19 | end |
16 | 20 |
|
17 | 21 | def call(env) |
18 | | - self.class.captured_trace_ids << Sentry.get_current_scope.get_trace_context[:trace_id] |
| 22 | + trace_context = Sentry.get_current_scope.get_trace_context |
| 23 | + self.class.captured_trace_ids << trace_context[:trace_id] |
| 24 | + self.class.captured_span_ids << trace_context[:span_id] |
19 | 25 | @app.call(env) |
20 | 26 | end |
21 | 27 | end |
@@ -88,6 +94,7 @@ def propagation_context_in_app(env) |
88 | 94 | context "when composed with CaptureExceptions", type: :request do |
89 | 95 | before do |
90 | 96 | CaptureContextSpecProbe.captured_trace_ids.clear |
| 97 | + CaptureContextSpecProbe.captured_span_ids.clear |
91 | 98 | end |
92 | 99 |
|
93 | 100 | context "without tracing enabled" do |
@@ -125,6 +132,15 @@ def propagation_context_in_app(env) |
125 | 132 | get "/world" |
126 | 133 | end |
127 | 134 |
|
| 135 | + it "points a span_id captured before CaptureExceptions at the started transaction" do |
| 136 | + get "/world" |
| 137 | + |
| 138 | + transaction = transport.events.last |
| 139 | + early_span_id = CaptureContextSpecProbe.captured_span_ids.first |
| 140 | + |
| 141 | + expect(early_span_id).to eq(transaction.contexts.dig(:trace, :span_id)) |
| 142 | + end |
| 143 | + |
128 | 144 | it "keeps the same trace_id from before CaptureExceptions through the started transaction" do |
129 | 145 | get "/world" |
130 | 146 |
|
|
0 commit comments