From c2ed5ec1b339fcea912377781053cb28c90c11ed Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 30 Jan 2023 15:21:28 +0100 Subject: [PATCH] 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 --- sentry_sdk/integrations/fastapi.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sentry_sdk/integrations/fastapi.py b/sentry_sdk/integrations/fastapi.py index 32c511d74a..5dde0e7d37 100644 --- a/sentry_sdk/integrations/fastapi.py +++ b/sentry_sdk/integrations/fastapi.py @@ -3,18 +3,21 @@ from sentry_sdk._types import MYPY from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations import DidNotEnable -from sentry_sdk.integrations.starlette import ( - StarletteIntegration, - StarletteRequestExtractor, -) from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_ROUTE from sentry_sdk.utils import transaction_from_function if MYPY: from typing import Any, Callable, Dict - from sentry_sdk.scope import Scope +try: + from sentry_sdk.integrations.starlette import ( + StarletteIntegration, + StarletteRequestExtractor, + ) +except DidNotEnable: + raise DidNotEnable("Starlette is not installed") + try: import fastapi # type: ignore except ImportError: