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