Skip to content

End the Analytics Engine span when a write rejects - #201

Merged
petyosi merged 1 commit into
pydantic:mainfrom
ayaangazali:ae-span-error-handling
Aug 2, 2026
Merged

End the Analytics Engine span when a write rejects#201
petyosi merged 1 commit into
pydantic:mainfrom
ayaangazali:ae-span-error-handling

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

instrumentAEFn in packages/otel-cf-workers/src/instrumentation/analytics-engine.ts called span.end() only on the success path, with no try/catch/finally around the wrapped call. So when writeDataPoint rejects, the span is never ended and never exported: the operation disappears from the trace entirely and the failure leaves no trace at all, which is the opposite of what you want from a failed write. Every sibling instrumentation in the package already guards this, for example do-storage.ts records the exception, sets ERROR, and ends the span in a finally.

This applies that same shape here, so a rejected write now ends its span with an exception event and ERROR status and still rethrows the original error unchanged.

The instrumented behavior had no test coverage at all before this, only the attribute helper did, so I added two cases against an InMemorySpanExporter: one for the success path and one for the rejection. The rejection test fails on current main with expected [] to have a length of 1, which is the missing span. Ran pnpm run check from the root, all green. Patch changeset for @pydantic/otel-cf-workers included.

quick disclosure: Claude Code helped me put this together and I read the final diff myself. Freshman still learning my way around the Workers runtime, so corrections welcome :)

Copilot AI review requested due to automatic review settings August 1, 2026 21:02

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 1, 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: af86a6da-6ff4-48f0-a37e-feb0522633ba

📥 Commits

Reviewing files that changed from the base of the PR and between e4762be and 6b4a35a.

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

Analytics Engine instrumentation now wraps writes in try/catch/finally. Successful writes retain their span attributes and query text. Failed writes record exceptions, set span status to ERROR, rethrow the original error, and end the span. Tests cover successful and rejected writes. A patch changeset documents the updated behavior.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: ending the Analytics Engine span when a write rejects.
Description check ✅ Passed The description directly explains the instrumentation fix, added tests, error behavior, 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.

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