feat(fastapi): Support span streaming in active thread tracking#6118
Merged
ericapisani merged 2 commits intomasterfrom Apr 21, 2026
Merged
feat(fastapi): Support span streaming in active thread tracking#6118ericapisani merged 2 commits intomasterfrom
ericapisani merged 2 commits intomasterfrom
Conversation
When the span streaming experiment is enabled, the current scope has a StreamedSpan instead of a legacy transaction. Detect this case and call the segment's _update_active_thread() so the profiler's active thread id is recorded on the segment in span-first mode. Also parametrize existing tests over streaming/static modes and add a dedicated test asserting the active thread id is attached to the segment when streaming. Refs PY-2322 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 6.25s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 16.67%. Project has 14778 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 31.26% 31.26% —%
==========================================
Files 190 190 —
Lines 21493 21498 +5
Branches 7138 7140 +2
==========================================
+ Hits 6719 6720 +1
- Misses 14774 14778 +4
- Partials 559 559 —Generated by Codecov Action |
sentrivana
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support span-first functionality in the FastAPI integration's active thread tracking, while continuing to support the legacy transaction-based path.
When the span streaming experiment (
trace_lifecycle: "stream") is enabled,current_scope.transactionisNoneand the scope instead holds aStreamedSpan. The existing profiler hook inpatch_get_request_handleronly calledcurrent_scope.transaction.update_active_thread(), so under streaming the profiler'sthread.idwas never attached to the segment. This PR detects theStreamedSpancase and calls_update_active_thread()on its segment; the legacy transaction path is preserved unchanged.Tests are parametrized across streaming and static modes where relevant, and a dedicated test asserts that the active thread id ends up on the segment's attributes when streaming is enabled.
Refs PY-2322
Fixes #6020