Skip to content

Commit

Permalink
fix(integrations): Use wraps on fastapi request call wrapper (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaras committed Nov 8, 2023
1 parent 4643e32 commit 2cb232e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/integrations/fastapi/test_fastapi.py
Expand Up @@ -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",
[
Expand Down

0 comments on commit 2cb232e

Please sign in to comment.