Skip to content

feat(server-utils): Add first-party Flue instrumentation - #24265

Draft
RulaKhaled wants to merge 2 commits into
developfrom
feat/flue-instrumentation-base
Draft

feat(server-utils): Add first-party Flue instrumentation#24265
RulaKhaled wants to merge 2 commits into
developfrom
feat/flue-instrumentation-base

Conversation

@RulaKhaled

@RulaKhaled RulaKhaled commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Instruments the Flue agent framework (@flue/runtime) through its own instrument() hook. Enabled by default on Node, no app code required. Verified against a scaffolded flue init app driven over HTTP against a real provider, on both injection paths:

http.server  POST
  └─ gen_ai.invoke_agent  invoke_agent Hello   (auto.ai.flue)
     ├─ gen_ai.chat  chat anthropic/claude-haiku-4.5  [988 in / 125 out / $0.001613]
     ├─ gen_ai.execute_tool  execute_tool get_weather
     └─ gen_ai.chat  chat anthropic/claude-haiku-4.5  [1035 in / 30 out / $0.001185]

Message content is gated on recordInputs/recordOutputs, falling back to dataCollection.genAI. Flue reaches providers through pi-ai, which bundles the openai/@anthropic-ai/sdk/@google/genai clients, so those are skipped while Flue is instrumented — otherwise every call gets a second gen_ai.chat.

Root cause: Flue publishes no diagnostics channels, only an { observe, interceptor } registration. The interceptor owns the agent span and the active context; observe owns the turn and tool spans, since turn_start/turn are the only signal one-to-one with a model call. Getting at the app's own instrument() 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 — so createFlueInstrumentation is exported from @sentry/cloudflare and skips providers itself.

Tests stacked in #24266.

Known gaps: Cloudflare untested end to end; Flue's own Sentry blueprint targets @sentry/node@^10.64.0 and our docs point at it, so on v11 both would register and double-report (needs a docs update, same shape as the @mastra/sentry migration).

Fixes #24017

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.91 kB +0.39% +110 B 🔺
@sentry/browser - with treeshaking flags 27.21 kB +0.37% +100 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 27.1 kB +0.35% +93 B 🔺
@sentry/browser (incl. Tracing) 50.27 kB +2.15% +1.05 kB 🔺
@sentry/browser (incl. Tracing + Span Streaming) 50.28 kB +2.15% +1.06 kB 🔺
@sentry/browser (incl. Tracing, Profiling) 53.26 kB +2.18% +1.13 kB 🔺
@sentry/browser (incl. Tracing, Replay) 89.76 kB +1.13% +998 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 78.86 kB +1.16% +901 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 94.45 kB +1.08% +1.01 kB 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 107.46 kB +1.02% +1.08 kB 🔺
@sentry/browser (incl. Feedback) 46.4 kB +0.23% +106 B 🔺
@sentry/browser (incl. sendFeedback) 33.96 kB +0.29% +96 B 🔺
@sentry/browser (incl. FeedbackAsync) 39.07 kB +0.24% +93 B 🔺
@sentry/browser (incl. Metrics) 29.93 kB +0.36% +105 B 🔺
@sentry/browser (incl. Logs) 30.19 kB +0.34% +101 B 🔺
@sentry/browser (incl. Metrics & Logs) 30.86 kB +0.37% +112 B 🔺
@sentry/react 30.66 kB +0.37% +113 B 🔺
@sentry/react (incl. Tracing) 52.59 kB +2.01% +1.03 kB 🔺
@sentry/vue 36.15 kB +0.28% +99 B 🔺
@sentry/vue (incl. Tracing) 52.53 kB +2.05% +1.05 kB 🔺
@sentry/svelte 28.93 kB +0.32% +91 B 🔺
CDN Bundle 30.64 kB +0.32% +95 B 🔺
CDN Bundle (incl. Tracing) 50.78 kB +2.1% +1.04 kB 🔺
CDN Bundle (incl. Logs, Metrics) 32.92 kB +0.32% +102 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 52.73 kB +2% +1.03 kB 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 73.61 kB +0.19% +135 B 🔺
CDN Bundle (incl. Tracing, Replay) 88.32 kB +1.19% +1.03 kB 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.29 kB +1.24% +1.1 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 94.36 kB +1.23% +1.15 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.38 kB +1.23% +1.17 kB 🔺
CDN Bundle - uncompressed 90.72 kB +0.29% +257 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 151.68 kB +2.37% +3.51 kB 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.3 kB +0.28% +266 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 157.64 kB +2.28% +3.51 kB 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.71 kB +0.19% +417 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 271.25 kB +1.31% +3.49 kB 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 277.2 kB +1.28% +3.49 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 284.95 kB +1.24% +3.49 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 290.89 kB +1.22% +3.49 kB 🔺
@sentry/nextjs (client) 54.91 kB +1.7% +913 B 🔺
@sentry/sveltekit (client) 50.69 kB +2.1% +1.04 kB 🔺
@sentry/core/server 37.1 kB +0.31% +114 B 🔺
@sentry/core/browser 13.66 kB +0.82% +110 B 🔺
@sentry/node 129.74 kB +1.53% +1.95 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.86 kB +0.3% +243 B 🔺
@sentry/node - without tracing 89.07 kB +0.41% +356 B 🔺
@sentry/node - without channel injection 108.85 kB +1.7% +1.82 kB 🔺
@sentry/aws-serverless 97.47 kB +0.39% +370 B 🔺
@sentry/cloudflare (withSentry) - minified 202.48 kB +0.25% +500 B 🔺
@sentry/cloudflare (withSentry) 504.19 kB +0.31% +1.51 kB 🔺

View base workflow run

RulaKhaled and others added 2 commits September 10, 2026 09:39
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>
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.

Add first-party Flue instrumentation

1 participant