Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sentry_sdk/integrations/falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sentry_sdk.integrations._wsgi_common import RequestExtractor
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.tracing_utils import has_span_streaming_enabled
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down Expand Up @@ -104,6 +105,25 @@ def process_request(
scope._name = "falcon"
scope.add_event_processor(_make_request_event_processor(req, integration))

def process_resource(
self, req: "Any", resp: "Any", resource: "Any", params: "Any"
) -> None:
"""
Sets the segment name and source as the route is resolved when this runs.
"""
client = sentry_sdk.get_client()
integration = client.get_integration(FalconIntegration)
if integration is None or not has_span_streaming_enabled(client.options):
return

name_for_style = {
"uri_template": req.uri_template,
"path": req.path,
}
name = name_for_style[integration.transaction_style]
source = sentry_sdk.traces.SOURCE_FOR_STYLE[integration.transaction_style]
sentry_sdk.set_transaction_name(name, source)


TRANSACTION_STYLE_VALUES = ("uri_template", "path")

Expand Down
16 changes: 14 additions & 2 deletions tests/integrations/falcon/test_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,36 @@ def test_transaction_style(
integration = FalconIntegration(transaction_style=transaction_style)
sentry_init(
integrations=[integration],
traces_sample_rate=1.0,
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
)

client = make_client()
if span_streaming:
items = capture_items("event")
items = capture_items("event", "span")

response = client.simulate_get(url)
assert response.status == falcon.HTTP_200

(event,) = (item.payload for item in items)
(event,) = (item.payload for item in items if item.type == "event")

sentry_sdk.flush()
spans = [item.payload for item in items if item.type == "span"]
spans = [span for span in spans if span["name"] == expected_transaction]
assert len(spans) == 1
assert spans[0]["attributes"]["sentry.span.source"] == expected_source
else:
events = capture_events()

response = client.simulate_get(url)
assert response.status == falcon.HTTP_200

(event,) = events
(event, transaction) = events

assert transaction["transaction"] == expected_transaction
assert transaction["transaction_info"] == {"source": expected_source}

assert event["transaction"] == expected_transaction
assert event["transaction_info"] == {"source": expected_source}

Expand Down
Loading