Skip to content

move imports

9648022
Select commit
Loading
Failed to load commit list.
Merged

feat(wsgi): Migrate to span first #5988

move imports
9648022
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: code-review completed Apr 13, 2026 in 2m 37s

3 issues

code-review: Found 3 issues (1 high, 1 medium, 1 low)

High

Circular import between wsgi.py and _wsgi_common.py will cause ImportError at runtime - `sentry_sdk/integrations/_wsgi_common.py:8`

The new import from sentry_sdk.integrations.wsgi import get_client_ip, get_request_url creates a circular dependency. wsgi.py imports _get_request_attributes from _wsgi_common.py (line 12 in wsgi.py), while _wsgi_common.py now imports from wsgi.py. When wsgi.py is loaded first, it will fail because _wsgi_common.py will try to import symbols from wsgi.py before they're defined. This will cause an ImportError or AttributeError at runtime.

Medium

AttributeError when span is None for non-captured HTTP methods - `sentry_sdk/integrations/wsgi.py:167`

When the HTTP method is not in http_methods_to_capture, span_ctx remains None and becomes nullcontext(), which yields None as the context value. The code then calls span.set_attribute(attr, value) on this None value, causing an AttributeError. While wrapped in capture_internal_exceptions(), this will log an internal error on every request with non-captured methods (like HEAD or OPTIONS by default).

Low

server.port attribute set as string instead of integer - `sentry_sdk/integrations/_wsgi_common.py:287-288`

The server.port attribute is set as a string from environ.get("SERVER_PORT") at line 288, but OpenTelemetry semantic conventions expect this to be an integer. Other integrations in this codebase (e.g., clickhouse_driver, asyncpg) use integer values for server.port. This type inconsistency could cause issues with backend data processing or filtering.


Duration: 2m 29s · Tokens: 1.9M in / 19.8k out · Cost: $2.46 (+extraction: $0.00, +merge: $0.00, +fix_gate: $0.01)

Annotations

Check failure on line 8 in sentry_sdk/integrations/_wsgi_common.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

Circular import between wsgi.py and _wsgi_common.py will cause ImportError at runtime

The new import `from sentry_sdk.integrations.wsgi import get_client_ip, get_request_url` creates a circular dependency. `wsgi.py` imports `_get_request_attributes` from `_wsgi_common.py` (line 12 in wsgi.py), while `_wsgi_common.py` now imports from `wsgi.py`. When `wsgi.py` is loaded first, it will fail because `_wsgi_common.py` will try to import symbols from `wsgi.py` before they're defined. This will cause an `ImportError` or `AttributeError` at runtime.

Check warning on line 167 in sentry_sdk/integrations/wsgi.py

See this annotation in the file changed.

@sentry-warden sentry-warden / warden: code-review

AttributeError when span is None for non-captured HTTP methods

When the HTTP method is not in `http_methods_to_capture`, `span_ctx` remains `None` and becomes `nullcontext()`, which yields `None` as the context value. The code then calls `span.set_attribute(attr, value)` on this `None` value, causing an `AttributeError`. While wrapped in `capture_internal_exceptions()`, this will log an internal error on every request with non-captured methods (like HEAD or OPTIONS by default).