feat(cloudflare): Add @sentry/cloudflare/vite orchestrion plugin #21967
feat(cloudflare): Add @sentry/cloudflare/vite orchestrion plugin #21967JPeer264 wants to merge 2 commits into
Conversation
size-limit report 📦
|
18b7454 to
596608d
Compare
596608d to
f5c454b
Compare
4d78130 to
b66e928
Compare
515173e to
45a679c
Compare
b66e928 to
332ece3
Compare
45a679c to
6e6c5b7
Compare
baafdd8 to
931a37a
Compare
6e6c5b7 to
d6c0992
Compare
95c6874 to
c0dfebc
Compare
4da617b to
965040a
Compare
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 965040a. Configure here.
c7a4227 to
f750c0d
Compare
b341ad9 to
06971c5
Compare
2a66913 to
7249eff
Compare
e7262f3 to
6713fc3
Compare
7249eff to
afcb71d
Compare
| "types": "./build/types/vite/index.d.ts", | ||
| "import": "./build/esm/vite/index.js" |
There was a problem hiding this comment.
Don't you need the cjs export here as well? Other exports have it 👀
Edit: I just noticed the comment above that it's only ESM. But this PR could fix that: #22286
| sentryCloudflareVitePlugin({ | ||
| _experimental: { | ||
| useDiagnosticsChannelInjection: true, | ||
| }, | ||
| }), |
There was a problem hiding this comment.
Is this the only option that would be needed to enable this?
Asking because usually, there's still the Sentry.experimentalUseDiagnosticsChannelInjection(); before init (while we're on v10).
There was a problem hiding this comment.
Yes. experimentalUseDiagnosticsChannelInjection wouldn't have an effect right now, because the Cloudflare SDK is using the core client and not the one from the Node SDK.
That would only change if we move this entire snippet over to Cloudflare directly:
6713fc3 to
0d56181
Compare
8517822 to
7e8f420
Compare
| */ | ||
| function getRegisteredChannelIntegrations(): Integration[] { | ||
| const marker = GLOBAL_OBJ.__SENTRY_ORCHESTRION__; | ||
| const registered = marker?.integrations || []; | ||
|
|
||
| return registered.map(factory => factory()); |
There was a problem hiding this comment.
Bug: The bundler property on globalThis.__SENTRY_ORCHESTRION__ is typed as string[] but is set to a boolean true by the Vite plugin, creating a type inconsistency.
Severity: LOW
Suggested Fix
To ensure type consistency, the Vite plugin should be updated to set globalThis.__SENTRY_ORCHESTRION__.bundler to a value that matches its string[] type. For example, instead of true, it could be set to an empty array [] or a specific marker array like ['vite'] if that information is useful for debugging.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/cloudflare/src/sdk.ts#L29-L34
Potential issue: A type mismatch exists for the `bundler` property on the global
`__SENTRY_ORCHESTRION__` object. The property is typed as `string[]` in `worldwide.ts`,
but the Vite plugin introduced in this pull request sets it to a boolean value (`true`).
While the current runtime usage only checks for truthiness, which works for both types,
this inconsistency violates the established type contract. This could lead to future
runtime errors if other code is added that expects `bundler` to be an array and attempts
to use array methods on it. The mismatch creates a type safety issue that should be
corrected for code consistency and to prevent potential future bugs.
Also affects:
packages/cloudflare/src/vite/index.ts:35~35
Did we get this right? 👍 / 👎 to inform future reviews.
b59ebba to
157e383
Compare
cfc41ca to
d2a6c9f
Compare
…tics channels Integrate the server-utils orchestrion channel-integration mechanism into the Cloudflare SDK, so bundled npm packages (e.g. `mysql`) are traced without monkey-patching, which workerd doesn't support anyway. - Add the `@sentry/cloudflare/vite` plugin, which runs the orchestrion transform (injecting `diagnostics_channel.tracingChannel` calls) and injects a registration module that puts the channel-subscriber integrations on the global marker. Workers built without the plugin don't ship that code. - `getDefaultIntegrations()` reads the registered integrations from the marker at `init()`, activating only those whose module was actually transformed, and warns (debug only, once per isolate) about modules whose transform failed. - Add a Cloudflare + MySQL e2e test app exercising real `db` spans in workerd. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tics channels Integrate the server-utils orchestrion channel-integration mechanism into the Cloudflare SDK, so bundled npm packages (e.g. `mysql`) are traced without monkey-patching, which workerd doesn't support anyway. - Add the `@sentry/cloudflare/vite` plugin, which runs the orchestrion transform (injecting `diagnostics_channel.tracingChannel` calls) and injects a registration module that puts the channel-subscriber integrations on the global marker. Workers built without the plugin don't ship that code. - `getDefaultIntegrations()` reads the registered integrations from the marker at `init()`, activating only those whose module was actually transformed, and warns (debug only, once per isolate) about modules whose transform failed. - Add a Cloudflare + MySQL e2e test app exercising real `db` spans in workerd. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
157e383 to
6755627
Compare
d2a6c9f to
dbd5795
Compare
closes #22062
This adds a
/viteplugin for Cloudflare that adds Orchestrion on build time. It adds all orchestrion integrations in thedefaultIntegrations, which adds more bundle size - this is not optimal and will be adapted in a follow up PR. Best case scenario: Only add integrations which the user really installed.For now the user only has to add the following to the Vite config:
import { cloudflare } from '@cloudflare/vite-plugin'; + import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; import { defineConfig } from 'vite'; export default defineConfig({ - plugins: [cloudflare()], + plugins: [ + cloudflare(), + sentryCloudflareVitePlugin({ + _experimental: { + useDiagnosticsChannelInjection: true, + } + }) + ], });The
_experimental.useDiagnosticsChannelInjectionis the same as we have in Next.js via the Webpack plugin - so it stays consistentAlso the migration from pure wrangler to Vite is as easy as just adding
vite.config.tsand prependingvite buildbeforewrangler deploy: https://developers.cloudflare.com/workers/vite-plugin/reference/migrating-from-wrangler-dev/