ref(cloudflare): Extract one factory for the Vite provider plugins - #24535
Draft
RulaKhaled wants to merge 1 commit into
Draft
RulaKhaled wants to merge 1 commit into
RulaKhaled wants to merge 1 commit into
Conversation
Contributor
size-limit report 📦
|
Base automatically changed from
feat/flue-cloudflare-autoinstrument
to
develop
September 21, 2026 09:20
RulaKhaled
force-pushed
the
feat/cloudflare-provider-plugin-factory
branch
from
September 21, 2026 09:23
5ece63b to
7ca5878
Compare
`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
force-pushed
the
feat/cloudflare-provider-plugin-factory
branch
from
September 21, 2026 09:43
7ca5878 to
8b3cbd3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #24476, where @isaacs pointed out that
flueRuntime.tsandmastraObservability.tsare near-identical and drifting. Both are now a few lines over a sharedcreateProvidedModulePlugin, so the next provider is a config object rather than a third copy.The probe moves from
createRequire().resolve()to the Rollup context'sthis.resolve(), which uses the same resolver and conditions as the injected import. That dropscreateRequire,node:pathand the error-code special case, and fixes a latent Mastra bug: its barecatch { return; }only works because@mastra/observabilitystill publishes arequirecondition, 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 tobuildStartandconfigResolvedstays 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:
transformis 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 storesundefinedif the bundler evaluates Sentry's module first, which is not Flue-specific, so there is one shape for both and nolazyoption.cloudflare-mastrais the real check here: on workerd the injected binding is the only pathloadMastraObservabilitycan take, so a broken injection means no agent spans and a failing suite.🤖 Generated with Claude Code