Skip to content

feat(server-utils): Add pi-ai integration - #25937

Merged
mydea merged 2 commits into
ref/pi-ai-chat-span-helpersfrom
feat/pi-ai-integration-opt-in
Nov 12, 2026
Merged

mydea merged 2 commits into
ref/pi-ai-chat-span-helpersfrom
feat/pi-ai-integration-opt-in

Conversation

@mydea

@mydea mydea commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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 (@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

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: a62dd4f (PR test merge using develop at 27a41ad)

Against: 2b878f1 (develop) · base run #65743

⚠️ Baseline mismatch: 3 develop commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once develop's baseline build for 27a41ad finishes.

Path Size % Change Change
@sentry/browser 29.98 kB - -
@sentry/browser - with treeshaking flags 28.13 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.02 kB - -
@sentry/browser (incl. Tracing) 52.36 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.33 kB - -
@sentry/browser (incl. Tracing, Replay) 92.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.41 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.49 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.48 kB - -
@sentry/browser (incl. Feedback) 47.57 kB - -
@sentry/browser (incl. sendFeedback) 35.07 kB - -
@sentry/browser (incl. FeedbackAsync) 40.18 kB - -
@sentry/browser (incl. Metrics) 31.54 kB - -
@sentry/browser (incl. Logs) 31.83 kB - -
@sentry/browser (incl. Metrics & Logs) 32.52 kB - -
@sentry/react 31.84 kB - -
@sentry/react (incl. Tracing) 54.8 kB - -
@sentry/vue 38.39 kB - -
@sentry/vue (incl. Tracing) 55.38 kB - -
@sentry/svelte 30 kB - -
@sentry/remix (Remix 3 client bundle) 57.97 kB - -
CDN Bundle 31.77 kB - -
CDN Bundle (incl. Tracing) 52.94 kB - -
CDN Bundle (incl. Logs, Metrics) 34.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.45 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.05 kB - -
CDN Bundle (incl. Tracing, Replay) 91.22 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.93 kB - -
CDN Bundle - uncompressed 92.89 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.15 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.42 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.92 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.31 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 278.17 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 291.87 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 299.63 kB - -
@sentry/nextjs (client) 57.74 kB - -
@sentry/sveltekit (client) 52.92 kB - -
@sentry/core/server 44.51 kB - -
@sentry/core/browser 14.02 kB - -
@sentry/node 158.02 kB +0.15% +221 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.45 kB +0.18% +140 B 🔺
@sentry/node - without tracing 97.39 kB +0.17% +156 B 🔺
@sentry/node - without channel injection 138.33 kB +0.17% +230 B 🔺
@sentry/aws-serverless 106.23 kB +0.18% +185 B 🔺
@sentry/cloudflare (withSentry) - minified 204.45 kB - -
@sentry/cloudflare (withSentry) 508.11 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 229.47 kB - -

View base workflow run

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 5 not successful, 50 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-eve Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Failing after 3m Details
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Failing after 2m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 30s Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 25s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 49s Details

@mydea
mydea added this pull request to stack #25938 October 30, 2026 10:53
@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch from 76ee3f1 to 0f24663 Compare October 30, 2026 12:53
@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch from 0f24663 to 650c252 Compare October 30, 2026 12:54
@mydea
mydea marked this pull request as ready for review October 30, 2026 13:19
@mydea
mydea requested review from a team as code owners October 30, 2026 13:19
@mydea
mydea requested review from andreiborza, chargome, isaacs and nicohrubec and removed request for a team October 30, 2026 13:19

@chargome chargome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice!

@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch from 650c252 to f3eb138 Compare November 3, 2026 12:09
@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch from f3eb138 to 2a02e07 Compare November 4, 2026 10:03
@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch from 2a02e07 to f05f6d2 Compare November 10, 2026 08:08
@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch 2 times, most recently from 4191444 to 65b1613 Compare November 11, 2026 14:41
@mydea
mydea requested a review from a team November 11, 2026 14:41
mydea and others added 2 commits November 11, 2026 16:25
Traces requests sent with `@earendil-works/pi-ai` as `gen_ai.chat` spans,
from the `Models` methods and the standalone `compat` functions. Opt-in for
now: Flue and pi-durable still record their own chat spans for the same
requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mydea
mydea force-pushed the feat/pi-ai-integration-opt-in branch from 65b1613 to 94329d1 Compare November 11, 2026 15:25
@mydea
mydea merged commit 363bb22 into develop Nov 12, 2026
348 of 353 checks passed
@mydea
mydea deleted the feat/pi-ai-integration-opt-in branch November 12, 2026 10:26
mydea added a commit that referenced this pull request Nov 12, 2026
…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>
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.

2 participants