Skip to content

Commit c2ed5ec

Browse files
authored
Fix check for Starlette in FastAPI integration (#1868)
When loading FastAPI integration also check if StarletteIntegration can actually be loaded. (Because Starlette is a requirement for FastAPI) Fixes #1603
1 parent 89a602b commit c2ed5ec

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sentry_sdk/integrations/fastapi.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
from sentry_sdk._types import MYPY
44
from sentry_sdk.hub import Hub, _should_send_default_pii
55
from sentry_sdk.integrations import DidNotEnable
6-
from sentry_sdk.integrations.starlette import (
7-
StarletteIntegration,
8-
StarletteRequestExtractor,
9-
)
106
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_ROUTE
117
from sentry_sdk.utils import transaction_from_function
128

139
if MYPY:
1410
from typing import Any, Callable, Dict
15-
1611
from sentry_sdk.scope import Scope
1712

13+
try:
14+
from sentry_sdk.integrations.starlette import (
15+
StarletteIntegration,
16+
StarletteRequestExtractor,
17+
)
18+
except DidNotEnable:
19+
raise DidNotEnable("Starlette is not installed")
20+
1821
try:
1922
import fastapi # type: ignore
2023
except ImportError:

0 commit comments

Comments
 (0)