Skip to content

ref(cloudflare): Extract one factory for the Vite provider plugins - #24535

Draft
RulaKhaled wants to merge 1 commit into
developfrom
feat/cloudflare-provider-plugin-factory
Draft

RulaKhaled wants to merge 1 commit into
developfrom
feat/cloudflare-provider-plugin-factory

Conversation

@RulaKhaled

@RulaKhaled RulaKhaled commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #24476, where @isaacs pointed out that flueRuntime.ts and mastraObservability.ts are near-identical and drifting. Both are now a few lines over a shared createProvidedModulePlugin, so the next provider is a config object rather than a third copy.

The probe moves from createRequire().resolve() to the Rollup context's this.resolve(), which uses the same resolver and conditions as the injected import. That drops createRequire, node:path and the error-code special case, and fixes a latent Mastra bug: its bare catch { return; } only works because @mastra/observability still publishes a require condition, so an ESM-only release would have turned injection off silently, the same failure #24476 fixed for Flue. this.resolve() needs a plugin context, so the probe moves to buildStart and configResolved stays only to capture the app root. Resolution runs per environment against a shared instance, so it stops once the package is found and retries otherwise, since the worker environment may not run first.

Mastra also picks up the guards Flue gained in #24476: transform is idempotent, a resolver error injects rather than skipping, and the namespace goes behind the same lazy getter. Assigning reads the binding at injection time and stores undefined if the bundler evaluates Sentry's module first, which is not Flue-specific, so there is one shape for both and no lazy option.

cloudflare-mastra is the real check here: on workerd the injected binding is the only path loadMastraObservability can take, so a broken injection means no agent spans and a failing suite.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.09 kB - -
@sentry/browser - with treeshaking flags 27.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.26 kB - -
@sentry/browser (incl. Tracing) 50.56 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.58 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.56 kB - -
@sentry/browser (incl. Tracing, Replay) 90.11 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.21 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.81 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.78 kB - -
@sentry/browser (incl. Feedback) 46.62 kB - -
@sentry/browser (incl. sendFeedback) 34.15 kB - -
@sentry/browser (incl. FeedbackAsync) 39.26 kB - -
@sentry/browser (incl. Metrics) 30.1 kB - -
@sentry/browser (incl. Logs) 30.35 kB - -
@sentry/browser (incl. Metrics & Logs) 31.02 kB - -
@sentry/react 30.84 kB - -
@sentry/react (incl. Tracing) 52.88 kB - -
@sentry/vue 36.34 kB - -
@sentry/vue (incl. Tracing) 52.86 kB - -
@sentry/svelte 29.11 kB - -
CDN Bundle 30.8 kB - -
CDN Bundle (incl. Tracing) 51.1 kB - -
CDN Bundle (incl. Logs, Metrics) 33.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.75 kB - -
CDN Bundle (incl. Tracing, Replay) 88.66 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.71 kB - -
CDN Bundle - uncompressed 91.16 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.53 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.49 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.14 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 272.1 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 278.04 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.74 kB - -
@sentry/nextjs (client) 55.21 kB - -
@sentry/sveltekit (client) 50.99 kB - -
@sentry/core/server 40 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 133.37 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.19 kB -0.01% -2 B 🔽
@sentry/node - without tracing 89.96 kB +0.03% +23 B 🔺
@sentry/node - without channel injection 112.15 kB +0.02% +16 B 🔺
@sentry/aws-serverless 98.23 kB +0.02% +19 B 🔺
@sentry/cloudflare (withSentry) - minified 204.74 kB - -
@sentry/cloudflare (withSentry) 509.41 kB - -

View base workflow run

Base automatically changed from feat/flue-cloudflare-autoinstrument to develop September 21, 2026 09:20
@RulaKhaled
RulaKhaled force-pushed the feat/cloudflare-provider-plugin-factory branch from 5ece63b to 7ca5878 Compare September 21, 2026 09:23
`flueRuntime.ts` and `mastraObservability.ts` were near-identical, differing
only in the module specifier, the injected identifier, the target regex, how
they handled a failed resolve, and getter versus assignment. Both call sites are
now a few lines over a shared `createProvidedModulePlugin`.

Replace the `createRequire().resolve()` probe with the Rollup context's
`this.resolve()`, which answers with the same resolver and conditions the
injected import will use. That drops `createRequire`, `node:path` and the
error-code special case, and it fixes a latent bug on the Mastra side: its bare
`catch { return; }` worked only because `@mastra/observability` still publishes
a `require` condition, so an ESM-only release would have turned injection off
with no error and no log. The probe needs a plugin context, so it moves from
`configResolved` to `buildStart`. `configResolved` stays to capture the app
root.

Resolution runs per environment against a shared plugin instance, so the probe
stops once it finds the package and retries in the next environment otherwise.
Only the worker environment ever reaches `transform`, and it may not run first.

Mastra also picks up the guards Flue gained in #24476: `transform` is
idempotent, a resolver error injects rather than silently skipping, and the
namespace now goes behind the same lazy getter. Assigning reads the binding at
injection time, so it stores `undefined` whenever the bundler evaluates Sentry's
module first. That hazard is not specific to Flue, so both providers use one
shape and the `lazy` option is gone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@RulaKhaled
RulaKhaled force-pushed the feat/cloudflare-provider-plugin-factory branch from 7ca5878 to 8b3cbd3 Compare September 21, 2026 09:43
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.

1 participant