Repository navigation
fix(cloudflare): Have @flue/runtime provide its own namespace - #25935
Conversation
size-limit report 📦Compared: 67860e2 (PR test merge using develop at 29f7386) Against: 29f7386 (develop) · base run #65616 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 6 not successful, 51 successful. See the run.
Successful checks
|
`@sentry/cloudflare/vite` spliced an `@flue/runtime` import into `@sentry/server-utils`'s Flue integration. Every orchestrion-instrumented module imports `@sentry/server-utils`, so that import closes a cycle through any instrumented package Flue loads at module scope. Once pi-ai is instrumented, a worker that reaches pi-ai first runs Flue's module-level `createModels()` before pi-ai's `ModelsImpl` exists and fails at startup. Flue's entry is already transformed, so it now publishes its own namespace through a self-import, which adds no edge to the module graph. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ig test The Cloudflare plugin test only echoed the option it passes. The transform tests and the cloudflare-flue-send-to-sentry e2e app cover the behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ab41938 to
322c19c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 322c19c. Configure here.
| const { moduleType, module } = state as { | ||
| moduleType?: string; | ||
| module?: { name?: string }; | ||
| module?: { name?: string; filePath?: string }; |
There was a problem hiding this comment.
I think this cast to string could lead to issues as filePath might also be a regex?
| module: moduleType === 'esm', | ||
| const esm = moduleType === 'esm'; | ||
| const selfProvided = | ||
| esm && module?.filePath && selfProvidedModules.includes(moduleName) |
There was a problem hiding this comment.
module.filePath can be a RegExp, which hits .split. the transformer swallows the TypeError and that file ends up uninstrumented. multi-file modules also publish each file under one key, last one wins. fine for flue today, but it's public PluginOptions (webpack ignores it), so maybe guard on typeof filePath === 'string' and note "single entry file" in the jsdoc?
…p `filePath` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s integration module Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
**Why:** pi-ai had no instrumentation of its own. Only Flue and pi-durable traced its requests, each with its own chat spans. This adds a `piAiIntegration` that traces every pi-ai request, so direct users are covered and both frameworks can later drop their chat-span code. The version range starts at 0.80 because Flue 2.0–2.2 depend on pi-ai 0.83–0.87. It's **opt-in** in this PR: Flue and pi-durable still record their own chat spans for the same requests, so enabling it next to them reports each call twice. The follow-up switches both frameworks over to it and enables it by default (it's on the coverage test's opt-in list until then). Split out of #25869, stacked on #25932, whose helpers it uses. **How to review:** Start with `integrations/pi-ai.ts` and `orchestrion/config/pi-ai.ts`. `complete*` awaits `stream*`, and `compat.stream` hands some models to a `Models` of its own, so a traced call can make another one synchronously. A depth counter gives only the outermost call a span. **Merge after #25935.** With pi-ai in the orchestrion config, the Cloudflare Flue worker crashes at startup (`Cannot access 'ModelsImpl' before initialization`) through the import cycle #25935 removes. **Release note:** > - **feat(server-utils): Add pi-ai integration** > > The new `piAiIntegration` traces requests sent with [pi-ai](https://github.com/earendil-works/pi) (`@earendil-works/pi-ai` >= 0.80) as `gen_ai.chat` spans, through `createModels()` or the standalone `stream`/`complete` functions. It is not enabled by default yet: add `Sentry.piAiIntegration()` to `integrations`. It needs the Sentry runtime hook or bundler plugin. > > Once pi-ai has sent a request, the `openai`, `@anthropic-ai/sdk`, `@google/genai` and Workers AI integrations stop recording requests for the rest of the process, because pi-ai sends its requests through those clients. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…rable (#25940) **Why:** Flue and pi-durable both send their model calls through pi-ai, and each had its own chat-span code (Flue's turn observations, pi-durable's `models` proxy). With `piAiIntegration` (#25937) enabled by default, pi-ai becomes the single source of `gen_ai.chat` spans, and ~1.1k lines of duplicated span code go away. Flue now hands its conversation id to the pi-ai span through the scope. Stack: #25932 → #25937 → this. #25935 must be merged before #25937 and this: without it, instrumenting pi-ai makes the Cloudflare Flue worker crash at startup. Supersedes #25869. **How to review:** The first commit is the switch. The second adds a one-time warning when Flue runs but pi-ai was not instrumented; it's separate so it can be dropped or split off. The next three scope the provider skip to pi-ai's own requests, make that warning runtime-specific, and keep the Flue and pi-durable recording options working on chat spans. The last two are cleanups: the active pi-ai span replaces the nesting counter, which also catches nested calls made after an `await`, and stale comments go. **Unsure about:** - Chat spans change origin from `auto.ai.flue` / `auto.ai.pi_durable` to `auto.ai.pi_ai`. - Flue's chat spans now need the runtime hook or bundler plugin; a manual-only `instrument(createFlueInstrumentation())` keeps agent and tool spans but loses chat spans, hence the warning. Setups following our docs are unaffected. - `flue.turn.purpose` (compaction vs. agent turn) is dropped, since pi-ai cannot see it. A possible follow-up is to record compaction the way getsentry/sentry-conventions#723 proposes, once it merges: Flue emits `compaction_start` (with a `manual`/`threshold`/`overflow` reason) and `compaction` observations, so it could open a `gen_ai.compact` span with the summarizing `gen_ai.chat` nested under it. - pi-durable records model calls only for a `models` object created with pi-ai's `createModels()`. **Release note:** > - **feat(server-utils): Add pi-ai integration** > > The new `piAiIntegration` traces requests sent with [pi-ai](https://github.com/earendil-works/pi) (`@earendil-works/pi-ai` >= 0.80) as `gen_ai.chat` spans, through `createModels()` or the standalone `stream`/`complete` functions. It is enabled by default and needs the Sentry runtime hook or bundler plugin. > > Requests pi-ai sends are reported once, as its `gen_ai.chat` span; direct calls to `openai`, `@anthropic-ai/sdk`, `@google/genai`, `@mistralai/mistralai` or Workers AI keep their own spans. > > Flue and pi-durable send their model calls through pi-ai, so their `gen_ai.chat` spans now come from this integration: > - Their origin changes from `auto.ai.flue` / `auto.ai.pi_durable` to `auto.ai.pi_ai`. Agent and tool spans keep their origin. > - Flue apps that only call `instrument(Sentry.createFlueInstrumentation())` need the runtime hook (`--import`) or bundler plugin for `gen_ai.chat` spans. Without it, the SDK logs a warning on the first model call. > - The `flue.turn.purpose` attribute is no longer set. > - `recordInputs` and `recordOutputs` on `createFlueInstrumentation()` and `piDurableIntegration()` keep applying to their `gen_ai.chat` spans. > - pi-durable records model calls only for a `models` object created with pi-ai's `createModels()`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>

Why:
flueIntegrationneeds Flue's owninstrument(), which a bundled worker can't resolve at runtime.@sentry/cloudflare/viteused to splice an@flue/runtimeimport into@sentry/server-utils's Flue integration for that. Every orchestrion-instrumented module imports@sentry/server-utils, so that import closes a cycle through any instrumented package Flue loads at module scope. With pi-ai instrumented (the upcoming pi-ai integration, split out of #25869), a worker that reaches pi-ai first runs Flue's module-levelcreateModels()before pi-ai'sModelsImplexists. I reproduced it locally withcloudflare-flue-send-to-sentry: the worker fails at startup withCannot access 'ModelsImpl' before initialization.Flue's entry is already transformed at build time, so it now publishes its own namespace through a self-import.
There are now two ways to hand a package to an integration in a bundled worker. Which one to use depends on whether the app already imports the package:
selfProvidedModules, new)@flue/runtime@mastra/observabilityimport * as ns from './index.mjs'import * as ns from '@mastra/observability'Mastra can't switch to the self-provided path: apps don't import
@mastra/observability(Mastra's observability is zero-config), so nothing would load it and it would never publish itself. Its splice has the same cycle shape (@mastra/observabilityimports@mastra/core, which is instrumented). That is harmless today because it only imports core subpaths that aren't transformed. If that changes, the splice can move into@sentry/cloudflare's own module, out of@sentry/server-utils.selfProvidedModulesis Cloudflare-only on purpose. On other bundlers,flueIntegrationwould then register Flue itself and clash with apps that callinstrument(Sentry.createFlueInstrumentation()), as our Node docs say. The webpack loader doesn't pass the option.How to review: Start with
selfProvidedSnippetinmoduleInjectedTransform.ts; its comment shows the generated output. The rest is wiring, removing Flue's provided-module plugin, and comments.Unsure about: Whether the Mastra splice should move out of
@sentry/server-utilsnow, before it can hit the same kind of cycle. I'd leave it until something actually triggers it.🤖 Generated with Claude Code