From d4623f6802711f4ba72164049a086a2eecf5426e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Gu=C3=A9rin?= Date: Sat, 14 Jan 2023 14:04:21 +0100 Subject: [PATCH] Avoid import of pkg_resource with Starlette integration By changing the order in the condition, we can avoid the call to `_get_installed_modules` (which imports `pkg_resources`) when the `mechanism_type` is set to `"starlette"`. --- sentry_sdk/integrations/asgi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index cfeaf4d298..6952957618 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -108,7 +108,7 @@ def __init__( ) asgi_middleware_while_using_starlette_or_fastapi = ( - "starlette" in _get_installed_modules() and mechanism_type == "asgi" + mechanism_type == "asgi" and "starlette" in _get_installed_modules() ) if asgi_middleware_while_using_starlette_or_fastapi: logger.warning(