Export every trace payload in a tail batch - #227
Conversation
|
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 (3)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
📝 WalkthroughWalkthroughThe Cloudflare Workers exporter now collects all matching trace entries from a tail-event batch. It merges their Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
findTraceEntry returned on the first entry carrying resourceSpans, so exportTailEventsToLogfire forwarded one payload per tail invocation. A tail worker is handed a batch with one TraceItem per producing invocation, and TailWorkerExporter console.logs a payload per flush, so everything after the first was dropped silently. Collect every entry and merge their resourceSpans into one request, which OTLP already models as a repeated field, so the single Response return stays as it was.
|
Rebased onto Worth separating this from the tail-sampling work in #242, since the names collide: this one is Cloudflare tail-worker event export in Still reproducing on current main. Happy to close it if the CF tail-worker path is not somewhere you want changes right now. |
29636cd to
a00a518
Compare
What is wrong
exportTailEventsToLogfirestops at the first payload it finds:Its input is a batch. A tail worker is handed one
TraceItemper producing invocation, andTailWorkerExporteremits a payload per flush:So a batch normally carries several payloads, and every one after the first is discarded. Nothing warns and nothing fails: the export returns a 200 for the payload it did send, so the loss is invisible from both ends.
Evidence
Three payloads across two batched invocations, one of which flushed twice, on
79bcac0:posts
{"resourceSpans":["first"]}. Two of the three traces never leave the worker. The proportion lost scales with how busy the producing worker is, so it is worst exactly when the traces matter most.What this does
Collects every entry and merges their
resourceSpansinto one request. OTLP already modelsresourceSpansas a repeated field, so this stays a single POST and thePromise<Response | undefined>return is unchanged, rather than becoming N requests with N results to reconcile.Behaviour for a batch with one payload is byte-identical, which the existing User-Agent test pins. Verified by restoring the early return, which fails the new test and no others.
Built this with Claude Code's help and reviewed the diff myself.