Skip to content

feat(attributes): Add gen_ai conversation compaction conventions - #723

Closed
cleptric wants to merge 3 commits into
mainfrom
feat/gen-ai-conversation-compacted
Closed

cleptric wants to merge 3 commits into
mainfrom
feat/gen-ai-conversation-compacted

Conversation

@cleptric

@cleptric cleptric commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Adds conventions for tracing GenAI conversation context compaction:

  • gen_ai.compact span op and a new well-known gen_ai.operation.name value compact, for the operation that compacts a conversation's context (for example, summarizing earlier messages to fit the context window). Neither is in OpenTelemetry. The op also gets "Compaction" span name and description groups, and gen_ai.operation.type documents that compact spans map to other.
  • gen_ai.conversation.compaction.reason (string, Sentry-specific) is set on the gen_ai.compact span and records what triggered it, for example manual, threshold or overflow.
  • gen_ai.conversation.compacted (boolean, from the OpenTelemetry definition) is set on later requests that run on the compacted context. Instrumentations set it to true only when compaction was reliably applied and leave it unset otherwise, never false.

The resulting trace shape is a gen_ai.compact span with gen_ai.conversation.compaction.reason, its child gen_ai.chat span(s) for the model request that writes the summary, and later gen_ai.chat spans with gen_ai.conversation.compacted. Sentry's coding-agent tracing emits this shape.

Relay currently infers gen_ai.operation.type ai_client for unknown operation names, so it needs a follow-up to map compact to other.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-conventions Ready Ready Preview Oct 15, 2026 11:45am UTC

Request Review

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Attributes

  • Add gen_ai conversation compaction conventions by cleptric in #723
  • Add http.request.duration by loewenheim in #697

Other

  • (names) Add queue.publish/create/receive/process/settle to messaging span names by pabloDeputter in #705

Bug Fixes 🐛

  • (attributes) Apply consistent scrubbing across deprecations by mjq in #692

Internal Changes 🔧

  • (repo) Update CODEOWNERS to include @giortzisg by Lms24 in #708

🤖 This preview updates automatically when you update the PR.

@cleptric cleptric changed the title feat(attributes): Add gen_ai.conversation.compacted attribute feat(attributes): Add gen_ai conversation compaction attributes Oct 15, 2026
@cleptric cleptric changed the title feat(attributes): Add gen_ai conversation compaction attributes feat(attributes): Add gen_ai conversation compaction conventions Oct 15, 2026
@cleptric cleptric closed this Nov 9, 2026
mydea added a commit to getsentry/sentry-javascript 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>

This branch was successfully deployed

1 active deployment
Preview — 10b1d657 Deployed Oct 15, 2026 by vercel[bot]
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