Skip to content
Open
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
11 changes: 9 additions & 2 deletions sentry_sdk/integrations/fastapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio
import sys
from copy import deepcopy
from functools import wraps

Expand Down Expand Up @@ -32,6 +32,13 @@
_DEFAULT_TRANSACTION_NAME = "generic FastAPI request"


# Vendored: https://github.com/Kludex/starlette/blob/0a29b5ccdcbd1285c75c4fdb5d62ae1d244a21b0/starlette/_utils.py#L11-L17
if sys.version_info >= (3, 13): # pragma: no cover
Copy link
Copy Markdown

@cooperoptigrid cooperoptigrid Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be true with Python version 4.0 and higher too, right? Using the _compat.py PY313 keeps its to Python 3.x.

Not sure if you care about that distinction

from inspect import iscoroutinefunction
else:
from asyncio import iscoroutinefunction


class FastApiIntegration(StarletteIntegration):
identifier = "fastapi"

Expand Down Expand Up @@ -74,7 +81,7 @@ def _sentry_get_request_handler(*args: "Any", **kwargs: "Any") -> "Any":
if (
dependant
and dependant.call is not None
and not asyncio.iscoroutinefunction(dependant.call)
and not iscoroutinefunction(dependant.call)
):
old_call = dependant.call

Expand Down
13 changes: 10 additions & 3 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import functools
import warnings
import sys
from collections.abc import Set
from copy import deepcopy
from json import JSONDecodeError
Expand Down Expand Up @@ -74,6 +74,13 @@
multipart = None


# Vendored: https://github.com/Kludex/starlette/blob/0a29b5ccdcbd1285c75c4fdb5d62ae1d244a21b0/starlette/_utils.py#L11-L17
if sys.version_info >= (3, 13): # pragma: no cover
from inspect import iscoroutinefunction
else:
from asyncio import iscoroutinefunction


_DEFAULT_TRANSACTION_NAME = "generic Starlette request"

TRANSACTION_STYLE_VALUES = ("endpoint", "url")
Expand Down Expand Up @@ -424,8 +431,8 @@ def _is_async_callable(obj: "Any") -> bool:
while isinstance(obj, functools.partial):
obj = obj.func

return asyncio.iscoroutinefunction(obj) or (
callable(obj) and asyncio.iscoroutinefunction(obj.__call__)
return iscoroutinefunction(obj) or (
callable(obj) and iscoroutinefunction(obj.__call__)
)


Expand Down
Loading