Skip to content

test(server-utils): Cover the Flue instrumentation - #24266

Open
RulaKhaled wants to merge 9 commits into
feat/flue-instrumentation-basefrom
feat/flue-instrumentation-tests
Open

test(server-utils): Cover the Flue instrumentation#24266
RulaKhaled wants to merge 9 commits into
feat/flue-instrumentation-basefrom
feat/flue-instrumentation-tests

Conversation

@RulaKhaled

@RulaKhaled RulaKhaled commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #24265 — review that first; this diff is tests only.

Unit (28 cases): span shapes and ops, the conversation id lifted off the re-entered agent operation, the usage/cost mapping, the all-zero-usage guard on failed turns, tool spans and their error status, content recording with its recordInputs/recordOutputs gating, trace continuation from a replayed traceparent, concurrent and delegated (subagent) runs, the provider-skip lifecycle, and dispose.

Integration: drives an agent through a tool call and asserts the full invoke_agentchat / execute_tool hierarchy, including that tool spans are siblings of chat under the agent invocation rather than children — matching how Flue's own OpenTelemetry adapter projects them.

The scenario uses pi-ai's built-in faux provider rather than a mock HTTP server, so responses are scripted in-process and no provider key is needed. It is ESM only — @flue/runtime has no require export condition, so the cjs mode returns early — and @flue/runtime is installed per-suite because its engines.node >= 22.19 would break yarn install on the Node 20 lane. Guarded by conditionalTest({ min: 22 }), so it skips on the repo's default Node 20; verified on Node 24.

Both suites were mutation-tested rather than just run green: reverting the zero-usage guard, the conversation-id lift, the tool-span handling, the turn-tracker cap and the provider-skip guard each produced a failure. One test passed vacuously on the first attempt and was fixed; another was written against a branch that turned out to be unreachable, which surfaced dead code in trackSpan that has since been removed.

🤖 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.96 kB - -
@sentry/browser - with treeshaking flags 27.26 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.15 kB - -
@sentry/browser (incl. Tracing) 50.51 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.52 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.5 kB - -
@sentry/browser (incl. Tracing, Replay) 90.07 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.16 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.77 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.73 kB - -
@sentry/browser (incl. Feedback) 46.46 kB - -
@sentry/browser (incl. sendFeedback) 34.01 kB - -
@sentry/browser (incl. FeedbackAsync) 39.12 kB - -
@sentry/browser (incl. Metrics) 29.98 kB - -
@sentry/browser (incl. Logs) 30.24 kB - -
@sentry/browser (incl. Metrics & Logs) 30.91 kB - -
@sentry/react 30.72 kB - -
@sentry/react (incl. Tracing) 52.81 kB - -
@sentry/vue 36.2 kB - -
@sentry/vue (incl. Tracing) 52.76 kB - -
@sentry/svelte 28.98 kB - -
CDN Bundle 30.7 kB - -
CDN Bundle (incl. Tracing) 51.01 kB - -
CDN Bundle (incl. Logs, Metrics) 32.98 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 52.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.67 kB - -
CDN Bundle (incl. Tracing, Replay) 88.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.53 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.63 kB - -
CDN Bundle - uncompressed 90.83 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.33 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.41 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.29 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.82 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 271.9 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 277.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.6 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.54 kB - -
@sentry/nextjs (client) 55.13 kB - -
@sentry/sveltekit (client) 50.93 kB - -
@sentry/core/server 37.13 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 130.44 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.83 kB - -
@sentry/node - without tracing 89.64 kB +0.04% +28 B 🔺
@sentry/node - without channel injection 109.37 kB +0.02% +21 B 🔺
@sentry/aws-serverless 97.86 kB +0.03% +20 B 🔺
@sentry/cloudflare (withSentry) - minified 203.36 kB - -
@sentry/cloudflare (withSentry) 506.44 kB - -

View base workflow run

@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch from 89239da to deb3330 Compare September 9, 2026 19:00
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch from deb3330 to bdda8e5 Compare September 9, 2026 19:08
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch from bdda8e5 to 612798a Compare September 10, 2026 07:41
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch 4 times, most recently from 74f4654 to cd565ee Compare September 11, 2026 12:53
@RulaKhaled
RulaKhaled marked this pull request as ready for review September 14, 2026 07:46
@RulaKhaled
RulaKhaled requested review from a team as code owners September 14, 2026 07:46
@RulaKhaled
RulaKhaled requested review from JPeer264 and mydea and removed request for a team September 14, 2026 07:46
Comment thread dev-packages/node-integration-tests/suites/tracing/flue/test.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d69cb28. Configure here.

Comment thread packages/server-utils/test/ai/lib/tracing/flue.test.ts
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch from d69cb28 to a7e44b7 Compare September 14, 2026 07:50
@RulaKhaled
RulaKhaled added this pull request to stack #24376 September 14, 2026 13:33
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch 2 times, most recently from 965a470 to ace67d3 Compare September 14, 2026 13:53
Comment thread dev-packages/node-integration-tests/suites/tracing/flue/test.ts
@RulaKhaled
RulaKhaled requested a review from a team as a code owner September 14, 2026 14:27
@RulaKhaled
RulaKhaled requested review from s1gr1d and removed request for a team September 14, 2026 14:27
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch from ace67d3 to da37aa7 Compare September 14, 2026 14:27
RulaKhaled and others added 9 commits September 14, 2026 23:03
Unit tests over `createFlueInstrumentation` for the span shapes, the conversation
id lifted off the re-entered agent operation, the usage/cost mapping, the
all-zero-usage guard on failed turns, tool spans, content recording and its
`recordInputs`/`recordOutputs` gating, and dispose.

The integration test drives a real agent through a tool call using `pi-ai`'s
`faux` provider, so the run is deterministic and needs no provider key or mock
server. ESM only: `@flue/runtime` has no `require` export condition, and it is
installed per-suite because its `engines.node >= 22.19` would break `yarn
install` on the Node 20 CI matrix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Concurrent agent runs, subagent delegation (adopted from Isaac's repro, moved
into the suite and asserted through a helper so a span-order assumption cannot
creep back), the agent name arriving via the observations, trace continuation
from the replayed traceparent, the provider skip applying on first use and
re-applying after a registry reset, the recording options following the current
client, and the conventional request attributes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Both tests fail against the previous implementation: the first leaves `openai`
registered before the run so the old first-entry-only guard short-circuits, and
the second overflows the turn tracker to prove the evicted span is ended rather
than dropped unsent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The `model` and `tool` interceptor branches open no span; they make the span
`observe` already opened active so the provider's HTTP call and the tool's own
work nest inside it. Deleting both branches left all 28 tests green, and the
e2e does not reach it either: its parent assertions come from the observation
stream firing inside the agent operation, and nothing in that scenario opens a
span inside a tool or model operation.

Each case fails when its own branch is removed, and neither fails for the
other's.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Both cases passed vacuously. `not.toBe(TRACE_ID)` on the malformed carrier also
held when no agent span was opened at all, since `undefined` is not the carrier's
id either; suppressing span creation entirely failed nine other tests and left
that one green. And the active-trace case never checked the span landed on the
surrounding request's trace, so continuing an unrelated new trace passed too.

Now the first asserts a well-formed trace id, and the second asserts the agent
span carries the `incoming request` span's own trace id. Dropping the
`!getActiveSpan()` guard fails the second.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Fails without the capture: the span is still errored, so only the error event
distinguishes the two.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Guards the concern raised on the Mastra error-capture PR: if a second capture
path is added, or the error starts reaching the global handlers, this fails.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@RulaKhaled
RulaKhaled force-pushed the feat/flue-instrumentation-tests branch from da37aa7 to 354d0e9 Compare September 14, 2026 20:04
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