Skip to content

Mark the email handler span as an error when it throws - #204

Merged
petyosi merged 1 commit into
pydantic:mainfrom
ayaangazali:email-error-status
Aug 3, 2026
Merged

Mark the email handler span as an error when it throws#204
petyosi merged 1 commit into
pydantic:mainfrom
ayaangazali:email-error-status

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

executeEmailHandler in packages/otel-cf-workers/src/instrumentation/email.ts records the exception on its span but never sets the span status, so it stays UNSET. A failed email invocation therefore does not read as failed: it carries an exception event but is not picked up by anything filtering on error status. The fetch handler, the alarm handler, and every storage binding already set ERROR alongside recordException, so the email handler was the only one missing it.

I found this by sweeping the instrumentation directory for files where the recordException count and the SpanStatusCode.ERROR count disagree, which is the same approach as #201 and #203. Email was the only remaining mismatch besides the queue consumer, which I have left alone since #203 is already touching that file.

There was no test file for the email handler, so I added one covering the success path and the throwing path. It needed executeEmailHandler exported, which also lines it up with executeFetchHandler and executeQueueHandler that are already exported and tested the same way. The throwing test fails on current main. Ran the repo preflight and pnpm run check, both green, and a patch changeset for @pydantic/otel-cf-workers is included.

quick disclosure: built this with Claude Code's help and read the final diff myself. Freshman still finding my feet here, so say the word if you would rather not export the handler just for a test :)

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

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: 20b6573c-afb9-46d9-89a2-bc5a69552f97

📥 Commits

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

📒 Files selected for processing (3)
  • .changeset/email-error-status.md
  • packages/otel-cf-workers/src/instrumentation/email.ts
  • packages/otel-cf-workers/test/instrumentation/email.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

The email instrumentation now exports executeEmailHandler and sets the active span status to SpanStatusCode.ERROR when the handler throws. The function ends the span and rethrows the error. New tests cover successful execution, failures, span lifecycle, exception recording, error propagation, and tracer cleanup. A patch changeset documents the correction.

Possibly related PRs

  • pydantic/logfire-js#203: Updates Cloudflare Workers instrumentation to record failures, mark spans as ERROR, end spans, rethrow errors, and add tests.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: marking email handler spans as errors when the handler throws.
Description check ✅ Passed The description directly explains the instrumentation change, tests, export, and changeset included in the pull request.
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 dc78163 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.
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