Skip to content

Commit e0d105e

Browse files
feat(falcon): Add http.route attribute (#7340)
Set the `http.route` attribute on the server span in patches for Falcon endpoints.
1 parent 5c6a9eb commit e0d105e

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎sentry_sdk/integrations/falcon.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import TYPE_CHECKING
22

33
import sentry_sdk
4+
from sentry_sdk.consts import SPANDATA
45
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
56
from sentry_sdk.integrations._wsgi_common import RequestExtractor
67
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
@@ -116,6 +117,10 @@ def process_resource(
116117
if integration is None or not has_span_streaming_enabled(client.options):
117118
return
118119

120+
server_span = sentry_sdk.get_current_scope()._server_segment_span
121+
if server_span is not None:
122+
server_span.set_attribute(SPANDATA.HTTP_ROUTE, req.uri_template)
123+
119124
name_for_style = {
120125
"uri_template": req.uri_template,
121126
"path": req.path,

‎sentry_sdk/integrations/wsgi.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __call__(
159159
},
160160
parent_span=None,
161161
)
162+
scope.get_current_scope()._server_segment_span = span_ctx
162163
else:
163164
transaction = continue_trace(
164165
environ,

‎tests/integrations/falcon/test_falcon.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
import sentry_sdk
8+
from sentry_sdk.consts import SPANDATA
89
from sentry_sdk.integrations.falcon import FalconIntegration
910
from sentry_sdk.integrations.logging import LoggingIntegration
1011
from sentry_sdk.utils import parse_version
@@ -155,6 +156,27 @@ def test_transaction_style(
155156
assert event["transaction_info"] == {"source": expected_source}
156157

157158

159+
def test_http_route(
160+
sentry_init,
161+
make_client,
162+
capture_items,
163+
):
164+
sentry_init(
165+
integrations=[FalconIntegration()],
166+
traces_sample_rate=1.0,
167+
trace_lifecycle="stream",
168+
)
169+
170+
client = make_client()
171+
items = capture_items("span")
172+
173+
client.simulate_get("/message/123456")
174+
175+
sentry_sdk.flush()
176+
(segment,) = [item.payload for item in items if item.payload.get("is_segment")]
177+
assert segment["attributes"][SPANDATA.HTTP_ROUTE] == "/message/{message_id:int}"
178+
179+
158180
@pytest.mark.parametrize("span_streaming", [True, False])
159181
def test_unhandled_errors(
160182
sentry_init,

0 commit comments

Comments
 (0)