Skip to content

Commit 9d2546f

Browse files
committed
Update tests. Forgot to add matching checks in other client
1 parent 25a953e commit 9d2546f

2 files changed

Lines changed: 16 additions & 40 deletions

File tree

sentry_sdk/integrations/httpx.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
7474

7575
if parsed_url is not None:
7676
attributes["url.full"] = parsed_url.url
77-
attributes["url.query"] = parsed_url.query
78-
attributes["url.fragment"] = parsed_url.fragment
77+
if parsed_url.query:
78+
attributes["url.query"] = parsed_url.query
79+
if parsed_url.fragment:
80+
attributes["url.fragment"] = parsed_url.fragment
7981

8082
if should_propagate_trace(client, str(request.url)):
8183
for (

tests/integrations/httpx/test_httpx.py

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import os
2-
import datetime
32
import asyncio
43
from unittest import mock
54

65
import httpx
76
import pytest
8-
from contextlib import contextmanager
97

108
import sentry_sdk
119
from sentry_sdk import capture_message, start_transaction
@@ -604,31 +602,19 @@ def test_no_request_source_if_duration_too_short_legacy(
604602
integrations=[HttpxIntegration()],
605603
traces_sample_rate=1.0,
606604
enable_http_request_source=True,
607-
http_request_source_threshold_ms=100,
605+
# Threshold so high no real request will ever exceed it
606+
http_request_source_threshold_ms=9999999,
608607
)
609608

610609
events = capture_events()
611610

612611
url = "http://example.com/"
613612

614613
with start_transaction(name="test_transaction"):
615-
616-
@contextmanager
617-
def fake_start_span(*args, **kwargs):
618-
with sentry_sdk.start_span(*args, **kwargs) as span:
619-
pass
620-
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
621-
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=99999)
622-
yield span
623-
624-
with mock.patch(
625-
"sentry_sdk.integrations.httpx.legacy_start_span",
626-
fake_start_span,
627-
):
628-
if asyncio.iscoroutinefunction(httpx_client.get):
629-
asyncio.get_event_loop().run_until_complete(httpx_client.get(url))
630-
else:
631-
httpx_client.get(url)
614+
if asyncio.iscoroutinefunction(httpx_client.get):
615+
asyncio.get_event_loop().run_until_complete(httpx_client.get(url))
616+
else:
617+
httpx_client.get(url)
632618

633619
(event,) = events
634620

@@ -656,31 +642,19 @@ def test_request_source_if_duration_over_threshold_legacy(
656642
integrations=[HttpxIntegration()],
657643
traces_sample_rate=1.0,
658644
enable_http_request_source=True,
659-
http_request_source_threshold_ms=100,
645+
# Threshold is low so any request will exceed it
646+
http_request_source_threshold_ms=0,
660647
)
661648

662649
events = capture_events()
663650

664651
url = "http://example.com/"
665652

666653
with start_transaction(name="test_transaction"):
667-
668-
@contextmanager
669-
def fake_start_span(*args, **kwargs):
670-
with sentry_sdk.start_span(*args, **kwargs) as span:
671-
pass
672-
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
673-
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=100001)
674-
yield span
675-
676-
with mock.patch(
677-
"sentry_sdk.integrations.httpx.legacy_start_span",
678-
fake_start_span,
679-
):
680-
if asyncio.iscoroutinefunction(httpx_client.get):
681-
asyncio.get_event_loop().run_until_complete(httpx_client.get(url))
682-
else:
683-
httpx_client.get(url)
654+
if asyncio.iscoroutinefunction(httpx_client.get):
655+
asyncio.get_event_loop().run_until_complete(httpx_client.get(url))
656+
else:
657+
httpx_client.get(url)
684658

685659
(event,) = events
686660

0 commit comments

Comments
 (0)