Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ad96b24

Browse filesBrowse files
authored
Fix httpx tests (#3810)
1 parent 25d311e commit ad96b24
Copy full SHA for ad96b24

File tree

Expand file treeCollapse file tree

1 file changed

+15
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-15
lines changed

‎tests/integrations/httpx/test_httpx.py

Copy file name to clipboardExpand all lines: tests/integrations/httpx/test_httpx.py
+15-15Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import responses
77

88
import sentry_sdk
9-
from sentry_sdk import capture_message, start_transaction
9+
from sentry_sdk import capture_message, start_span
1010
from sentry_sdk.consts import MATCH_ALL, SPANDATA
1111
from sentry_sdk.integrations.httpx import HttpxIntegration
1212
from tests.conftest import ApproxDict
@@ -26,7 +26,7 @@ def before_breadcrumb(crumb, hint):
2626
url = "http://example.com/"
2727
responses.add(responses.GET, url, status=200)
2828

29-
with start_transaction():
29+
with start_span():
3030
events = capture_events()
3131

3232
if asyncio.iscoroutinefunction(httpx_client.get):
@@ -72,11 +72,10 @@ def test_outgoing_trace_headers(sentry_init, httpx_client, capture_envelopes):
7272
url = "http://example.com/"
7373
responses.add(responses.GET, url, status=200)
7474

75-
with start_transaction(
75+
with start_span(
7676
name="/interactions/other-dogs/new-dog",
7777
op="greeting.sniff",
78-
trace_id="01234567890123456789012345678901",
79-
) as transaction:
78+
) as span:
8079
if asyncio.iscoroutinefunction(httpx_client.get):
8180
response = asyncio.get_event_loop().run_until_complete(
8281
httpx_client.get(url)
@@ -102,7 +101,7 @@ def test_outgoing_trace_headers(sentry_init, httpx_client, capture_envelopes):
102101
(httpx.Client(), httpx.AsyncClient()),
103102
)
104103
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
106105
):
107106
sentry_init(
108107
traces_sample_rate=1.0,
@@ -115,11 +114,10 @@ def test_outgoing_trace_headers_append_to_baggage(
115114
url = "http://example.com/"
116115
responses.add(responses.GET, url, status=200)
117116

118-
with start_transaction(
117+
with start_span(
119118
name="/interactions/other-dogs/new-dog",
120119
op="greeting.sniff",
121-
trace_id="01234567890123456789012345678901",
122-
) as transaction:
120+
):
123121
if asyncio.iscoroutinefunction(httpx_client.get):
124122
response = asyncio.get_event_loop().run_until_complete(
125123
httpx_client.get(url, headers={"baGGage": "custom=data"})
@@ -130,17 +128,18 @@ def test_outgoing_trace_headers_append_to_baggage(
130128
(envelope,) = envelopes
131129
transaction = envelope.get_transaction_event()
132130
request_span = transaction["spans"][-1]
131+
trace_id = transaction["contexts"]["trace"]["trace_id"]
133132

134133
assert response.request.headers[
135134
"sentry-trace"
136135
] == "{trace_id}-{parent_span_id}-{sampled}".format(
137-
trace_id=transaction["contexts"]["trace"]["trace_id"],
136+
trace_id=trace_id,
138137
parent_span_id=request_span["span_id"],
139138
sampled=1,
140139
)
141140
assert (
142141
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")
144143
)
145144

146145

@@ -274,7 +273,7 @@ def test_option_trace_propagation_targets(
274273
integrations=[HttpxIntegration()],
275274
)
276275

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
278277
if asyncio.iscoroutinefunction(httpx_client.get):
279278
asyncio.get_event_loop().run_until_complete(httpx_client.get(url))
280279
else:
@@ -288,7 +287,7 @@ def test_option_trace_propagation_targets(
288287
assert "sentry-trace" not in request_headers
289288

290289

291-
def test_do_not_propagate_outside_transaction(sentry_init, httpx_mock):
290+
def test_propagates_twp_outside_root_span(sentry_init, httpx_mock):
292291
httpx_mock.add_response()
293292

294293
sentry_init(
@@ -301,7 +300,8 @@ def test_do_not_propagate_outside_transaction(sentry_init, httpx_mock):
301300
httpx_client.get("http://example.com/")
302301

303302
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()
305305

306306

307307
@pytest.mark.tests_internal_exceptions
@@ -352,7 +352,7 @@ def test_span_origin(sentry_init, capture_events, httpx_client):
352352
url = "http://example.com/"
353353
responses.add(responses.GET, url, status=200)
354354

355-
with start_transaction(name="test_transaction"):
355+
with start_span(name="test_root_span"):
356356
if asyncio.iscoroutinefunction(httpx_client.get):
357357
asyncio.get_event_loop().run_until_complete(httpx_client.get(url))
358358
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.