Skip to content

fix(httpx): Always set span attributes even when request raises

a632a81
Select commit
Loading
Failed to load commit list.
Merged

feat(httpx): Migrate to span first #6084

fix(httpx): Always set span attributes even when request raises
a632a81
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: find-bugs completed Apr 21, 2026 in 4m 34s

1 issue

find-bugs: Found 1 issue (1 medium)

Medium

Missing try/finally in async httpx span streaming path causes attributes to be lost on exceptions - `sentry_sdk/integrations/httpx.py:208-213`

In the async httpx client's span streaming path (lines 208-213), if await real_send() raises an exception, the attributes dictionary containing URL information (url.full, url.query, url.fragment) will never be set on the span. The sync client implementation correctly uses a try/finally block (lines 98-109 in the full file) to ensure set_attributes() is called even when exceptions occur. This inconsistency causes incomplete span data when async HTTP requests fail.


Duration: 4m 30s · Tokens: 3.3M in / 26.4k out · Cost: $6.52 (+extraction: $0.01, +fix_gate: $0.00)

Annotations

Check warning on line 213 in sentry_sdk/integrations/httpx.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: find-bugs

Missing try/finally in async httpx span streaming path causes attributes to be lost on exceptions

In the async httpx client's span streaming path (lines 208-213), if `await real_send()` raises an exception, the `attributes` dictionary containing URL information (url.full, url.query, url.fragment) will never be set on the span. The sync client implementation correctly uses a `try/finally` block (lines 98-109 in the full file) to ensure `set_attributes()` is called even when exceptions occur. This inconsistency causes incomplete span data when async HTTP requests fail.