diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index 780beeb69a..ef06e76f52 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -264,6 +264,10 @@ def __iter__(self): try: chunk = next(iterator) except StopIteration: + # Close the Sentry transaction (it could be that response.close() is never called by the framework) + # This is done here to make sure the Transaction stays + # open until all streaming responses are done. + finish_running_transaction(self._current_scope) break except BaseException: reraise(*_capture_exception())