Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scripts/populate_tox/package_dependencies.jsonl

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions sentry_sdk/integrations/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_http_request_source,
has_span_streaming_enabled,
propagate_trace_headers,
Expand Down Expand Up @@ -128,6 +129,23 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
with capture_internal_exceptions():
add_http_request_source(span)

breadcrumb_data = {
SPANDATA.HTTP_METHOD: request.method,
SPANDATA.HTTP_STATUS_CODE: rv.status_code,
"reason": rv.reason_phrase,
}

if parsed_url and (not is_span_streaming_enabled or should_send_default_pii()):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_not_span_streaming_enabled part is there for continuity in transaction mode, where we don't care about should_send_default_pii before setting breadcrumb data.

breadcrumb_data.update(
{
"url": parsed_url.url,
SPANDATA.HTTP_QUERY: parsed_url.query,
SPANDATA.HTTP_FRAGMENT: parsed_url.fragment,
}
)

add_http_breadcrumb(rv.status_code, breadcrumb_data)

return rv

Client.send = send # type: ignore
Expand Down Expand Up @@ -220,6 +238,22 @@ async def send(
with capture_internal_exceptions():
add_http_request_source(span)

breadcrumb_data = {
SPANDATA.HTTP_METHOD: request.method,
SPANDATA.HTTP_STATUS_CODE: rv.status_code,
"reason": rv.reason_phrase,
}
if parsed_url and (not is_span_streaming_enabled or should_send_default_pii()):
breadcrumb_data.update(
{
"url": parsed_url.url,
SPANDATA.HTTP_QUERY: parsed_url.query,
SPANDATA.HTTP_FRAGMENT: parsed_url.fragment,
}
)

add_http_breadcrumb(rv.status_code, breadcrumb_data)

return rv

AsyncClient.send = send # type: ignore
33 changes: 33 additions & 0 deletions sentry_sdk/integrations/httpx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_http_request_source,
has_span_streaming_enabled,
propagate_trace_headers,
Expand Down Expand Up @@ -129,6 +130,22 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
with capture_internal_exceptions():
add_http_request_source(span)

breadcrumb_data = {
SPANDATA.HTTP_METHOD: request.method,
SPANDATA.HTTP_STATUS_CODE: rv.status_code,
"reason": rv.reason_phrase,
}
if parsed_url and (not is_span_streaming_enabled or should_send_default_pii()):
breadcrumb_data.update(
{
"url": parsed_url.url,
SPANDATA.HTTP_QUERY: parsed_url.query,
SPANDATA.HTTP_FRAGMENT: parsed_url.fragment,
}
)

add_http_breadcrumb(rv.status_code, breadcrumb_data)

return rv

Client.send = send # type: ignore
Expand Down Expand Up @@ -222,6 +239,22 @@ async def send(
with capture_internal_exceptions():
add_http_request_source(span)

breadcrumb_data = {
SPANDATA.HTTP_METHOD: request.method,
SPANDATA.HTTP_STATUS_CODE: rv.status_code,
"reason": rv.reason_phrase,
}
if parsed_url and (not is_span_streaming_enabled or should_send_default_pii()):
breadcrumb_data.update(
{
"url": parsed_url.url,
SPANDATA.HTTP_QUERY: parsed_url.query,
SPANDATA.HTTP_FRAGMENT: parsed_url.fragment,
}
)

add_http_breadcrumb(rv.status_code, breadcrumb_data)

return rv

AsyncClient.send = send # type: ignore
2 changes: 2 additions & 0 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def maybe_create_breadcrumbs_from_span(
if span.op == OP.HTTP_CLIENT and span.origin not in (
"auto.http.aiohttp",
"auto.http.pyreqwest",
"auto.http.httpx",
"auto.http.httpx2",
):
level = None
status_code = span._data.get(SPANDATA.HTTP_STATUS_CODE)
Expand Down
5 changes: 4 additions & 1 deletion tests/integrations/httpx/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def before_breadcrumb(crumb, hint):
crumb["data"]["extra"] = "foo"
return crumb

sentry_init(integrations=[HttpxIntegration()], before_breadcrumb=before_breadcrumb)
sentry_init(
integrations=[HttpxIntegration()],
before_breadcrumb=before_breadcrumb,
)

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

Expand Down
5 changes: 4 additions & 1 deletion tests/integrations/httpx2/test_httpx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def before_breadcrumb(crumb, hint):
crumb["data"]["extra"] = "foo"
return crumb

sentry_init(integrations=[Httpx2Integration()], before_breadcrumb=before_breadcrumb)
sentry_init(
integrations=[Httpx2Integration()],
before_breadcrumb=before_breadcrumb,
)

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

Expand Down
Loading