From 474350cd0992c74a8192be6c389e4d1d96438bdc Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 1 Oct 2026 11:58:41 +0200 Subject: [PATCH] ref(pyramid): Remove transaction_style parameter --- sentry_sdk/integrations/pyramid.py | 40 ++++------------------ tests/integrations/pyramid/test_pyramid.py | 17 ++++----- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index e2f29b8054..a7e5f60734 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -8,7 +8,7 @@ from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware -from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE +from sentry_sdk.traces import SegmentNameSource from sentry_sdk.utils import ( capture_internal_exceptions, ensure_integration_enabled, @@ -37,23 +37,10 @@ from sentry_sdk.utils import ExcInfo -TRANSACTION_STYLE_VALUES = ("route_name", "route_pattern") - - class PyramidIntegration(Integration): identifier = "pyramid" origin = f"auto.http.{identifier}" - transaction_style = "" - - def __init__(self, transaction_style: str = "route_name") -> 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: version = package_version("pyramid") @@ -84,9 +71,12 @@ def sentry_patched_call_view( SPANDATA.HTTP_ROUTE, request.matched_route.pattern ) - _set_transaction_name_and_source( - sentry_sdk.get_current_scope(), integration.transaction_style, request - ) + try: + sentry_sdk.get_current_scope().set_transaction_name( + request.matched_route.pattern, source=SegmentNameSource.ROUTE + ) + except Exception: + pass scope = sentry_sdk.get_isolation_scope() @@ -163,22 +153,6 @@ def _capture_exception(exc_info: "ExcInfo") -> None: sentry_sdk.capture_event(event, hint=hint) -def _set_transaction_name_and_source( - scope: "sentry_sdk.Scope", transaction_style: str, request: "Request" -) -> None: - try: - name_for_style = { - "route_name": request.matched_route.name, - "route_pattern": request.matched_route.pattern, - } - scope.set_transaction_name( - name_for_style[transaction_style], - source=SEGMENT_SOURCE_FOR_STYLE[transaction_style], - ) - except Exception: - pass - - class PyramidRequestExtractor(RequestExtractor): def url(self) -> str: return self.request.path_url diff --git a/tests/integrations/pyramid/test_pyramid.py b/tests/integrations/pyramid/test_pyramid.py index 6f68708b44..1ec8aed657 100644 --- a/tests/integrations/pyramid/test_pyramid.py +++ b/tests/integrations/pyramid/test_pyramid.py @@ -112,29 +112,26 @@ def hi2(request): "method": "GET", "url": "http://localhost/context_message/yoo", } - assert event["transaction"] == "hi2" + assert event["transaction"] == "/context_message/{msg}" @pytest.mark.parametrize( - "url,transaction_style,expected_transaction,expected_source", + "url,expected_transaction,expected_source", [ - ("/message", "route_name", "hi", "component"), - ("/message", "route_pattern", "/message", "route"), - ("/message/123456", "route_name", "hi_with_id", "component"), - ("/message/123456", "route_pattern", "/message/{message_id}", "route"), + ("/message", "/message", "route"), + ("/message/123456", "/message/{message_id}", "route"), ], ) -def test_transaction_style( +def test_segment_name_and_source( sentry_init, get_client, capture_items, url, - transaction_style, expected_transaction, expected_source, ): sentry_init( - integrations=[PyramidIntegration(transaction_style=transaction_style)], + integrations=[PyramidIntegration()], traces_sample_rate=1.0, ) @@ -504,7 +501,7 @@ def tracing_error(request): (segment,) = spans (error_event,) = error_events - assert segment["name"] == "tracing_error" + assert segment["name"] == "/tracing-error" assert segment["status"] == SpanStatus.ERROR assert segment["attributes"]["sentry.origin"] == "auto.http.pyramid"