Skip to content

ref(telemetry): Give each context compaction its own span - #2599

Merged
thomasjiangcy merged 1 commit into
mainfrom
ref/compaction-telemetry-baseline
Nov 3, 2026
Merged

thomasjiangcy merged 1 commit into
mainfrom
ref/compaction-telemetry-baseline

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Telemetry baseline before the compaction redesign. Compaction behavior does not change.

  • Each compaction now gets one agent.context_compaction span. Before, its attributes landed on whatever span was active (agent.step.prepare, gen_ai.invoke_agent, or chat.reply).
  • app.compaction.mode (blocking / active / handoff) is on the span and on its children, including the summary gen_ai.chat span. That means you can group summary duration and gen_ai.usage.cache_read.input_tokens by mode.
  • app.compaction.outcome is compacted or summary_failed.
  • app.turn.compaction_wait_ms on chat.turn is the time the Turn waited on compaction in that execution slice.

Why the token attributes were "strings": they were already numbers in code. The project's default Sentry data scrubbing removes the value of any attribute key that contains token. In Sentry, app.compaction.trigger_tokens, app.compaction.replacement_tokens, and app.context_tokens_estimated are always null. app.compaction.summary_chars arrives as a number (query it with tags[...,number]). So this PR renames the estimates to app.compaction.input.estimate, .replacement.estimate, .threshold, and .input_limit. The other option is adding these keys to the project's safe fields.

Open questions for review:

  • app.context_tokens_estimated and app.context_input_limit_tokens are still set elsewhere (agent.step.prepare, turn preparation, the summary-failed logs), and thread compaction in conversation-memory.ts still sets app.compaction.trigger_tokens / target_tokens. Sentry scrubs all of these too. I left them alone to keep this PR scoped.
  • In the last 7 days there were about 1.3k junior.context_compaction summary calls but only about 690 spans with compaction attributes. About half of the compactions may end without a replacement (summary failure or input above the limit). The new outcome attribute and the span's error.type should show which.

via @thomasjiangcy.

--

View Session [Sentry]

Put compaction attributes on one agent.context_compaction span per
compaction, label it and its summary call with app.compaction.mode, and
record the Turn wait on compaction as app.turn.compaction_wait_ms.

Rename the token estimate attributes. Sentry data scrubbing removed the
values of keys that contain "token", so they never reached Sentry.

Co-Authored-By: Thomas Jiang <20501235+thomasjiangcy@users.noreply.github.com>
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 3, 2026 11:11am UTC

Request Review

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

4 screenshot changes — 4 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@thomasjiangcy
thomasjiangcy merged commit d3a1f30 into main Nov 3, 2026
47 checks passed
@thomasjiangcy
thomasjiangcy deleted the ref/compaction-telemetry-baseline branch November 3, 2026 12:05

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 077467b6 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant