Skip to content

Omit the prefix from KV list query text when there is none - #240

Open
ayaangazali wants to merge 1 commit into
pydantic:mainfrom
ayaangazali:kv-list-query-text
Open

Omit the prefix from KV list query text when there is none#240
ayaangazali wants to merge 1 commit into
pydantic:mainfrom
ayaangazali:kv-list-query-text

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

Defect

Every kv.list() call that does not pass a prefix writes the literal text list undefined to db.query.text on the KV span. That is the default list call, so it is the common case rather than an edge case.

Evidence

instrumentKVFn built the query text by interpolation:

const opts: KVNamespaceListOptions = argArray[0] || {}
const { prefix } = opts
span.setAttribute(ATTR_DB_QUERY_TEXT, `${operation} ${prefix || undefined}`)

The || undefined idiom means "omit this" everywhere else in the file, because setAttributes drops undefined values. Inside a template literal it does the opposite: undefined stringifies, so the attribute is always present and reads list undefined when no prefix was given.

Verified against the file's own createSpan / mockTracer harness on current main. instrumentKV(kv, 'CACHE').list() set db.query.text to list undefined.

Fix

Interpolate only when there is a prefix. The attribute stays present either way, so list spans remain consistent with every other KV operation, which always sets it. Truthiness is kept rather than an explicit undefined check, to match how prefix and the surrounding cursor and limit attributes are already treated.

The new test asserts both branches. On the old line it fails with expected 'list undefined' to be 'list'.

One unrelated line is included because it is required, not by choice: kv.test.ts was the only one of the eight test files in that directory without the /// <reference types="@cloudflare/workers-types" /> header, so the pre-commit lint could not resolve KVNamespace in it and rejected the commit. Adding the header matches the other seven.

Built this with Claude Code's help and reviewed the diff myself.

Copilot AI lite review requested due to automatic review settings August 17, 2026 18:08

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 17, 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: 326dce3c-89fe-4947-84ba-13a30a64a94d

📥 Commits

Reviewing files that changed from the base of the PR and between 79bcac0 and bf0cb21.

📒 Files selected for processing (3)
  • .changeset/kv-list-query-text.md
  • packages/otel-cf-workers/src/instrumentation/kv.ts
  • packages/otel-cf-workers/test/instrumentation/kv.test.ts
🔗 Linked repositories identified

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

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

Included review availability: Your plan includes up to 3 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The KV instrumentation now records list as the query text when no prefix is provided. It records list user: when a prefix is provided. Tests cover both cases and restore the tracer spy in a finally block. A patch changeset documents the fix.

Merge Risk: ⚪ Minimal · up to bf0cb

This localized change removes the incorrect undefined text from KV list span query attributes while preserving prefixed lists; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the KV list query text defect, the fix, the tests, and the required type reference.
Title check ✅ Passed The title clearly and concisely describes the primary fix for KV list query text without a prefix.
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.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Still reproduces on 4691011: kv.ts:94 builds the list query text as ${operation} ${prefix || undefined}, so every kv.list() without a prefix, which is the default call, emits db.query.text: "list undefined". The || undefined idiom means "omit" a few lines above at 46-52, where setAttributes really does drop undefined, but inside a template literal it stringifies.

Green and conflict free since it was opened, and no human has looked at it yet. Happy to close it if the Cloudflare packages are not taking changes right now.

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.

2 participants