Skip to content

Commit beeee5f

Browse files
committed
Bottle never calls response.close()
1 parent 5bab9ec commit beeee5f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

sentry_sdk/integrations/bottle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def wrapped_callback(*args, **kwargs):
138138
):
139139
_capture_exception(res, handled=True)
140140

141+
# Manually close the transaction because Bottle does not call `close()` on the WSGI response
142+
sentry_sdk.get_current_scope().transaction.__exit__(None, None, None)
143+
141144
return res
142145

143146
return wrapped_callback

sentry_sdk/integrations/wsgi.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ def __iter__(self):
269269

270270
yield chunk
271271

272+
# Close the Sentry transaction (it could be that response.close() is never called by the framework)
273+
# This is done here to make sure the Transaction stays
274+
# open until all streaming responses are done.
275+
if self._transaction is not None:
276+
self._transaction.__exit__(None, None, None)
277+
272278
def close(self):
273279
# type: () -> None
274280
with use_isolation_scope(self._isolation_scope):
@@ -279,9 +285,8 @@ def close(self):
279285
# Close the Sentry transaction
280286
# This is done here to make sure the Transaction stays
281287
# open until all streaming responses are done.
282-
# Of course this here works also for non streaming responses.
283288
if self._transaction is not None:
284-
self._transaction.__exit__(None, None, None)
289+
self._transaction.__exit__(None, None, None)
285290
except AttributeError:
286291
pass
287292
except BaseException:

0 commit comments

Comments
 (0)