Repository navigation
ref(telemetry): Give each context compaction its own span - #2599
Merged
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
4 screenshot changes — 4 changed · 0 added · 0 removed Review screenshots in Frameshift
|
thomasjiangcy
approved these changes
Nov 3, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Telemetry baseline before the compaction redesign. Compaction behavior does not change.
agent.context_compactionspan. Before, its attributes landed on whatever span was active (agent.step.prepare,gen_ai.invoke_agent, orchat.reply).app.compaction.mode(blocking/active/handoff) is on the span and on its children, including the summarygen_ai.chatspan. That means you can group summary duration andgen_ai.usage.cache_read.input_tokensby mode.app.compaction.outcomeiscompactedorsummary_failed.app.turn.compaction_wait_msonchat.turnis 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, andapp.context_tokens_estimatedare always null.app.compaction.summary_charsarrives as a number (query it withtags[...,number]). So this PR renames the estimates toapp.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_estimatedandapp.context_input_limit_tokensare still set elsewhere (agent.step.prepare, turn preparation, the summary-failed logs), and thread compaction inconversation-memory.tsstill setsapp.compaction.trigger_tokens/target_tokens. Sentry scrubs all of these too. I left them alone to keep this PR scoped.junior.context_compactionsummary 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 newoutcomeattribute and the span'serror.typeshould show which.via @thomasjiangcy.
--
View Session [Sentry]