11import pytest
22from unittest import mock
33
4- import sentry_sdk
54from sentry_sdk import (
65 capture_exception ,
76 continue_trace ,
109 get_current_span ,
1110 get_traceparent ,
1211 is_initialized ,
13- start_transaction ,
12+ start_span ,
1413 set_tags ,
1514 get_global_scope ,
1615 get_current_scope ,
@@ -44,23 +43,23 @@ def test_get_current_span_current_scope(sentry_init):
4443
4544
4645@pytest .mark .forked
47- def test_get_current_span_current_scope_with_transaction (sentry_init ):
46+ def test_get_current_span_current_scope_with_span (sentry_init ):
4847 sentry_init ()
4948
5049 assert get_current_span () is None
5150
52- with start_transaction () as new_transaction :
53- assert get_current_span () == new_transaction
51+ with start_span () as new_span :
52+ assert get_current_span () == new_span
5453
5554
5655@pytest .mark .forked
5756def test_traceparent_with_tracing_enabled (sentry_init ):
5857 sentry_init (traces_sample_rate = 1.0 )
5958
60- with start_transaction () as transaction :
59+ with start_span () as span :
6160 expected_traceparent = "%s-%s-1" % (
62- transaction .trace_id ,
63- transaction .span_id ,
61+ span .trace_id ,
62+ span .span_id ,
6463 )
6564 assert get_traceparent () == expected_traceparent
6665
@@ -78,51 +77,51 @@ def test_traceparent_with_tracing_disabled(sentry_init):
7877
7978
8079@pytest .mark .forked
81- def test_baggage_with_tracing_disabled (sentry_init ):
80+ def test_baggage_with_tracing_disabled (sentry_init , SortedBaggage ):
8281 sentry_init (release = "1.0.0" , environment = "dev" )
8382 propagation_context = get_isolation_scope ()._propagation_context
8483 expected_baggage = (
8584 "sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0" .format (
8685 propagation_context .trace_id
8786 )
8887 )
89- assert get_baggage () == expected_baggage
88+ assert get_baggage () == SortedBaggage ( expected_baggage )
9089
9190
9291@pytest .mark .forked
93- def test_baggage_with_tracing_enabled (sentry_init ):
92+ def test_baggage_with_tracing_enabled (sentry_init , SortedBaggage ):
9493 sentry_init (traces_sample_rate = 1.0 , release = "1.0.0" , environment = "dev" )
95- with start_transaction () as transaction :
94+ with start_span () as span :
9695 expected_baggage = "sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0,sentry-sample_rate=1.0,sentry-sampled={}" .format (
97- transaction .trace_id , "true" if transaction .sampled else "false"
96+ span .trace_id , "true" if span .sampled else "false"
9897 )
99- assert get_baggage () == expected_baggage
98+ assert get_baggage () == SortedBaggage ( expected_baggage )
10099
101100
102101@pytest .mark .forked
103102def test_continue_trace (sentry_init ):
104- sentry_init ()
103+ sentry_init (traces_sample_rate = 1.0 )
105104
106105 trace_id = "471a43a4192642f0b136d5159a501701"
107106 parent_span_id = "6e8f22c393e68f19"
108107 parent_sampled = 1
109- transaction = continue_trace (
108+
109+ with continue_trace (
110110 {
111111 "sentry-trace" : "{}-{}-{}" .format (trace_id , parent_span_id , parent_sampled ),
112112 "baggage" : "sentry-trace_id=566e3688a61d4bc888951642d6f14a19" ,
113113 },
114- name = "some name" ,
115- )
116- with start_transaction (transaction ):
117- assert transaction .name == "some name"
118-
119- propagation_context = get_isolation_scope ()._propagation_context
120- assert propagation_context .trace_id == transaction .trace_id == trace_id
121- assert propagation_context .parent_span_id == parent_span_id
122- assert propagation_context .parent_sampled == parent_sampled
123- assert propagation_context .dynamic_sampling_context == {
124- "trace_id" : "566e3688a61d4bc888951642d6f14a19"
125- }
114+ ):
115+ with start_span (name = "some name" ) as span :
116+ assert span .name == "some name"
117+
118+ propagation_context = get_isolation_scope ()._propagation_context
119+ assert propagation_context .trace_id == span .trace_id == trace_id
120+ assert propagation_context .parent_span_id == parent_span_id
121+ assert propagation_context .parent_sampled == parent_sampled
122+ assert propagation_context .dynamic_sampling_context == {
123+ "trace_id" : "566e3688a61d4bc888951642d6f14a19"
124+ }
126125
127126
128127@pytest .mark .forked
0 commit comments