Skip to content

fix(django): finish streaming spans on response close - #4878

Draft
ahmadalguydi wants to merge 1 commit into
open-telemetry:mainfrom
ahmadalguydi:codex/django-streaming-response
Draft

fix(django): finish streaming spans on response close#4878
ahmadalguydi wants to merge 1 commit into
open-telemetry:mainfrom
ahmadalguydi:codex/django-streaming-response

Conversation

@ahmadalguydi

@ahmadalguydi ahmadalguydi commented Jul 28, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #4681 by keeping Django server spans active for StreamingHttpResponse objects until Django invokes the response's guaranteed close() lifecycle hook.

The existing response status/header instrumentation and response hook still run in process_response; duration metrics, active-request accounting, context detachment, and span finalization are deferred only for streaming responses. The close wrapper is idempotent and finalizes telemetry even when the original close method raises.

Checklist

  • Added regression coverage for deferred span completion and idempotent close handling.
  • Ran the Django middleware test suite.
  • Ran git diff --check and Python compilation.

Test result: 42 passed for instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django Instrumentation: Spans close prematurely for StreamingHttpResponse

1 participant