Skip to content

End the queue producer span when a send rejects - #203

Merged
petyosi merged 1 commit into
pydantic:mainfrom
ayaangazali:queue-send-error-handling
Aug 3, 2026
Merged

End the queue producer span when a send rejects#203
petyosi merged 1 commit into
pydantic:mainfrom
ayaangazali:queue-send-error-handling

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

instrumentQueueSend and instrumentQueueSendBatch in packages/otel-cf-workers/src/instrumentation/queue.ts called span.end() only after the wrapped call resolved, with nothing wrapping it. So a rejected queue.send() or queue.sendBatch() leaves its span unended and therefore never exported: the send disappears from the trace and the failure leaves no record, which is exactly when you would want the span. The queue consumer handler further up the same file already guards its own path, and the other bindings do too, so the producer side was the odd one out.

Both now record the exception, set ERROR, and end the span in a finally, rethrowing the original error untouched. This is the same fix as #201 for Analytics Engine, found by sweeping the instrumentation directory for files whose span.end() count exceeded their finally count.

There was no test file for the queue bindings, so I added one covering a successful send plus both rejection paths. The two rejection tests fail on current main with expected [] to have a length of 1, which is the span that never arrives. Ran the repo preflight and pnpm run check, both green. Patch changeset for @pydantic/otel-cf-workers included.

quick disclosure: built with Claude Code's help and I went through the diff myself before opening. Freshman still learning the Workers side, so tell me if the producer span should behave differently on failure :)

Copilot AI review requested due to automatic review settings August 3, 2026 01:01

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 3, 2026

Copy link
Copy Markdown

Review Change Stack

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: 18108998-088b-45b7-820b-7bbc6175c857

📥 Commits

Reviewing files that changed from the base of the PR and between f00f72f and d2930a6.

📒 Files selected for processing (3)
  • .changeset/queue-send-error-handling.md
  • packages/otel-cf-workers/src/instrumentation/queue.ts
  • packages/otel-cf-workers/test/instrumentation/queue.test.ts
🔗 Linked repositories identified

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

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

📝 Walkthrough

Walkthrough

Queue send and sendBatch instrumentation now records rejected operations as span errors, rethrows the original errors, and always ends spans. Tests cover successful and failed operations, span attributes, completion, error status, exception events, and error propagation. A patch changeset documents the behavior.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: ending queue producer spans when sends reject.
Description check ✅ Passed The description directly explains the queue instrumentation fix, tests, error handling, and changeset.
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

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

@petyosi
petyosi merged commit 6d1a80a into pydantic:main Aug 3, 2026
5 checks passed
petyosi added a commit that referenced this pull request Aug 3, 2026
The consumer handler recorded the exception but left the span status
UNSET, the same gap #203 closed for the producer sends and #204 closed
for the email handler. It fell between those two PRs, so close it here.
@coderabbitai coderabbitai Bot mentioned this pull request Aug 3, 2026
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.

3 participants