Skip to content

feat(cloudflare): instrument Workers KV bindings - #25488

Open
faizansaiyed123 wants to merge 8 commits into
getsentry:developfrom
faizansaiyed123:feat/cloudflare-kv-instrumentation
Open

faizansaiyed123 wants to merge 8 commits into
getsentry:developfrom
faizansaiyed123:feat/cloudflare-kv-instrumentation

Conversation

@faizansaiyed123

Copy link
Copy Markdown
Contributor

Fixes #24037

Implements the Workers KV portion of #24037.

  • add isKVNamespace detection using get, put, list, and getWithMetadata, excluding JSRPC proxies
  • add KV instrumentation for get, getWithMetadata, put, delete, and list
  • emit cache spans with KV cache/database attributes
  • add unit tests and a Cloudflare integration suite

Vectorize and Analytics Engine remain separate follow-ups.

@faizansaiyed123
faizansaiyed123 requested a review from a team as a code owner October 18, 2026 04:18
@faizansaiyed123
faizansaiyed123 requested review from JPeer264 and mydea and removed request for a team October 18, 2026 04:18
@github-actions github-actions Bot added the external PR from an external contributor label Oct 18, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/cloudflare/src/instrumentations/worker/instrumentKV.ts Outdated
Comment thread packages/cloudflare/test/instrumentations/worker/instrumentKV.test.ts Outdated
Comment thread dev-packages/cloudflare-integration-tests/suites/kv/test.ts
@faizansaiyed123
faizansaiyed123 force-pushed the feat/cloudflare-kv-instrumentation branch from bf253b0 to c23d2c8 Compare October 18, 2026 04:34

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/cloudflare/test/instrumentations/instrumentEnv.test.ts Outdated
Comment thread dev-packages/cloudflare-integration-tests/suites/kv/test.ts
@faizansaiyed123

Copy link
Copy Markdown
Contributor Author

Hi @isaacs, following up on our discussion in #24037.

I’ve kept this PR focused on Workers KV as agreed. I also made a small test cleanup and added explicit coverage that cache.key is absent from KV list spans.

Could you please take another look when you have a chance? Thanks for your guidance!

@JPeer264 JPeer264 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.

Thanks a lot for creating the PR. The code looks great overall. Just found couple of small things - once they are addressed we can ship it

expect(spans).toEqual(
expect.arrayContaining([
expect.objectContaining({
attributes: expect.objectContaining({

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.

It'd be nice if you could be more explicit about what attributes are in there. Our /write-tests skill can help out here in case you have an agent.

})
.start(signal);

await runner.makeRequest('get', '/kv/list');

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.

Could you add a test where you call at least 2 endpoints? Not that something is off, but would be nice to just double check that two requests are for sure sent in separate spans

MY_KV: KVNamespace;
}

export default Sentry.withSentry(

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.

Optional, since we haven't migrated most of it yet, but I would suggest to rewrite it so Vite is being used. For that you only need to create a vite.config.mts and a instrument.server.ts - there should be other integration tests lying around that have the same pattern.

const client = getClient();

return {
name: client && hasSpanStreamingEnabled(client) ? cacheOperation : keys?.join(', ') || operation,

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.

Here we don't need to check for streamed spans anymore (we just had to add this for instrumentations that were there before we added span streaming)

Suggested change
name: client && hasSpanStreamingEnabled(client) ? cacheOperation : keys?.join(', ') || operation,
name: cacheOperation,

@JPeer264

Copy link
Copy Markdown
Member

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@faizansaiyed123
faizansaiyed123 requested a review from a team as a code owner October 20, 2026 10:35
@faizansaiyed123
faizansaiyed123 requested review from logaretm and removed request for a team October 20, 2026 10:35
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

This PR is too large for Bugbot to review. It changes 86,197 lines and 3,466,497 characters. Split the change into smaller pull requests to get a review.

@faizansaiyed123
faizansaiyed123 force-pushed the feat/cloudflare-kv-instrumentation branch from be68e22 to 3bdf95a Compare October 20, 2026 10:35
@faizansaiyed123
faizansaiyed123 force-pushed the feat/cloudflare-kv-instrumentation branch from e5147de to f89897e Compare October 20, 2026 10:36

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f89897e. Configure here.

Comment thread packages/cloudflare/src/instrumentations/worker/instrumentKV.ts Outdated

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudflare: Several common bindings are not instrumented

2 participants