Skip to content
Merged
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
77 changes: 18 additions & 59 deletions sentry_sdk/integrations/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE
from sentry_sdk.traces import Span, get_current_span
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
has_data_collection_enabled,
parse_url,
)

Expand Down Expand Up @@ -196,56 +194,27 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None:

client_options = sentry_sdk.get_client().options
filtered_query_string = None
if has_data_collection_enabled(client_options):
query_string = request_websocket.query_string.decode(
"utf-8", errors="replace"
)
if query_string:
filtered_query_string = (
_apply_data_collection_filtering_to_query_string(
query_string=query_string,
behaviour=client_options["data_collection"]["url_query_params"],
)
)
if filtered_query_string:
segment.set_attribute(
"url.query",
filtered_query_string,
)

parsed_url = parse_url(request_websocket.url)
segment.set_attribute(
"url.full",
f"{parsed_url.url}?{filtered_query_string}"
if filtered_query_string
else parsed_url.url,
)

if client_options["data_collection"]["user_info"]:
user_properties = {}

if len(request_websocket.access_route) >= 1:
segment.set_attribute(
"client.address", request_websocket.access_route[0]
)
user_properties["ip_address"] = request_websocket.access_route[0]

current_user_id = _get_current_user_id_from_quart()
if current_user_id:
user_properties["id"] = current_user_id

if user_properties:
existing_user_properties = scope._user or {}
scope.set_user({**existing_user_properties, **user_properties})

elif should_send_default_pii():
segment.set_attribute("url.full", request_websocket.url)
segment.set_attribute(
"url.query",
request_websocket.query_string.decode("utf-8", errors="replace"),
query_string = request_websocket.query_string.decode("utf-8", errors="replace")
if query_string:
filtered_query_string = _apply_data_collection_filtering_to_query_string(
query_string=query_string,
behaviour=client_options["data_collection"]["url_query_params"],
)
if filtered_query_string:
segment.set_attribute("url.query", filtered_query_string)

parsed_url = parse_url(request_websocket.url)
segment.set_attribute(
"url.full",
f"{parsed_url.url}?{filtered_query_string}"
if filtered_query_string
else parsed_url.url,
)

if client_options["data_collection"]["user_info"]:
user_properties = {}

if len(request_websocket.access_route) >= 1:
segment.set_attribute(
"client.address", request_websocket.access_route[0]
Expand Down Expand Up @@ -285,17 +254,7 @@ def inner(event: "Event", hint: "dict[str, Any]") -> "Event":
request_info["headers"] = _filter_headers(dict(request.headers))

client_options = sentry_sdk.get_client().options
if has_data_collection_enabled(client_options):
if client_options["data_collection"]["user_info"]:
if len(request.access_route) >= 1:
request_info["env"] = {"REMOTE_ADDR": request.access_route[0]}

current_user_id = _get_current_user_id_from_quart()
if current_user_id:
user_info = event.setdefault("user", {})
user_info["id"] = current_user_id

elif should_send_default_pii():
if client_options["data_collection"]["user_info"]:
if len(request.access_route) >= 1:
request_info["env"] = {"REMOTE_ADDR": request.access_route[0]}

Expand Down
Loading
Loading