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
11 changes: 11 additions & 0 deletions sentry_sdk/integrations/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.consts import SPANDATA

Check warning on line 8 in sentry_sdk/integrations/quart.py

View check run for this annotation

@sentry/warden / warden: code-review

http.route lookup uses request proxy instead of request_websocket

In `_request_websocket_started`, `route_path` is read from `request.url_rule.rule` instead of `request_websocket.url_rule.rule`, so websocket connections never set `http.route` (the bare `except` swallows the missing request context). Use `request_websocket` like the transaction-name path below it.
from sentry_sdk.data_collection import _apply_data_collection_filtering_to_query_string
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations._wsgi_common import _filter_headers
Expand Down Expand Up @@ -181,6 +182,16 @@
if has_websocket_context():
request_websocket = websocket._get_current_object()

route_path = None
try:
route_path = request.url_rule.rule
except Exception:

Check warning on line 188 in sentry_sdk/integrations/quart.py

View check run for this annotation

@sentry/warden / warden: code-review

[3GU-3L3] http.route lookup uses request proxy instead of request_websocket (additional location)

In `_request_websocket_started`, `route_path` is read from `request.url_rule.rule` instead of `request_websocket.url_rule.rule`, so websocket connections never set `http.route` (the bare `except` swallows the missing request context). Use `request_websocket` like the transaction-name path below it.
pass

Check warning on line 189 in sentry_sdk/integrations/quart.py

View check run for this annotation

@sentry/warden / warden: find-bugs

http.route reads from request proxy instead of request_websocket

Use request_websocket.url_rule.rule so http.route is set for websockets too; request fails outside request context and is swallowed by the bare except.

server_span = sentry_sdk.get_current_scope()._server_segment_span
if server_span is not None and route_path is not None:
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)

# Set the transaction name here, but rely on ASGI middleware
# to actually start the transaction
_set_transaction_name_and_source(
Expand Down
24 changes: 24 additions & 0 deletions tests/integrations/quart/test_quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
set_tag,
)
from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.utils import parse_version

Expand Down Expand Up @@ -176,6 +177,29 @@
assert event["transaction"] == expected_transaction


@pytest.mark.asyncio
async def test_http_route(
sentry_init,
capture_items,
):
sentry_init(
integrations=[quart_sentry.QuartIntegration()],
traces_sample_rate=1.0,
trace_lifecycle="stream",
)

app = quart_app_factory()
items = capture_items("span")

Check warning on line 193 in tests/integrations/quart/test_quart.py

View check run for this annotation

@sentry/warden / warden: find-bugs

[DY8-L29] http.route reads from request proxy instead of request_websocket (additional location)

Use request_websocket.url_rule.rule so http.route is set for websockets too; request fails outside request context and is swallowed by the bare except.
client = app.test_client()
await client.get("/message/123456")

sentry_sdk.flush()

(segment,) = [item.payload for item in items if item.payload.get("is_segment")]
assert segment["attributes"][SPANDATA.HTTP_ROUTE] == "/message/<message_id>"

Check warning on line 200 in tests/integrations/quart/test_quart.py

View check run for this annotation

@sentry/warden / warden: code-review

[3GU-3L3] http.route lookup uses request proxy instead of request_websocket (additional location)

In `_request_websocket_started`, `route_path` is read from `request.url_rule.rule` instead of `request_websocket.url_rule.rule`, so websocket connections never set `http.route` (the bare `except` swallows the missing request context). Use `request_websocket` like the transaction-name path below it.


@pytest.mark.asyncio
async def test_errors(
sentry_init,
Expand Down
Loading