Skip to content

Stop writing an empty trace payload from the tail exporter - #272

Open
ayaangazali wants to merge 1 commit into
pydantic:mainfrom
ayaangazali:tail-empty-export
Open

Stop writing an empty trace payload from the tail exporter#272
ayaangazali wants to merge 1 commit into
pydantic:mainfrom
ayaangazali:tail-empty-export

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

TailWorkerExporter.shutdown() calls sendSpans([]), which serializes a batch of zero spans and logs the result. JsonTraceSerializer.serializeRequest([]) returns {"resourceSpans":[]}, so every shutdown writes an empty export into the tail stream.

That matters because of how the payload is picked up. exportTailEventsToLogfire forwards the first logged object that has a resourceSpans key, and an empty one qualifies. On 4691011, with the empty payload logged before the real one in the same batch:

const events = [{ logs: [
  { message: [{ resourceSpans: [] }] },
  { message: [{ resourceSpans: [{ scopeSpans: [{ spans: [{ name: 'real-span' }] }] }] }] },
] }]
await exportTailEventsToLogfire(events, { LOGFIRE_TOKEN: token })
// POST -> {"resourceSpans":[]}

The request goes out empty and real-span is never sent.

The fix returns early from sendSpans when the batch is empty, which covers export([]) as well, and drops the sendSpans([]) call from shutdown since emitting that payload was its only effect. The exporter has nothing to flush anyway: each batch is written as it arrives.

Two regressions, in a new test file next to the exporter: an empty export plus a shutdown write nothing and still report success, and a batch with a span still writes its payload. The first fails without the guard, the second fails if the guard returns unconditionally.

Built this with Claude Code's help and reviewed the diff myself.

Copilot AI lite review requested due to automatic review settings August 25, 2026 17:09

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 25, 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: c1acac88-0f60-4b7b-83f2-c8557859a23e

📥 Commits

Reviewing files that changed from the base of the PR and between 4691011 and e035690.

📒 Files selected for processing (3)
  • .changeset/tail-empty-export.md
  • packages/logfire-cf-workers/src/TailWorkerExporter.test.ts
  • packages/logfire-cf-workers/src/TailWorkerExporter.ts
🔗 Linked repositories identified

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

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)

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


📝 Walkthrough

Walkthrough

TailWorkerExporter.shutdown() no longer sends an empty span batch. sendSpans() returns a successful result without serialization or logging when the batch is empty. Non-empty batches retain their existing serialization and logging behavior. Tests cover empty exports, shutdown, and non-empty payloads. A patch changeset documents the fix.

Merge Risk: ⚪ Minimal · up to e0356

The PR prevents empty trace payloads from being emitted while preserving successful empty exports and non-empty span delivery; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: the tail exporter no longer writes empty trace payloads.
Description check ✅ Passed The description accurately explains the empty-payload issue, the implementation changes, and the regression tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

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


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

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Seven days, so a status note rather than a new question.

Still reproduces on 0a592e4. shutdown() calls sendSpans([]), which serializes to {"resourceSpans":[]} and logs it, and findTraceEntry returns the first logged object carrying a resourceSpans key and stops looking. So when the empty payload lands ahead of a real one in the same tail batch, the batch's actual spans are dropped.

Green, no conflicts, drift 0 on the two files it touches, and CodeRabbit approved it on the 25th.

Worth restating one thing from the body, since it is the part I would push back on if I were reviewing: restoring sendSpans([]) in shutdown does not fail any test once the empty-batch guard exists, so that deletion is unpinned on purpose. It stays because emitting the payload was the call's only effect.

Happy to close this if the Cloudflare packages are parked for now. I would rather that than have it sit in your queue.

Built this with Claude Code's help and reviewed the diff myself.

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.

2 participants