feat(server-utils): Add first-party Flue instrumentation - #24265
Draft
RulaKhaled wants to merge 2 commits into
Draft
feat(server-utils): Add first-party Flue instrumentation#24265RulaKhaled wants to merge 2 commits into
RulaKhaled wants to merge 2 commits into
Conversation
Contributor
size-limit report 📦
|
Instruments the Flue agent framework (`@flue/runtime`) through the runtime's own
`instrument()` hook, producing the `invoke_agent` -> `chat` / `execute_tool`
hierarchy with token usage and Flue-computed cost.
Flue exposes no diagnostics channels; it takes an `{ observe, interceptor }`
registration. The interceptor owns the agent span and the active context, so
spans opened underneath parent correctly. `observe` owns the turn and tool spans,
because `turn_start`/`turn` are the only signal one-to-one with a model call and
`turn` carries usage.
Reaching the app's own `instrument()` is the awkward part: it closes over a
module-scope registry, so registering into a second evaluated copy fails
silently, and `createRequire` — how `mastraIntegration` finds the app's copy —
cannot resolve an ESM-only package with no `require` export condition. Each
injection path therefore supplies it differently, and neither records what the
other uses: under a bundler plugin the injected snippet passes the binding out
(new optional `bindings` on the channel-integration definitions), and under the
runtime hook the module is imported by the resolved URL the hook records, which
ESM guarantees resolves to the same instance.
Also skips the raw provider integrations while Flue is instrumented: Flue calls
the providers through `@earendil-works/pi-ai`, which bundles the `openai`,
`@anthropic-ai/sdk` and `@google/genai` clients, so those would emit a second
`gen_ai.chat` beside ours.
Cloudflare needs manual registration — agents run in per-Durable-Object isolates
that an integration registered off `Sentry.init()` never sees — so
`createFlueInstrumentation` is exported from `@sentry/cloudflare` and performs
the provider skip itself.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Flue exposes the content on its event stream — `turn_request` carries the full `ModelRequest` (system prompt, messages, tool definitions), the settled `turn` carries `response.output`, and the tool events carry arguments and results — so there is no reason to omit it. Recorded as `gen_ai.input.messages`, `gen_ai.output.messages`, `gen_ai.system_instructions`, `gen_ai.tool.definitions`, `gen_ai.tool.call.arguments` and `gen_ai.tool.call.result`, gated on `recordInputs`/`recordOutputs` via `resolveAIRecordingOptions`, which falls back to the client's `dataCollection.genAI` settings. `FlueOptions` is threaded back through `flueIntegration` and now does something. Note the request content is only on `turn_request`; the settled `turn` reports request metadata alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
RulaKhaled
force-pushed
the
feat/flue-instrumentation-base
branch
from
September 10, 2026 07:41
9fb3fcd to
d62f4f2
Compare
isaacs
self-requested a review
September 10, 2026 14:47
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.
Instruments the Flue agent framework (
@flue/runtime) through its owninstrument()hook. Enabled by default on Node, no app code required. Verified against a scaffoldedflue initapp driven over HTTP against a real provider, on both injection paths:Message content is gated on
recordInputs/recordOutputs, falling back todataCollection.genAI. Flue reaches providers throughpi-ai, which bundles theopenai/@anthropic-ai/sdk/@google/genaiclients, so those are skipped while Flue is instrumented — otherwise every call gets a secondgen_ai.chat.Root cause: Flue publishes no diagnostics channels, only an
{ observe, interceptor }registration. The interceptor owns the agent span and the active context;observeowns the turn and tool spans, sinceturn_start/turnare the only signal one-to-one with a model call. Getting at the app's owninstrument()needs both injection paths, because neither records what the other uses: the bundler snippet passes the binding out, while the runtime hook imports the module by its recorded URL.Cloudflare needs manual registration — agents run in per-Durable-Object isolates an integration registered off
Sentry.init()never sees — socreateFlueInstrumentationis exported from@sentry/cloudflareand skips providers itself.Tests stacked in #24266.
Known gaps: Cloudflare untested end to end; Flue's own Sentry blueprint targets
@sentry/node@^10.64.0and our docs point at it, so on v11 both would register and double-report (needs a docs update, same shape as the@mastra/sentrymigration).Fixes #24017
🤖 Generated with Claude Code