-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Django StreamingHttpResponse View not working as expected #3736
Comments
Do we have a way to set the trace_id? But it seems that we don't have a set_trace_id thing at transaction/event level, right? I know that we can do a Span(trace_id=myid), but passing this to ALL calls downstream is bad. 😅 |
Hey @marcoaleixo thanks for raising this, I will have a look! |
Indeed! I have now reproduced this with this demo application: The first span |
This is a bug. I guess it has something to do with how Django handles streaming views and what we monkey patch in Django. Sentry is probably not patching the functions in Django that are handling the streaming responses. |
hey @antonpirker - thanks for taking a look but I have a quick question: how do you prioritize those fixes? Just to understand if I will need to use another observability tool until you fix this. |
Hey! I will have some time today and tomorrow to look at this. I will keep you posted on the progress |
Small update: The problem is that |
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 #3736
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.18.0
Steps to Reproduce
Here the span.trace_id will be for instance "1234"
In this function, the trace_id will be totally different.
I think that this is related the StreamingHttpResponse, because the Sentry is working fine for all my other views.
Feel free to ask more details to help in the investigation.
FROM python:3.9.18-slim-bullseye
Django==4.1
djangorestframework==3.14
I'm executing my server with python manage.py runserver 0.0.0.0:8000
In production we use something like gunicorn api.wsgi -b 0.0.0.0:8081
Expected Result
The trace_id should stay the same in StreamingHttpResponse views and underlying function calls.
Actual Result
The trace_id is different between the view and underlying function calls.
The text was updated successfully, but these errors were encountered: