Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 15 additions & 6 deletions sentry_sdk/integrations/_asgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@
)

client = asgi_scope.get("client")
if client and should_send_default_pii():
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
if client:
if has_data_collection_enabled(client_options):
if client_options["data_collection"]["user_info"]:

Check warning on line 153 in sentry_sdk/integrations/_asgi_common.py

View check run for this annotation

@sentry/warden / warden: code-review

client_options may be unbound when scope type is not http/websocket

In both `_get_request_data` and `_get_request_attributes`, `client_options = sentry_sdk.get_client().options` is assigned only inside the `if ty in ("http", "websocket")` block, but is later referenced unconditionally when `client`/`asgi_scope_client` is truthy. If a scope with `ty` other than http/websocket carries a `client` entry, `has_data_collection_enabled(client_options)` raises `NameError`. In practice only http/websocket ASGI scopes carry a `client` key (lifespan scopes do not), so this path is largely unreachable with spec-compliant servers, but it is a latent regression: the prior code branched on `should_send_default_pii()` and did not depend on `client_options`.
Comment thread
sentry-warden[bot] marked this conversation as resolved.
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
elif should_send_default_pii():
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}

return request_data

Expand Down Expand Up @@ -226,9 +230,14 @@
else url_without_query_string
)

client = asgi_scope.get("client")
if client and should_send_default_pii():
ip = _get_ip(asgi_scope)
attributes["client.address"] = ip
asgi_scope_client = asgi_scope.get("client")
if asgi_scope_client:
if has_data_collection_enabled(client_options):

Check warning on line 235 in sentry_sdk/integrations/_asgi_common.py

View check run for this annotation

@sentry/warden / warden: code-review

[DVQ-38F] client_options may be unbound when scope type is not http/websocket (additional location)

In both `_get_request_data` and `_get_request_attributes`, `client_options = sentry_sdk.get_client().options` is assigned only inside the `if ty in ("http", "websocket")` block, but is later referenced unconditionally when `client`/`asgi_scope_client` is truthy. If a scope with `ty` other than http/websocket carries a `client` entry, `has_data_collection_enabled(client_options)` raises `NameError`. In practice only http/websocket ASGI scopes carry a `client` key (lifespan scopes do not), so this path is largely unreachable with spec-compliant servers, but it is a latent regression: the prior code branched on `should_send_default_pii()` and did not depend on `client_options`.
if client_options["data_collection"]["user_info"]:
Comment thread
sentry[bot] marked this conversation as resolved.
ip = _get_ip(asgi_scope)
attributes["client.address"] = ip
elif should_send_default_pii():
ip = _get_ip(asgi_scope)
attributes["client.address"] = ip
Comment thread
cursor[bot] marked this conversation as resolved.

return attributes
Loading
Loading