Skip to content

Record http.url on cache spans for string and URL keys - #209

Open
ayaangazali wants to merge 1 commit into
pydantic:mainfrom
ayaangazali:cache-url-attribute
Open

Record http.url on cache spans for string and URL keys#209
ayaangazali wants to merge 1 commit into
pydantic:mainfrom
ayaangazali:cache-url-attribute

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

The Cache methods accept RequestInfo | URL, so the key can be a Request, a bare string, or a URL. instrumentFunction in packages/otel-cf-workers/src/instrumentation/cache.ts read the url as argArray[0].url, which only exists on a Request, so caches.default.match('https://example.com/x') and the URL form both produced a cache span with no http.url at all. Two of the three documented input shapes lost the attribute.

This pulls the url out of whichever shape was passed. I also made sanitiseURL return undefined instead of throwing on something unparseable, because it runs while building the span attributes, before the span exists, so a throw there would have surfaced inside the caller's own cache call rather than as a failed span.

There was no test file for the cache bindings, so I added one covering all three key shapes plus an unparseable one. The string and URL cases fail on current main with expected undefined to be 'https://example.com/...'. Ran the repo preflight and pnpm run check, both green. Patch changeset for @pydantic/otel-cf-workers included.

quick disclosure: worked through this with Claude Code and read the final diff myself. Freshman still learning, so if you would rather keep the attribute Request-only I am happy to drop it :)

Copilot AI review requested due to automatic review settings August 4, 2026 07:21

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 4, 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: 2f0533ce-ea39-46d7-8a0f-f0336845a87a

📥 Commits

Reviewing files that changed from the base of the PR and between 28a13c0 and 7f5ab2a.

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

Cache instrumentation now extracts URLs from string keys, URL objects, and request-like objects. Valid URLs are recorded as the http.url span attribute. Invalid or unsupported keys omit the attribute without throwing. Tests cover valid Request, string, and URL keys, plus invalid URLs. A patch changeset documents the behavior.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: recording http.url for string and URL cache keys.
Description check ✅ Passed The description directly explains the cache instrumentation change, error handling, tests, 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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff and relevant surrounding code. No significant correctness, failure-mode, compatibility, or test-coverage issues found.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (79bcac0) and re-verified there. Approved and clean, no conflicts.

Recap: Cache methods accept RequestInfo | URL, but the attribute was read as argArray[0].url, which only exists on a Request. String keys and URL keys both produced cache spans with no http.url, so two of the three documented input shapes lost it.

Happy to close it if you would rather not take this one.

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