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
22 changes: 2 additions & 20 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 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 SegmentNameSource
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down Expand Up @@ -100,32 +101,13 @@ def process_resource(
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,
}
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")
sentry_sdk.set_transaction_name(req.uri_template, SegmentNameSource.ROUTE)


class FalconIntegration(Integration):
identifier = "falcon"
origin = f"auto.http.{identifier}"

transaction_style = ""

def __init__(self, transaction_style: str = "uri_template") -> None:
if transaction_style not in TRANSACTION_STYLE_VALUES:
raise ValueError(
f"Invalid value for transaction_style: {transaction_style} "
f"(must be in {TRANSACTION_STYLE_VALUES})"
)
self.transaction_style = transaction_style

@staticmethod
def setup_once() -> None:
_check_minimum_version(FalconIntegration, parse_version(FALCON_VERSION))
Expand Down
13 changes: 5 additions & 8 deletions tests/integrations/falcon/test_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,21 @@ def test_has_context(


@pytest.mark.parametrize(
"url,transaction_style,expected_transaction,expected_source",
"url,expected_transaction,expected_source",
[
("/message", "uri_template", "/message", "route"),
("/message", "path", "/message", "url"),
("/message/123456", "uri_template", "/message/{message_id:int}", "route"),
("/message/123456", "path", "/message/123456", "url"),
("/message", "/message", "route"),
("/message/123456", "/message/{message_id:int}", "route"),
],
)
def test_transaction_style(
def test_segment_name_and_source(
sentry_init,
make_client,
capture_items,
url,
transaction_style,
expected_transaction,
expected_source,
):
integration = FalconIntegration(transaction_style=transaction_style)
integration = FalconIntegration()
sentry_init(
integrations=[integration],
traces_sample_rate=1.0,
Expand Down
Loading