From c2c18a675487fe5804af9ae817ce84a460e64e9c Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 1 Oct 2026 11:52:49 +0200 Subject: [PATCH 1/2] ref(quart): Remove transaction_style parameter --- sentry_sdk/integrations/quart.py | 44 +++++--------------------- tests/integrations/quart/test_quart.py | 31 ++++++++---------- 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/sentry_sdk/integrations/quart.py b/sentry_sdk/integrations/quart.py index 05083f7926..0df3c3593c 100644 --- a/sentry_sdk/integrations/quart.py +++ b/sentry_sdk/integrations/quart.py @@ -10,8 +10,7 @@ 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.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE -from sentry_sdk.traces import Span, get_current_span +from sentry_sdk.traces import SegmentNameSource, Span, get_current_span from sentry_sdk.utils import ( capture_internal_exceptions, ensure_integration_enabled, @@ -49,23 +48,11 @@ except ImportError: raise DidNotEnable("Quart is not installed or incompatible") -TRANSACTION_STYLE_VALUES = ("endpoint", "url") - class QuartIntegration(Integration): identifier = "quart" origin = f"auto.http.{identifier}" - transaction_style = "" - - def __init__(self, transaction_style: str = "endpoint") -> None: - if transaction_style not in TRANSACTION_STYLE_VALUES: - raise ValueError( - "Invalid value for transaction_style: %s (must be in %s)" - % (transaction_style, TRANSACTION_STYLE_VALUES) - ) - self.transaction_style = transaction_style - @staticmethod def setup_once() -> None: request_started.connect(_request_websocket_started) @@ -131,25 +118,6 @@ def _sentry_func(*args: "Any", **kwargs: "Any") -> "Any": Scaffold.route = _sentry_route -def _set_transaction_name_and_source( - scope: "sentry_sdk.Scope", transaction_style: str, request: "Request" -) -> None: - try: - name_for_style = { - "url": request.url_rule.rule, - "endpoint": request.url_rule.endpoint, - } - - source = SEGMENT_SOURCE_FOR_STYLE[transaction_style] - - scope.set_transaction_name( - name=name_for_style[transaction_style], - source=source, - ) - except Exception: - pass - - async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None: integration = sentry_sdk.get_client().get_integration(QuartIntegration) if integration is None: @@ -172,9 +140,13 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None: # Set the transaction name here, but rely on ASGI middleware # to actually start the transaction - _set_transaction_name_and_source( - sentry_sdk.get_current_scope(), integration.transaction_style, request_websocket - ) + try: + sentry_sdk.get_current_scope().set_transaction_name( + name=request.url_rule.rule, + source=SegmentNameSource.ROUTE, + ) + except Exception: + pass scope = sentry_sdk.get_isolation_scope() diff --git a/tests/integrations/quart/test_quart.py b/tests/integrations/quart/test_quart.py index b5039e3dde..7db35bbfff 100644 --- a/tests/integrations/quart/test_quart.py +++ b/tests/integrations/quart/test_quart.py @@ -143,7 +143,7 @@ async def test_has_context(sentry_init, capture_events): assert response.status_code == 200 (event,) = events - assert event["transaction"] == "hi" + assert event["transaction"] == "/message" assert "data" not in event["request"] assert event["request"]["url"] == "http://localhost/message" @@ -545,10 +545,10 @@ async def hi_tx(): message, span = [item.payload for item in items] - assert span["name"] == "hi_tx" + assert span["name"] == "/message_tx" assert message["message"] == "hi" - assert message["transaction"] == "hi_tx" + assert message["transaction"] == "/message_tx" assert message["tags"]["view"] == "yes" assert message["tags"]["before_request"] == "yes" @@ -576,9 +576,9 @@ async def error(): error_event, span = [item.payload for item in items] - assert span["name"] == "error" + assert span["name"] == "/error" - assert error_event["transaction"] == "error" + assert error_event["transaction"] == "/error" (exception,) = error_event["exception"]["values"] assert exception["type"] == "ZeroDivisionError" @@ -608,7 +608,7 @@ async def dispatch_request(self): (event,) = events assert event["message"] == "hi" - assert event["transaction"] == "hello_class" + assert event["transaction"] == "/hello-class/" @pytest.mark.asyncio @@ -657,31 +657,26 @@ async def test_basic(sentry_init, capture_items): assert segment["attributes"]["sentry.op"] == "http.server" assert segment["attributes"]["sentry.origin"] == "auto.http.quart" assert segment["attributes"]["http.request.method"] == "GET" - assert segment["name"] == "hi" + assert segment["name"] == "/message" @pytest.mark.asyncio @pytest.mark.parametrize( - "url,transaction_style,expected_name,expected_source", + "url,expected_name,expected_source", [ - ("/message", "endpoint", "hi", "component"), - ("/message", "url", "/message", "route"), - ("/message/123456", "endpoint", "hi_with_id", "component"), - ("/message/123456", "url", "/message/", "route"), + ("/message", "/message", "route"), + ("/message/123456", "/message/", "route"), ], ) -async def test_transaction_style( +async def test_segment_name_and_source( sentry_init, capture_items, url, - transaction_style, expected_name, expected_source, ): sentry_init( - integrations=[ - quart_sentry.QuartIntegration(transaction_style=transaction_style) - ], + integrations=[quart_sentry.QuartIntegration()], traces_sample_rate=1.0, data_collection={}, ) @@ -934,7 +929,7 @@ async def login(): spans = [item.payload for item in items] assert len(spans) == 2 - segment = next(s for s in spans if s["name"] == "hi") + segment = next(s for s in spans if s["name"] == "/message") if expect_user_info and user_id is not None: assert segment["attributes"]["user.id"] == user_id else: From e49dd51c82b0f7044f53c9681af1045d7b3e501c Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 1 Oct 2026 12:01:24 +0200 Subject: [PATCH 2/2] use request_websocket instead of request --- sentry_sdk/integrations/quart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/quart.py b/sentry_sdk/integrations/quart.py index 0df3c3593c..1b007f2b16 100644 --- a/sentry_sdk/integrations/quart.py +++ b/sentry_sdk/integrations/quart.py @@ -142,7 +142,7 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None: # to actually start the transaction try: sentry_sdk.get_current_scope().set_transaction_name( - name=request.url_rule.rule, + name=request_websocket.url_rule.rule, source=SegmentNameSource.ROUTE, ) except Exception: