diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index b2ecfe23b7..28165f1670 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -207,7 +207,11 @@ async def _run_app(self, scope, receive, send, asgi_version): method = scope.get("method", "").upper() should_trace = method in self.http_methods_to_capture - with sentry_sdk.continue_trace(_get_headers(scope)): + with ( + sentry_sdk.continue_trace(_get_headers(scope)) + if should_trace + else nullcontext() + ): with ( sentry_sdk.start_span( op=(