diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index 81417de689..3b20d563a2 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -23,7 +23,6 @@ from sentry_sdk.traces import ( BAGGAGE_HEADER_NAME, SENTRY_TRACE_HEADER_NAME, - SOURCE_FOR_STYLE, SegmentNameSource, Span, SpanStatus, @@ -47,7 +46,6 @@ parse_url, parse_version, reraise, - transaction_from_function, ) try: @@ -74,25 +72,15 @@ from sentry_sdk.utils import ExcInfo -TRANSACTION_STYLE_VALUES = ("handler_name", "method_and_path_pattern") - - class AioHttpIntegration(Integration): identifier = "aiohttp" origin = f"auto.http.{identifier}" def __init__( self, - transaction_style: str = "handler_name", *, failed_request_status_codes: "Set[int]" = _DEFAULT_FAILED_REQUEST_STATUS_CODES, ) -> 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 self._failed_request_status_codes = failed_request_status_codes @staticmethod @@ -265,21 +253,12 @@ async def sentry_urldispatcher_resolve( if server_span is not None and pattern is not None: server_span.set_attribute(SPANDATA.HTTP_ROUTE, pattern) - name = None - - try: - if integration.transaction_style == "handler_name": - name = transaction_from_function(rv.handler) - elif integration.transaction_style == "method_and_path_pattern": - name = "{} {}".format(request.method, pattern) - except Exception: - pass + current_scope = sentry_sdk.get_current_scope() - if name is not None: - current_scope = sentry_sdk.get_current_scope() + if pattern is not None: current_scope.set_transaction_name( - name, - source=SOURCE_FOR_STYLE[integration.transaction_style], + pattern, + source=SegmentNameSource.ROUTE, ) return rv diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index e4f72991db..13424ddba8 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -49,10 +49,7 @@ async def hello(request): (event,) = events - assert ( - event["transaction"] - == "tests.integrations.aiohttp.test_aiohttp.test_basic..hello" - ) + assert event["transaction"] == "/" (exception,) = event["exception"]["values"] assert exception["type"] == "ZeroDivisionError" @@ -325,10 +322,7 @@ async def hello(request): (span,) = [item.payload for item in items] - assert ( - span["name"] - == "tests.integrations.aiohttp.test_aiohttp.test_tracing_unparseable_url..hello" - ) + assert span["name"] == "/" @pytest.mark.asyncio @@ -1340,14 +1334,11 @@ async def hello(request): (server_span,) = [item.payload for item in items] assert server_span["is_segment"] is True - assert ( - server_span["name"] - == "tests.integrations.aiohttp.test_aiohttp.test_tracing..hello" - ) + assert server_span["name"] == "/" assert server_span["attributes"]["sentry.op"] == "http.server" assert server_span["attributes"]["sentry.origin"] == "auto.http.aiohttp" assert server_span["attributes"]["http.response.status_code"] == 200 - assert server_span["attributes"]["sentry.segment.name.source"] == "component" + assert server_span["attributes"]["sentry.segment.name.source"] == "route" assert server_span["status"] == "ok" # No query string on the request, so the attribute should be omitted. assert "url.query" not in server_span["attributes"] @@ -1450,35 +1441,13 @@ async def hello(request): @pytest.mark.asyncio -@pytest.mark.parametrize( - "url,transaction_style,expected_name,expected_source", - [ - ( - "/message", - "handler_name", - "tests.integrations.aiohttp.test_aiohttp." - "test_transaction_style..hello", - "component", - ), - ( - "/message", - "method_and_path_pattern", - "GET /{var}", - "route", - ), - ], -) async def test_transaction_style( sentry_init, aiohttp_client, capture_items, - url, - transaction_style, - expected_name, - expected_source, ): sentry_init( - integrations=[AioHttpIntegration(transaction_style=transaction_style)], + integrations=[AioHttpIntegration()], traces_sample_rate=1.0, data_collection={}, ) @@ -1492,7 +1461,7 @@ async def hello(request): items = capture_items("span") client = await aiohttp_client(app) - resp = await client.get(url) + resp = await client.get("/message") assert resp.status == 200 sentry_sdk.flush() @@ -1500,9 +1469,9 @@ async def hello(request): assert len(items) == 1 (server_segment,) = [item.payload for item in items] - assert server_segment["name"] == expected_name + assert server_segment["name"] == "/{var}" assert server_segment["is_segment"] - assert server_segment["attributes"]["sentry.segment.name.source"] == expected_source + assert server_segment["attributes"]["sentry.segment.name.source"] == "route" @pytest.mark.asyncio @@ -1781,7 +1750,7 @@ async def hello(request): child_span, server_span = [item.payload for item in items] - assert server_span["attributes"]["sentry.segment.name.source"] == "component" + assert server_span["attributes"]["sentry.segment.name.source"] == "route" assert "sentry.segment.name.source" not in child_span["attributes"] if expect_user_info: