Keep tail-sampling buffers until every span in the trace has ended - #2308
Conversation
Dropping the buffer when the root ends lets a later child take the pass-through path, so a dropped trace can still export spans and a late span that should sample the trace never sees the rest of it.
|
Warning Your free Security trial is over. An organization admin can activate billing to continue. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Important Approval pendingCodeRabbit has no unresolved comments, but it has not reviewed the latest commit. Use the checkbox below to review the latest commit. CodeRabbit will approve the changes if it finds no blocking issues.
📝 WalkthroughWalkthroughTail sampling now counts started spans for each trace. The trace buffer remains active until all tracked spans end, instead of being removed when the root span ends. Sampled traces can still be released when sampling criteria are met. New tests verify that late spans from dropped traces are not exported and that a late child can cause the complete trace to be exported. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks! |
The buffer was being dropped as soon as the root span ended. Anything that finished after that — a detached child, a background task, a streaming finalizer — hit the no-buffer path and was exported even if the sampler had already decided to drop the trace.
The same release also meant a late span that did meet the sampling criteria could no longer pull the rest of the trace in, so the backend only saw a rootless fragment.
This keeps the buffer until every started span has ended. A dropped trace stays dropped; a late qualifying span can still include the whole trace. Matches the approach in pydantic/logfire-js#230.
Closes #2273