Skip to content

Commit 2cb232e

Browse files
authored
fix(integrations): Use wraps on fastapi request call wrapper (#2476)
1 parent 4643e32 commit 2cb232e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

sentry_sdk/integrations/fastapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from copy import deepcopy
33

4+
from sentry_sdk._functools import wraps
45
from sentry_sdk._types import TYPE_CHECKING
56
from sentry_sdk.hub import Hub, _should_send_default_pii
67
from sentry_sdk.integrations import DidNotEnable
@@ -79,6 +80,7 @@ def _sentry_get_request_handler(*args, **kwargs):
7980
):
8081
old_call = dependant.call
8182

83+
@wraps(old_call)
8284
def _sentry_call(*args, **kwargs):
8385
# type: (*Any, **Any) -> Any
8486
hub = Hub.current

tests/integrations/fastapi/test_fastapi.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,28 @@ def test_transaction_name(
377377
)
378378

379379

380+
def test_route_endpoint_equal_dependant_call(sentry_init):
381+
"""
382+
Tests that the route endpoint name is equal to the wrapped dependant call name.
383+
"""
384+
sentry_init(
385+
auto_enabling_integrations=False, # Make sure that httpx integration is not added, because it adds tracing information to the starlette test clients request.
386+
integrations=[
387+
StarletteIntegration(),
388+
FastApiIntegration(),
389+
],
390+
traces_sample_rate=1.0,
391+
debug=True,
392+
)
393+
394+
app = fastapi_app_factory()
395+
396+
for route in app.router.routes:
397+
if not hasattr(route, "dependant"):
398+
continue
399+
assert route.endpoint.__qualname__ == route.dependant.call.__qualname__
400+
401+
380402
@pytest.mark.parametrize(
381403
"request_url,transaction_style,expected_transaction_name,expected_transaction_source",
382404
[

0 commit comments

Comments
 (0)