|
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 |
@@ -98,6 +104,7 @@ def call(env) |
98 | 104 | context "when composed with CaptureExceptions", type: :request do |
99 | 105 | before do |
100 | 106 | CaptureContextSpecProbe.captured_trace_ids.clear |
| 107 | + CaptureContextSpecProbe.captured_span_ids.clear |
101 | 108 | end |
102 | 109 |
|
103 | 110 | context "without tracing enabled" do |
@@ -127,6 +134,15 @@ def call(env) |
127 | 134 | end |
128 | 135 | end |
129 | 136 |
|
| 137 | + it "points a span_id captured before CaptureExceptions at the started transaction" do |
| 138 | + get "/world" |
| 139 | + |
| 140 | + transaction = Sentry.get_current_client.transport.events.last |
| 141 | + early_span_id = CaptureContextSpecProbe.captured_span_ids.first |
| 142 | + |
| 143 | + expect(early_span_id).to eq(transaction.contexts.dig(:trace, :span_id)) |
| 144 | + end |
| 145 | + |
130 | 146 | it "keeps the same trace_id from before CaptureExceptions through the started transaction" do |
131 | 147 | get "/world" |
132 | 148 |
|
|
0 commit comments