Skip to content

feat(core): Instrument workers-ai-provider#22119

Draft
JPeer264 wants to merge 1 commit into
developfrom
jp/cloudflare-workers-ai
Draft

feat(core): Instrument workers-ai-provider#22119
JPeer264 wants to merge 1 commit into
developfrom
jp/cloudflare-workers-ai

Conversation

@JPeer264

@JPeer264 JPeer264 commented Jul 8, 2026

Copy link
Copy Markdown
Member

closes #20839
closes JS-2449

This is instrumenting workers-ai, but it needs to be wrapped, as in Cloudflare there is no monkey patching for bindings. In a follow-up PR this will be included in the instrumentEnv within Cloudflare.

Tbh I would have added this into packages/cloudflare, but all AI integrations do live in core, and there are also some utils which are only there and would have needed to export, such as endStreamSpan and all the gen-ai-attributes. The downside of this is that the workers-ai types needed to be vendored in (in the packages/cloudflare we could have taken them from the @cloudflare/workers-types package.

@JPeer264 JPeer264 self-assigned this Jul 8, 2026
@linear-code

linear-code Bot commented Jul 8, 2026

Copy link
Copy Markdown

JS-2449

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.59 kB - -
@sentry/browser - with treeshaking flags 26.03 kB - -
@sentry/browser (incl. Tracing) 46.34 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.13 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.12 kB - -
@sentry/browser (incl. Tracing, Replay) 85.61 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.26 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.32 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.97 kB - -
@sentry/browser (incl. Feedback) 44.76 kB - -
@sentry/browser (incl. sendFeedback) 32.38 kB - -
@sentry/browser (incl. FeedbackAsync) 37.51 kB - -
@sentry/browser (incl. Metrics) 28.67 kB - -
@sentry/browser (incl. Logs) 28.91 kB - -
@sentry/browser (incl. Metrics & Logs) 29.59 kB - -
@sentry/react 29.38 kB - -
@sentry/react (incl. Tracing) 48.61 kB - -
@sentry/vue 33.03 kB - -
@sentry/vue (incl. Tracing) 48.24 kB - -
@sentry/svelte 27.61 kB - -
CDN Bundle 30 kB - -
CDN Bundle (incl. Tracing) 48.32 kB - -
CDN Bundle (incl. Logs, Metrics) 31.57 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.64 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.81 kB - -
CDN Bundle (incl. Tracing, Replay) 85.84 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.92 kB - -
CDN Bundle - uncompressed 89.35 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.1 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.05 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.07 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.75 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.27 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.23 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.97 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.92 kB - -
@sentry/nextjs (client) 51.16 kB - -
@sentry/sveltekit (client) 46.75 kB - -
@sentry/core/server 79.33 kB +1.18% +918 B 🔺
@sentry/core/browser 65.69 kB +1.47% +948 B 🔺
@sentry/node-core 62.72 kB +0.01% +1 B 🔺
@sentry/node 125.33 kB +0.01% +1 B 🔺
@sentry/node (incl. diagnostics channel injection) 134.97 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.72 kB - -
@sentry/node - without tracing 74.05 kB +0.01% +1 B 🔺
@sentry/aws-serverless 85.5 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 181.71 kB - -
@sentry/cloudflare (withSentry) 449.16 kB - -

View base workflow run

@JPeer264

JPeer264 commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

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 a22515d. Configure here.

}) as T;

instrumentedClients.add(instrumented);
return instrumented;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WeakSet misses original client

Medium Severity

instrumentWorkersAiClient only registers the proxy in instrumentedClients, not the binding passed in. A second call with the same original env.AI (or manual wrap after auto instrumentation) is not recognized and wraps again, so each run can emit nested spans.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a22515d. Configure here.


instrumentedClients.add(instrumented);
return instrumented;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing integration or E2E test

Low Severity

This feature PR adds Workers AI instrumentation with unit tests only. Per SDK review guidelines, a feat change should include at least one integration or E2E test exercising the new tracing behavior end-to-end.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit a22515d. Configure here.

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.

Cloudflare instrument workers-ai

1 participant