Skip to content

Commit a632a81

Browse files
ericapisaniclaude
andcommitted
fix(httpx): Always set span attributes even when request raises
Wrap real_send in try/finally so span attributes (URL, method, etc.) are always flushed to the span. Previously an exception from real_send would leave the span with no attributes at all. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 19eeac5 commit a632a81

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

sentry_sdk/integrations/httpx.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
9595
else:
9696
request.headers[key] = value
9797

98-
rv = real_send(self, request, **kwargs)
98+
try:
99+
rv = real_send(self, request, **kwargs)
99100

100-
streamed_span.status = "error" if rv.status_code >= 400 else "ok"
101-
attributes["http.response.status_code"] = rv.status_code
102-
103-
streamed_span.set_attributes(attributes)
101+
streamed_span.status = "error" if rv.status_code >= 400 else "ok"
102+
attributes["http.response.status_code"] = rv.status_code
103+
finally:
104+
streamed_span.set_attributes(attributes)
104105

105106
# Needs to happen within the context manager as we want to attach the
106107
# final data before the span finishes and is sent for ingesting.

0 commit comments

Comments
 (0)