Mark D1 batch statement spans as errors when the batch fails - #207
Mark D1 batch statement spans as errors when the batch fails#207ayaangazali wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughD1 batch instrumentation now marks every query span with Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/otel-cf-workers/test/instrumentation/d1.test.ts (1)
72-76: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert exception event placement.
The test verifies statuses but not the contract that only the parent span records the exception. Assert one
exceptionevent onparentand zero such events on each query span. This prevents a future change from duplicating exception events.Proposed test addition
expect(parent?.status.code).toBe(SpanStatusCode.ERROR) + expect(parent?.events.filter((event) => event.name === 'exception')).toHaveLength(1) expect(querySpans).toHaveLength(2) for (const span of querySpans) { expect(span.status.code).toBe(SpanStatusCode.ERROR) + expect(span.events.filter((event) => event.name === 'exception')).toHaveLength(0) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/otel-cf-workers/test/instrumentation/d1.test.ts` around lines 72 - 76, Update the assertions in the D1 instrumentation test around parent and query span status checks to verify exception event placement: assert that parent contains exactly one exception event, and each span in querySpans contains none. Keep the existing status and span-count assertions unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/otel-cf-workers/test/instrumentation/d1.test.ts`:
- Around line 72-76: Update the assertions in the D1 instrumentation test around
parent and query span status checks to verify exception event placement: assert
that parent contains exactly one exception event, and each span in querySpans
contains none. Keep the existing status and span-count assertions unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ea6e9a59-ce0f-4b92-b990-d1189b7c125f
📒 Files selected for processing (3)
.changeset/d1-batch-subspan-status.mdpackages/otel-cf-workers/src/instrumentation/d1.tspackages/otel-cf-workers/test/instrumentation/d1.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
pydantic/logfire(manual)pydantic/pydantic-ai(manual)
petyosi
left a comment
There was a problem hiding this comment.
Reviewed the full diff and relevant surrounding code. No significant correctness, failure-mode, compatibility, or test-coverage issues found.
b7958f1 to
8f893c6
Compare
|
Rebased onto current main (79bcac0) and re-verified there. Approved and clean, no conflicts. Recap since it has been a couple of weeks: Happy to close it if you would rather not take this one. |
instrumentD1Fncreates one span per statement in abatch()call (packages/otel-cf-workers/src/instrumentation/d1.ts:116), but the catch only setsERRORon the parent span. The statement spans are ended in thefinallywith their status stillUNSET, so a failed batch renders as a failed parent with a set of apparently successful queries underneath it, which reads exactly backwards from what happened.This sets the error status on the statement spans too. I left the exception itself on the parent rather than recording it once per statement, since it is one failure rather than N, but say the word if you would rather each statement span carried it.
There was no test file for the D1 bindings, so I added one covering a successful batch and a rejected one. The rejection test fails on current main with
expected +0 to be 2, that beingUNSETwhereERRORwas expected. Ran the repo preflight andpnpm run check, both green. Patch changeset for@pydantic/otel-cf-workersincluded.Worth noting this one hid from the sweep I used for #201, #203 and #204: d1.ts pairs
recordExceptionandsetStatusthree times each, so it looked balanced, and only reading the batch branch showed the sub-spans were missed.quick disclosure: built with Claude Code's help and I read the final diff myself. Freshman still learning, so corrections welcome :)