1313import pytest
1414
1515import sentry_sdk
16- import sentry_sdk .client
16+ from sentry_sdk .transport import Transport
17+ from sentry_sdk .envelope import Envelope
18+
19+
20+ class TransportWithOptions (Transport ):
21+ """Transport does not pass in the options so we need this here"""
22+
23+ def __init__ (self , options = None ):
24+ Transport .__init__ (self , options )
25+
26+ def capture_envelope (self , _ : Envelope ) -> None :
27+ """No-op capture_envelope for tests"""
28+ pass
1729
1830
1931def test_dsc_head_of_trace (sentry_init , capture_envelopes ):
@@ -22,10 +34,11 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes):
2234 and sends a transaction event to Sentry.
2335 """
2436 sentry_init (
25- dsn = "https://mysecret@bla .ingest.sentry.io/12312012" ,
37+ dsn = "https://mysecret@o1234 .ingest.sentry.io/12312012" ,
26382739 environment = "canary" ,
2840 traces_sample_rate = 1.0 ,
41+ transport = TransportWithOptions ,
2942 )
3043 envelopes = capture_envelopes ()
3144
@@ -45,6 +58,10 @@ def test_dsc_head_of_trace(sentry_init, capture_envelopes):
4558 assert type (envelope_trace_header ["public_key" ]) == str
4659 assert envelope_trace_header ["public_key" ] == "mysecret"
4760
61+ assert "org_id" in envelope_trace_header
62+ assert type (envelope_trace_header ["org_id" ]) == str
63+ assert envelope_trace_header ["org_id" ] == "1234"
64+
4865 assert "sample_rate" in envelope_trace_header
4966 assert type (envelope_trace_header ["sample_rate" ]) == str
5067 assert envelope_trace_header ["sample_rate" ] == "1.0"
@@ -72,10 +89,11 @@ def test_dsc_continuation_of_trace(sentry_init, capture_envelopes):
7289 Our service is continuing the trace and sends a transaction event to Sentry.
7390 """
7491 sentry_init (
75- dsn = "https://mysecret@bla .ingest.sentry.io/12312012" ,
92+ dsn = "https://mysecret@o1234 .ingest.sentry.io/12312012" ,
76937794 environment = "canary" ,
7895 traces_sample_rate = 1.0 ,
96+ transport = TransportWithOptions ,
7997 )
8098 envelopes = capture_envelopes ()
8199
@@ -149,10 +167,11 @@ def my_traces_sampler(sampling_context):
149167 return 0.25
150168
151169 sentry_init (
152- dsn = "https://mysecret@bla .ingest.sentry.io/12312012" ,
170+ dsn = "https://mysecret@o1234 .ingest.sentry.io/12312012" ,
153171154172 environment = "canary" ,
155173 traces_sampler = my_traces_sampler ,
174+ transport = TransportWithOptions ,
156175 )
157176 envelopes = capture_envelopes ()
158177
@@ -219,9 +238,10 @@ def test_dsc_issue(sentry_init, capture_envelopes):
219238 Our service is a standalone service that does not have tracing enabled. Just uses Sentry for error reporting.
220239 """
221240 sentry_init (
222- dsn = "https://mysecret@bla .ingest.sentry.io/12312012" ,
241+ dsn = "https://mysecret@o1234 .ingest.sentry.io/12312012" ,
223242224243 environment = "canary" ,
244+ transport = TransportWithOptions ,
225245 )
226246 envelopes = capture_envelopes ()
227247
@@ -244,6 +264,10 @@ def test_dsc_issue(sentry_init, capture_envelopes):
244264 assert type (envelope_trace_header ["public_key" ]) == str
245265 assert envelope_trace_header ["public_key" ] == "mysecret"
246266
267+ assert "org_id" in envelope_trace_header
268+ assert type (envelope_trace_header ["org_id" ]) == str
269+ assert envelope_trace_header ["org_id" ] == "1234"
270+
247271 assert "sample_rate" not in envelope_trace_header
248272
249273 assert "sampled" not in envelope_trace_header
@@ -265,10 +289,11 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes):
265289 Envelopes containing errors also have the same DSC than the transaction envelopes.
266290 """
267291 sentry_init (
268- dsn = "https://mysecret@bla .ingest.sentry.io/12312012" ,
292+ dsn = "https://mysecret@o1234 .ingest.sentry.io/12312012" ,
269293270294 environment = "canary" ,
271295 traces_sample_rate = 1.0 ,
296+ transport = TransportWithOptions ,
272297 )
273298 envelopes = capture_envelopes ()
274299
@@ -294,6 +319,10 @@ def test_dsc_issue_with_tracing(sentry_init, capture_envelopes):
294319 assert type (envelope_trace_header ["public_key" ]) == str
295320 assert envelope_trace_header ["public_key" ] == "mysecret"
296321
322+ assert "org_id" in envelope_trace_header
323+ assert type (envelope_trace_header ["org_id" ]) == str
324+ assert envelope_trace_header ["org_id" ] == "1234"
325+
297326 assert "sample_rate" in envelope_trace_header
298327 assert envelope_trace_header ["sample_rate" ] == "1.0"
299328 assert type (envelope_trace_header ["sample_rate" ]) == str
@@ -332,10 +361,11 @@ def test_dsc_issue_twp(sentry_init, capture_envelopes, traces_sample_rate):
332361 (This test would be service B in this scenario)
333362 """
334363 sentry_init (
335- dsn = "https://mysecret@bla .ingest.sentry.io/12312012" ,
364+ dsn = "https://mysecret@o1234 .ingest.sentry.io/12312012" ,
336365337366 environment = "canary" ,
338367 traces_sample_rate = traces_sample_rate ,
368+ transport = TransportWithOptions ,
339369 )
340370 envelopes = capture_envelopes ()
341371
0 commit comments