Skip to content

Keep tail-sampling buffers until every span in the trace has ended - #2308

Merged
alexmojaki merged 6 commits into
pydantic:mainfrom
gyanu2507:fix/tail-sampling-late-spans
Aug 27, 2026
Merged

Keep tail-sampling buffers until every span in the trace has ended#2308
alexmojaki merged 6 commits into
pydantic:mainfrom
gyanu2507:fix/tail-sampling-late-spans

Conversation

@gyanu2507

@gyanu2507 gyanu2507 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

Review in cubic

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.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Warning

Your free Security trial is over. An organization admin can activate billing to continue.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 71b95b60-a3e0-476d-89f2-1bdab3a68968

📥 Commits

Reviewing files that changed from the base of the PR and between e484a6b and 1b07955.

📒 Files selected for processing (2)
  • logfire/sampling/_tail_sampling.py
  • tests/test_tail_sampling.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)
  • pydantic/platform (auto-detected)
  • pydantic/pydantic (auto-detected)

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Important

Approval pending

CodeRabbit 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.

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Tail 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)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: retaining tail-sampling buffers until all spans in a trace end.
Description check ✅ Passed The description directly explains the dropped-trace bug, late qualifying spans, and the implemented buffer-lifetime fix.
Linked Issues check ✅ Passed The implementation tracks outstanding spans and the tests cover both dropped traces and late spans that cause sampling, satisfying issue #2273.
Out of Scope Changes check ✅ Passed The code and tests remain focused on tail-sampling buffer lifetime and the behavior described in issue #2273.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

cubic-dev-ai[bot]

This comment was marked as resolved.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread docs/how-to-guides/sampling.md

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review
@alexmojaki
alexmojaki added this pull request to the merge queue Aug 27, 2026
@alexmojaki

Copy link
Copy Markdown
Contributor

Thanks!

Merged via the queue into pydantic:main with commit 2670883 Aug 27, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants