11import pytest
22
3- from sentry_sdk import Hub
3+ from sentry_sdk import Hub , capture_message
4+ from sentry_sdk .tracing import Span
45
56
67@pytest .mark .parametrize ("sample_rate" , [0.0 , 1.0 ])
@@ -26,3 +27,35 @@ def test_basic(sentry_init, capture_events, sample_rate):
2627 assert parent_span ["transaction" ] == "hi"
2728 else :
2829 assert not events
30+
31+
32+ def test_continue_from_headers (sentry_init , capture_events ):
33+ sentry_init (traces_sample_rate = 1.0 )
34+ events = capture_events ()
35+
36+ with Hub .current .trace (transaction = "hi" ):
37+ with Hub .current .span () as old_span :
38+ headers = dict (Hub .current .iter_trace_propagation_headers ())
39+
40+ span = Span .continue_from_headers (headers )
41+ assert span is not None
42+ assert span .trace_id == old_span .trace_id
43+
44+ with Hub .current .trace (span ):
45+ with Hub .current .configure_scope () as scope :
46+ scope .transaction = "ho"
47+
48+ capture_message ("hello" )
49+
50+ trace1 , message , trace2 = events
51+
52+ assert trace1 ["transaction" ] == "hi"
53+ assert trace2 ["transaction" ] == "ho"
54+
55+ assert (
56+ trace1 ["contexts" ]["trace" ]["trace_id" ]
57+ == trace2 ["contexts" ]["trace" ]["trace_id" ]
58+ == span .trace_id
59+ == message ["contexts" ]["trace" ]["trace_id" ]
60+ )
61+ assert message ["message" ] == "hello"
0 commit comments