diff --git a/sentry_sdk/integrations/falcon.py b/sentry_sdk/integrations/falcon.py index 7a595bcf2a..7f360544ba 100644 --- a/sentry_sdk/integrations/falcon.py +++ b/sentry_sdk/integrations/falcon.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING import sentry_sdk +from sentry_sdk.consts import SPANDATA 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 @@ -116,6 +117,10 @@ def process_resource( if integration is None or not has_span_streaming_enabled(client.options): return + server_span = sentry_sdk.get_current_scope()._server_segment_span + if server_span is not None: + server_span.set_attribute(SPANDATA.HTTP_ROUTE, req.uri_template) + name_for_style = { "uri_template": req.uri_template, "path": req.path, diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index b0156a9829..3204e15e43 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -159,6 +159,7 @@ def __call__( }, parent_span=None, ) + scope.get_current_scope()._server_segment_span = span_ctx else: transaction = continue_trace( environ, diff --git a/tests/integrations/falcon/test_falcon.py b/tests/integrations/falcon/test_falcon.py index 8bf22707e1..79765bc537 100644 --- a/tests/integrations/falcon/test_falcon.py +++ b/tests/integrations/falcon/test_falcon.py @@ -5,6 +5,7 @@ import pytest import sentry_sdk +from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.falcon import FalconIntegration from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.utils import parse_version @@ -155,6 +156,27 @@ def test_transaction_style( assert event["transaction_info"] == {"source": expected_source} +def test_http_route( + sentry_init, + make_client, + capture_items, +): + sentry_init( + integrations=[FalconIntegration()], + traces_sample_rate=1.0, + trace_lifecycle="stream", + ) + + client = make_client() + items = capture_items("span") + + client.simulate_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:int}" + + @pytest.mark.parametrize("span_streaming", [True, False]) def test_unhandled_errors( sentry_init,