Skip to content

Commit 39d6006

Browse files
ref(quart): Remove transaction_style parameter (#7805)
Inline the branches that set the route template as the segment name (i.e., `transaction_style="url"`). Closes #7764
1 parent 29d9d8f commit 39d6006

2 files changed

Lines changed: 21 additions & 54 deletions

File tree

‎sentry_sdk/integrations/quart.py‎

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from sentry_sdk.integrations import DidNotEnable, Integration
1111
from sentry_sdk.integrations._wsgi_common import _filter_headers
1212
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
13-
from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE
14-
from sentry_sdk.traces import Span, get_current_span
13+
from sentry_sdk.traces import SegmentNameSource, Span, get_current_span
1514
from sentry_sdk.utils import (
1615
capture_internal_exceptions,
1716
ensure_integration_enabled,
@@ -49,23 +48,11 @@
4948
except ImportError:
5049
raise DidNotEnable("Quart is not installed or incompatible")
5150

52-
TRANSACTION_STYLE_VALUES = ("endpoint", "url")
53-
5451

5552
class QuartIntegration(Integration):
5653
identifier = "quart"
5754
origin = f"auto.http.{identifier}"
5855

59-
transaction_style = ""
60-
61-
def __init__(self, transaction_style: str = "endpoint") -> None:
62-
if transaction_style not in TRANSACTION_STYLE_VALUES:
63-
raise ValueError(
64-
"Invalid value for transaction_style: %s (must be in %s)"
65-
% (transaction_style, TRANSACTION_STYLE_VALUES)
66-
)
67-
self.transaction_style = transaction_style
68-
6956
@staticmethod
7057
def setup_once() -> None:
7158
request_started.connect(_request_websocket_started)
@@ -131,25 +118,6 @@ def _sentry_func(*args: "Any", **kwargs: "Any") -> "Any":
131118
Scaffold.route = _sentry_route
132119

133120

134-
def _set_transaction_name_and_source(
135-
scope: "sentry_sdk.Scope", transaction_style: str, request: "Request"
136-
) -> None:
137-
try:
138-
name_for_style = {
139-
"url": request.url_rule.rule,
140-
"endpoint": request.url_rule.endpoint,
141-
}
142-
143-
source = SEGMENT_SOURCE_FOR_STYLE[transaction_style]
144-
145-
scope.set_transaction_name(
146-
name=name_for_style[transaction_style],
147-
source=source,
148-
)
149-
except Exception:
150-
pass
151-
152-
153121
async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None:
154122
integration = sentry_sdk.get_client().get_integration(QuartIntegration)
155123
if integration is None:
@@ -172,9 +140,13 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None:
172140

173141
# Set the transaction name here, but rely on ASGI middleware
174142
# to actually start the transaction
175-
_set_transaction_name_and_source(
176-
sentry_sdk.get_current_scope(), integration.transaction_style, request_websocket
177-
)
143+
try:
144+
sentry_sdk.get_current_scope().set_transaction_name(
145+
name=request_websocket.url_rule.rule,
146+
source=SegmentNameSource.ROUTE,
147+
)
148+
except Exception:
149+
pass
178150

179151
scope = sentry_sdk.get_isolation_scope()
180152

‎tests/integrations/quart/test_quart.py‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def test_has_context(sentry_init, capture_events):
143143
assert response.status_code == 200
144144

145145
(event,) = events
146-
assert event["transaction"] == "hi"
146+
assert event["transaction"] == "/message"
147147
assert "data" not in event["request"]
148148
assert event["request"]["url"] == "http://localhost/message"
149149

@@ -545,10 +545,10 @@ async def hi_tx():
545545

546546
message, span = [item.payload for item in items]
547547

548-
assert span["name"] == "hi_tx"
548+
assert span["name"] == "/message_tx"
549549

550550
assert message["message"] == "hi"
551-
assert message["transaction"] == "hi_tx"
551+
assert message["transaction"] == "/message_tx"
552552
assert message["tags"]["view"] == "yes"
553553
assert message["tags"]["before_request"] == "yes"
554554

@@ -576,9 +576,9 @@ async def error():
576576

577577
error_event, span = [item.payload for item in items]
578578

579-
assert span["name"] == "error"
579+
assert span["name"] == "/error"
580580

581-
assert error_event["transaction"] == "error"
581+
assert error_event["transaction"] == "/error"
582582
(exception,) = error_event["exception"]["values"]
583583
assert exception["type"] == "ZeroDivisionError"
584584

@@ -608,7 +608,7 @@ async def dispatch_request(self):
608608
(event,) = events
609609

610610
assert event["message"] == "hi"
611-
assert event["transaction"] == "hello_class"
611+
assert event["transaction"] == "/hello-class/"
612612

613613

614614
@pytest.mark.asyncio
@@ -657,31 +657,26 @@ async def test_basic(sentry_init, capture_items):
657657
assert segment["attributes"]["sentry.op"] == "http.server"
658658
assert segment["attributes"]["sentry.origin"] == "auto.http.quart"
659659
assert segment["attributes"]["http.request.method"] == "GET"
660-
assert segment["name"] == "hi"
660+
assert segment["name"] == "/message"
661661

662662

663663
@pytest.mark.asyncio
664664
@pytest.mark.parametrize(
665-
"url,transaction_style,expected_name,expected_source",
665+
"url,expected_name,expected_source",
666666
[
667-
("/message", "endpoint", "hi", "component"),
668-
("/message", "url", "/message", "route"),
669-
("/message/123456", "endpoint", "hi_with_id", "component"),
670-
("/message/123456", "url", "/message/<message_id>", "route"),
667+
("/message", "/message", "route"),
668+
("/message/123456", "/message/<message_id>", "route"),
671669
],
672670
)
673-
async def test_transaction_style(
671+
async def test_segment_name_and_source(
674672
sentry_init,
675673
capture_items,
676674
url,
677-
transaction_style,
678675
expected_name,
679676
expected_source,
680677
):
681678
sentry_init(
682-
integrations=[
683-
quart_sentry.QuartIntegration(transaction_style=transaction_style)
684-
],
679+
integrations=[quart_sentry.QuartIntegration()],
685680
traces_sample_rate=1.0,
686681
data_collection={},
687682
)
@@ -934,7 +929,7 @@ async def login():
934929
spans = [item.payload for item in items]
935930
assert len(spans) == 2
936931

937-
segment = next(s for s in spans if s["name"] == "hi")
932+
segment = next(s for s in spans if s["name"] == "/message")
938933
if expect_user_info and user_id is not None:
939934
assert segment["attributes"]["user.id"] == user_id
940935
else:

0 commit comments

Comments
 (0)