diff --git a/sentry_sdk/integrations/fastapi.py b/sentry_sdk/integrations/fastapi.py index 11c9bdcf51..6fbe53b92b 100644 --- a/sentry_sdk/integrations/fastapi.py +++ b/sentry_sdk/integrations/fastapi.py @@ -1,6 +1,7 @@ import asyncio from copy import deepcopy +from sentry_sdk._functools import wraps from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations import DidNotEnable @@ -79,6 +80,7 @@ def _sentry_get_request_handler(*args, **kwargs): ): old_call = dependant.call + @wraps(old_call) def _sentry_call(*args, **kwargs): # type: (*Any, **Any) -> Any hub = Hub.current diff --git a/tests/integrations/fastapi/test_fastapi.py b/tests/integrations/fastapi/test_fastapi.py index 524eed0560..56d52be474 100644 --- a/tests/integrations/fastapi/test_fastapi.py +++ b/tests/integrations/fastapi/test_fastapi.py @@ -377,6 +377,28 @@ def test_transaction_name( ) +def test_route_endpoint_equal_dependant_call(sentry_init): + """ + Tests that the route endpoint name is equal to the wrapped dependant call name. + """ + sentry_init( + auto_enabling_integrations=False, # Make sure that httpx integration is not added, because it adds tracing information to the starlette test clients request. + integrations=[ + StarletteIntegration(), + FastApiIntegration(), + ], + traces_sample_rate=1.0, + debug=True, + ) + + app = fastapi_app_factory() + + for route in app.router.routes: + if not hasattr(route, "dependant"): + continue + assert route.endpoint.__qualname__ == route.dependant.call.__qualname__ + + @pytest.mark.parametrize( "request_url,transaction_style,expected_transaction_name,expected_transaction_source", [