Skip to content

Commit c32c202

Browse files
committed
Manually close transaction in flask
1 parent beeee5f commit c32c202

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sentry_sdk/integrations/flask.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
before_render_template,
3737
got_request_exception,
3838
request_started,
39+
request_finished,
3940
)
4041
from markupsafe import Markup
4142
except ImportError:
@@ -82,6 +83,7 @@ def setup_once():
8283

8384
before_render_template.connect(_add_sentry_trace)
8485
request_started.connect(_request_started)
86+
request_finished.connect(_request_finished)
8587
got_request_exception.connect(_capture_exception)
8688

8789
old_app = Flask.__call__
@@ -152,6 +154,11 @@ def _request_started(app, **kwargs):
152154
scope.add_event_processor(evt_processor)
153155

154156

157+
def _request_finished(sender, response, **kwargs):
158+
# Manually close the transaction because Bottle does not call `close()` on the WSGI response
159+
sentry_sdk.get_current_scope().transaction.__exit__(None, None, None)
160+
161+
155162
class FlaskRequestExtractor(RequestExtractor):
156163
def env(self):
157164
# type: () -> Dict[str, str]

0 commit comments

Comments
 (0)