6
6
import responses
7
7
8
8
import sentry_sdk
9
- from sentry_sdk import capture_message , start_transaction
9
+ from sentry_sdk import capture_message , start_span
10
10
from sentry_sdk .consts import MATCH_ALL , SPANDATA
11
11
from sentry_sdk .integrations .httpx import HttpxIntegration
12
12
from tests .conftest import ApproxDict
@@ -26,7 +26,7 @@ def before_breadcrumb(crumb, hint):
26
26
url = "http://example.com/"
27
27
responses .add (responses .GET , url , status = 200 )
28
28
29
- with start_transaction ():
29
+ with start_span ():
30
30
events = capture_events ()
31
31
32
32
if asyncio .iscoroutinefunction (httpx_client .get ):
@@ -72,11 +72,10 @@ def test_outgoing_trace_headers(sentry_init, httpx_client, capture_envelopes):
72
72
url = "http://example.com/"
73
73
responses .add (responses .GET , url , status = 200 )
74
74
75
- with start_transaction (
75
+ with start_span (
76
76
name = "/interactions/other-dogs/new-dog" ,
77
77
op = "greeting.sniff" ,
78
- trace_id = "01234567890123456789012345678901" ,
79
- ) as transaction :
78
+ ) as span :
80
79
if asyncio .iscoroutinefunction (httpx_client .get ):
81
80
response = asyncio .get_event_loop ().run_until_complete (
82
81
httpx_client .get (url )
@@ -102,7 +101,7 @@ def test_outgoing_trace_headers(sentry_init, httpx_client, capture_envelopes):
102
101
(httpx .Client (), httpx .AsyncClient ()),
103
102
)
104
103
def test_outgoing_trace_headers_append_to_baggage (
105
- sentry_init , httpx_client , capture_envelopes
104
+ sentry_init , httpx_client , capture_envelopes , SortedBaggage , # noqa: N803
106
105
):
107
106
sentry_init (
108
107
traces_sample_rate = 1.0 ,
@@ -115,11 +114,10 @@ def test_outgoing_trace_headers_append_to_baggage(
115
114
url = "http://example.com/"
116
115
responses .add (responses .GET , url , status = 200 )
117
116
118
- with start_transaction (
117
+ with start_span (
119
118
name = "/interactions/other-dogs/new-dog" ,
120
119
op = "greeting.sniff" ,
121
- trace_id = "01234567890123456789012345678901" ,
122
- ) as transaction :
120
+ ):
123
121
if asyncio .iscoroutinefunction (httpx_client .get ):
124
122
response = asyncio .get_event_loop ().run_until_complete (
125
123
httpx_client .get (url , headers = {"baGGage" : "custom=data" })
@@ -130,17 +128,18 @@ def test_outgoing_trace_headers_append_to_baggage(
130
128
(envelope ,) = envelopes
131
129
transaction = envelope .get_transaction_event ()
132
130
request_span = transaction ["spans" ][- 1 ]
131
+ trace_id = transaction ["contexts" ]["trace" ]["trace_id" ]
133
132
134
133
assert response .request .headers [
135
134
"sentry-trace"
136
135
] == "{trace_id}-{parent_span_id}-{sampled}" .format (
137
- trace_id = transaction [ "contexts" ][ "trace" ][ " trace_id" ] ,
136
+ trace_id = trace_id ,
138
137
parent_span_id = request_span ["span_id" ],
139
138
sampled = 1 ,
140
139
)
141
140
assert (
142
141
response .request .headers ["baggage" ]
143
- == "custom=data,sentry-trace_id=01234567890123456789012345678901 ,sentry-environment=production,sentry-release=d08ebdb9309e1b004c6f52202de58a09c2268e42,sentry-transaction=/interactions/other-dogs/new-dog,sentry-sample_rate=1.0,sentry-sampled=true"
142
+ == SortedBaggage ( f "custom=data,sentry-trace_id={ trace_id } ,sentry-environment=production,sentry-release=d08ebdb9309e1b004c6f52202de58a09c2268e42,sentry-transaction=/interactions/other-dogs/new-dog,sentry-sample_rate=1.0,sentry-sampled=true")
144
143
)
145
144
146
145
@@ -274,7 +273,7 @@ def test_option_trace_propagation_targets(
274
273
integrations = [HttpxIntegration ()],
275
274
)
276
275
277
- with sentry_sdk .start_transaction (): # Must be in a transaction to propagate headers
276
+ with sentry_sdk .start_span (): # Must be in a root span to propagate headers
278
277
if asyncio .iscoroutinefunction (httpx_client .get ):
279
278
asyncio .get_event_loop ().run_until_complete (httpx_client .get (url ))
280
279
else :
@@ -288,7 +287,7 @@ def test_option_trace_propagation_targets(
288
287
assert "sentry-trace" not in request_headers
289
288
290
289
291
- def test_do_not_propagate_outside_transaction (sentry_init , httpx_mock ):
290
+ def test_propagates_twp_outside_root_span (sentry_init , httpx_mock ):
292
291
httpx_mock .add_response ()
293
292
294
293
sentry_init (
@@ -301,7 +300,8 @@ def test_do_not_propagate_outside_transaction(sentry_init, httpx_mock):
301
300
httpx_client .get ("http://example.com/" )
302
301
303
302
request_headers = httpx_mock .get_request ().headers
304
- assert "sentry-trace" not in request_headers
303
+ assert "sentry-trace" in request_headers
304
+ assert request_headers ["sentry-trace" ] == sentry_sdk .get_traceparent ()
305
305
306
306
307
307
@pytest .mark .tests_internal_exceptions
@@ -352,7 +352,7 @@ def test_span_origin(sentry_init, capture_events, httpx_client):
352
352
url = "http://example.com/"
353
353
responses .add (responses .GET , url , status = 200 )
354
354
355
- with start_transaction (name = "test_transaction " ):
355
+ with start_span (name = "test_root_span " ):
356
356
if asyncio .iscoroutinefunction (httpx_client .get ):
357
357
asyncio .get_event_loop ().run_until_complete (httpx_client .get (url ))
358
358
else :
0 commit comments