Fix spans for streaming responses in WSGI based frameworks (#3798) · gitcommit90/sentry-python@da20623 · GitHub
Skip to content

Commit da20623

Browse files
authored
Fix spans for streaming responses in WSGI based frameworks (getsentry#3798)
Fixes spans in streaming responses when using WSGI based frameworks. Only close the transaction once the response was consumed. This way all the spans created during creation of the response will be recorded with the transaction: - The transaction stays open until all the streaming blocks are sent to the client. (because of this I had to update the tests, to make sure the tests, consume the response, because the Werkzeug test client (used by Flask and Django and our Strawberry tests) will not close the WSGI response) - A maximum runtime of 5 minutes for transactions is enforced. (like Javascript does it) - When using a generator to generate the streaming response, it uses the correct scopes to have correct parent-child relationship of spans created in the generator. People having Sentry in a streaming application will: - See an increase in their transaction duration to up to 5 minutes - Get the correct span tree for streaming responses generated by a generator Fixes getsentry#3736
1 parent a7c2d70 commit da20623

6 files changed

Lines changed: 270 additions & 73 deletions

File tree

sentry_sdk/integrations/wsgi.py

Lines changed: 94 additions & 41 deletions

sentry_sdk/tracing_utils.py

Lines changed: 18 additions & 0 deletions

0 commit comments

Comments
 (0)