@@ -198,6 +198,32 @@ def traces_sampler(sampling_context):
198198 assert span ["attributes" ]["my_attribute" ] == "my_value"
199199
200200
201+ def test_sampling_context (sentry_init , capture_envelopes ):
202+ def traces_sampler (sampling_context ):
203+ assert "transaction_context" in sampling_context
204+ assert "trace_id" in sampling_context ["transaction_context" ]
205+ assert "span_id" in sampling_context ["transaction_context" ]
206+ assert "parent_span_id" in sampling_context ["transaction_context" ]
207+ assert "parent_sampled" in sampling_context
208+ assert "attributes" in sampling_context
209+ return 1.0
210+
211+ sentry_init (
212+ traces_sampler = traces_sampler ,
213+ _experiments = {"trace_lifecycle" : "stream" },
214+ )
215+
216+ events = capture_envelopes ()
217+
218+ with sentry_sdk .traces .start_span (name = "span" ):
219+ ...
220+
221+ sentry_sdk .get_client ().flush ()
222+ spans = envelopes_to_spans (events )
223+
224+ assert len (spans ) == 1
225+
226+
201227def test_span_attributes (sentry_init , capture_envelopes ):
202228 sentry_init (
203229 traces_sample_rate = 1.0 ,
@@ -608,6 +634,28 @@ def test_set_span_source(sentry_init, capture_envelopes):
608634 assert span ["attributes" ]["sentry.span.source" ] == SegmentSource .TASK .value
609635
610636
637+ def test_set_span_origin (sentry_init , capture_envelopes ):
638+ sentry_init (
639+ traces_sample_rate = 1.0 ,
640+ _experiments = {"trace_lifecycle" : "stream" },
641+ )
642+
643+ events = capture_envelopes ()
644+
645+ with sentry_sdk .traces .start_span (name = "span" ) as span :
646+ span .set_origin ("redis" )
647+ assert span .get_attributes ()["sentry.origin" ] == "redis"
648+
649+ sentry_sdk .get_client ().flush ()
650+ spans = envelopes_to_spans (events )
651+
652+ assert len (spans ) == 1
653+ (span ,) = spans
654+
655+ assert span ["name" ] == "span"
656+ assert span ["attributes" ]["sentry.origin" ] == "redis"
657+
658+
611659def test_transport_format (sentry_init , capture_envelopes ):
612660 sentry_init (
613661 server_name = "test-server" ,
0 commit comments