GeezerVison is showing github.com — ref(server-utils): Extract pi-ai chat span helpers from pi-durable by mydea · Pull Request #25932 · getsentry/sentry-javascript
Conversation
mydea
commented
Oct 30, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
This PR only moves things around in preparation for follow up work. Functionally nothing should change and it should mostly be stamp-able.
Why: Split out of #25869. The upcoming pi-ai integration creates the same gen_ai.chat span as pi-durable's models proxy does today, so the span logic moves to ai/pi-ai/ first. That way it gets reviewed once, as a move, while pi-durable still uses it. No behavior change: the pi-durable unit tests pass unmodified (only a type import moved).
How to review: ai/pi-ai/chat.ts is the body of the old traceModelRequest/endChatSpan, with the origin as a parameter. getPiAiChatSpanOptions returns the span options instead of starting the span, because pi-durable keeps the span active while the request is sent (startSpanManual), whereas a channel-based integration starts it inactive.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
size-limit report 📦
Compared: 27a41ad (PR test merge using develop at 2b878f1)
Against: 2b878f1 (develop) · base run #65743
✅ Baseline matches: this diff contains only this PR's changes.
| 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 |
157.88 kB |
+0.06% |
+86 B 🔺 |
| @sentry/node/import (ESM hook with diagnostics-channel injection) |
82.31 kB |
- |
- |
| @sentry/node - without tracing |
97.25 kB |
+0.02% |
+19 B 🔺 |
| @sentry/node - without channel injection |
138.19 kB |
+0.07% |
+86 B 🔺 |
| @sentry/aws-serverless |
106.06 kB |
+0.02% |
+21 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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Optional E2E tests
Some optional checks were not successful. They do not block the merge. 4 not successful, 51 successful. See the run.
|
Check |
Status |
|
| ❌ |
CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) |
Failing after 52s |
Details |
| ❌ |
CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) |
Failing after 10m |
Details |
| ❌ |
CI: Optional E2E Tests / E2E node-eve Test (optional) |
Failing after 2m |
Details |
| ❌ |
CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) |
Failing after 2m |
Details |
Successful checks
|
Check |
Status |
|
| ✅ |
CI: Optional E2E Tests / E2E astro-7 Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E solidstart-2 Test (optional) |
Successful in 56s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) |
Successful in 31s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) |
Successful in 40s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-think Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) |
Successful in 36s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E astro-7-static Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) |
Successful in 53s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) |
Successful in 47s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) |
Successful in 53s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) |
Successful in 40s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) |
Successful in 32s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) |
Successful in 57s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) |
Successful in 46s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E deno (latest) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) |
Successful in 39s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) |
Successful in 51s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) |
Successful in 36s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) |
Successful in 37s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) |
Successful in 36s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) |
Successful in 29s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) |
Successful in 41s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-mastra Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) |
Successful in 40s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) |
Successful in 31s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-flue Test (optional) |
Successful in 1m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-pi-durable Test (optional) |
Successful in 35s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) |
Successful in 53s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) |
Successful in 4m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) |
Successful in 35s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) |
Successful in 58s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nuxt-5 Test (optional) |
Successful in 2m |
Details |
| ✅ |
CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) |
Successful in 40s |
Details |
| ✅ |
CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) |
Successful in 41s |
Details |
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The span options and response attributes of a pi-ai request move to
`ai/pi-ai/chat.ts`, and the pi-ai structural types to `ai/pi-ai/types.ts`, so
a pi-ai integration can reuse them. pi-durable's `models` proxy uses them with
no change in behavior.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Span attributes drop `undefined` values, so the conditional spreads are not
needed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
mydea
added a commit
that referenced
this pull request
Nov 12, 2026
**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 <[email protected]>
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 <[email protected]>
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|