|
187 | 187 | end |
188 | 188 | end |
189 | 189 |
|
| 190 | + describe "#get_trace_context" do |
| 191 | + before { perform_basic_setup } |
| 192 | + |
| 193 | + context "with span" do |
| 194 | + let(:transaction) { Sentry::Transaction.new(op: "test") } |
| 195 | + |
| 196 | + before do |
| 197 | + subject.set_span(transaction) |
| 198 | + end |
| 199 | + |
| 200 | + it "returns the span's trace context with dynamic_sampling_context" do |
| 201 | + trace_context = subject.get_trace_context |
| 202 | + expect(trace_context[:trace_id]).to eq(transaction.trace_id) |
| 203 | + expect(trace_context[:span_id]).to eq(transaction.span_id) |
| 204 | + expect(trace_context[:op]).to eq("test") |
| 205 | + expect(trace_context[:dynamic_sampling_context]).to eq(transaction.get_dynamic_sampling_context) |
| 206 | + end |
| 207 | + |
| 208 | + it "prioritizes span over external propagation context" do |
| 209 | + Sentry.register_external_propagation_context do |
| 210 | + ["abc123def456789012345678901234ab", "1234567890abcdef"] |
| 211 | + end |
| 212 | + |
| 213 | + trace_context = subject.get_trace_context |
| 214 | + expect(trace_context[:trace_id]).to eq(transaction.trace_id) |
| 215 | + expect(trace_context[:dynamic_sampling_context]).to eq(transaction.get_dynamic_sampling_context) |
| 216 | + |
| 217 | + Sentry.clear_external_propagation_context |
| 218 | + end |
| 219 | + end |
| 220 | + |
| 221 | + context "with external propagation context" do |
| 222 | + let(:external_trace_id) { "abc123def456789012345678901234ab" } |
| 223 | + let(:external_span_id) { "1234567890abcdef" } |
| 224 | + |
| 225 | + before do |
| 226 | + Sentry.register_external_propagation_context do |
| 227 | + [external_trace_id, external_span_id] |
| 228 | + end |
| 229 | + end |
| 230 | + |
| 231 | + after do |
| 232 | + Sentry.clear_external_propagation_context |
| 233 | + end |
| 234 | + |
| 235 | + it "returns the external propagation context's trace context" do |
| 236 | + trace_context = subject.get_trace_context |
| 237 | + expect(trace_context[:trace_id]).to eq(external_trace_id) |
| 238 | + expect(trace_context[:span_id]).to eq(external_span_id) |
| 239 | + end |
| 240 | + end |
| 241 | + |
| 242 | + context "when external propagation context callback returns nil" do |
| 243 | + before do |
| 244 | + Sentry.register_external_propagation_context do |
| 245 | + nil |
| 246 | + end |
| 247 | + end |
| 248 | + |
| 249 | + after do |
| 250 | + Sentry.clear_external_propagation_context |
| 251 | + end |
| 252 | + |
| 253 | + it "falls back to local propagation context with dynamic_sampling_context" do |
| 254 | + trace_context = subject.get_trace_context |
| 255 | + expect(trace_context[:trace_id]).to eq(subject.propagation_context.trace_id) |
| 256 | + expect(trace_context[:span_id]).to eq(subject.propagation_context.span_id) |
| 257 | + expect(trace_context[:dynamic_sampling_context]).to eq(subject.propagation_context.get_dynamic_sampling_context) |
| 258 | + end |
| 259 | + end |
| 260 | + end |
| 261 | + |
190 | 262 | describe "#apply_to_event" do |
191 | 263 | before { perform_basic_setup } |
192 | 264 |
|
|
300 | 372 | subject.apply_to_event(event) |
301 | 373 |
|
302 | 374 | expect(event.contexts[:trace]).to eq(transaction.get_trace_context) |
| 375 | + expect(event.contexts[:trace]).not_to have_key(:dynamic_sampling_context) |
303 | 376 | expect(event.contexts.dig(:trace, :op)).to eq("foo") |
304 | 377 | expect(event.dynamic_sampling_context).to eq(transaction.get_dynamic_sampling_context) |
305 | 378 | end |
306 | 379 |
|
307 | 380 | it "sets trace context and dynamic_sampling_context from propagation context if there's no span" do |
308 | 381 | subject.apply_to_event(event) |
309 | 382 | expect(event.contexts[:trace]).to eq(subject.propagation_context.get_trace_context) |
| 383 | + expect(event.contexts[:trace]).not_to have_key(:dynamic_sampling_context) |
310 | 384 | expect(event.dynamic_sampling_context).to eq(subject.propagation_context.get_dynamic_sampling_context) |
311 | 385 | end |
312 | 386 |
|
|
0 commit comments