You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Django StreamingHttpResponse View not working as expected #3736
changed the title [-]Django StreamingHttpResponse not working as expected[/-][+]Django StreamingHttpResponse View not working as expected[/+]on Nov 5, 2024
Do we have a way to set the trace_id?
Maybe an easy fix is to get the trace_id in the view level and pass as parameter to my function and do a transaction.set_trace_id(trace_id=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. 😅
The first span "Streaming View" is present in the trace, but the second span "Stream Response Generator" is missing (because it has the wrong trace id)
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?
This bug is creating a hole in the observability of one of my main endpoints :/
Just to understand if I will need to use another observability tool until you fix this.
I do have some bandwidth to work on this fix but not sure if I have enough context to work on it.
Hey @BSathvik to be honest, I can not give any time estimate for a fix for this.
Right now we are working on the next major of the SDK. This new version will be able to use OpenTelemetry under the hood. This will give us a lot of power and maybe this issue will resolve itself. And if it does not, we will update our Django integration to bring it more in line with OpenTelementry and in the course of this we will also address this issue.
Hello, I have developed a package to provide a work-around for this issue. It is based on the code in the linked PR. It provides a custom integration that keeps the transaction open until gunicorn calls .close() on the StreamingHTTPResponse. It is also compatible with non-streaming responses.
@stephanie-anderson By the way, I recently tried sentry-sdk==3.0.0rc1 to see if it solves this bug, and it doesn't appear to.
Was this release intended to solve this bug? Should I open a different issue if I'm still having this problem? Or is the fix in an upcoming release? If so, could we have clarification on which release the fix is targeted for?
Activity
[-]Django StreamingHttpResponse not working as expected[/-][+]Django StreamingHttpResponse View not working as expected[/+]marcoaleixo commentedon Nov 5, 2024
Do we have a way to set the trace_id?
Maybe an easy fix is to get the trace_id in the view level and pass as parameter to my function and do a transaction.set_trace_id(trace_id=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. 😅
antonpirker commentedon Nov 7, 2024
Hey @marcoaleixo thanks for raising this, I will have a look!
antonpirker commentedon Nov 7, 2024
Indeed!
I have now reproduced this with this demo application:
https://github.com/antonpirker/testing-sentry/blob/main/test-django-rest-framework-streaming/mysite/api/views.py
The first span

"Streaming View"is present in the trace, but the second span"Stream Response Generator"is missing (because it has the wrong trace id)antonpirker commentedon Nov 7, 2024
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.
marcoaleixo commentedon Nov 12, 2024
hey @antonpirker - thanks for taking a look but I have a quick question: how do you prioritize those fixes?
This bug is creating a hole in the observability of one of my main endpoints :/
Just to understand if I will need to use another observability tool until you fix this.
I do have some bandwidth to work on this fix but not sure if I have enough context to work on it.
24 remaining items
BSathvik commentedon Jan 22, 2025
Hey y'all! we're running into the same issue, would you be able to provide a guesstimate for the fix? Thanks!
antonpirker commentedon Jan 23, 2025
Hey @BSathvik to be honest, I can not give any time estimate for a fix for this.
Right now we are working on the next major of the SDK. This new version will be able to use OpenTelemetry under the hood. This will give us a lot of power and maybe this issue will resolve itself. And if it does not, we will update our Django integration to bring it more in line with OpenTelementry and in the course of this we will also address this issue.
antonpirker commentedon Mar 6, 2025
As this feature will be provided in the upcoming major version of the SDK from the OpenTelementry integration, I am closing this issue.
nickodell commentedon May 27, 2025
Hello, I have developed a package to provide a work-around for this issue. It is based on the code in the linked PR. It provides a custom integration that keeps the transaction open until gunicorn calls
.close()on the StreamingHTTPResponse. It is also compatible with non-streaming responses.It is available here.
https://github.com/nickodell/shr_span_recorder
nickodell commentedon Jun 3, 2025
@stephanie-anderson By the way, I recently tried
sentry-sdk==3.0.0rc1to see if it solves this bug, and it doesn't appear to.Was this release intended to solve this bug? Should I open a different issue if I'm still having this problem? Or is the fix in an upcoming release? If so, could we have clarification on which release the fix is targeted for?