Skip to content

feat(ai): Compute context utilization on AI spans#5814

Merged
constantinius merged 11 commits intomasterfrom
constantinius/feat/event-normalization/model-context-usage
Apr 16, 2026
Merged

feat(ai): Compute context utilization on AI spans#5814
constantinius merged 11 commits intomasterfrom
constantinius/feat/event-normalization/model-context-usage

Conversation

@constantinius
Copy link
Copy Markdown
Contributor

@constantinius constantinius commented Apr 10, 2026

Closes https://linear.app/getsentry/issue/TET-2220/relay-implement-context-window-usage-per-span

Builds on #5831 which introduced the ModelMetadata global config with context window size.

For each AI span, if the model has a configured context size, set gen_ai.context.window_size and compute gen_ai.context.utilization as total_tokens / context_window_size. These fields were introduced with getsentry/sentry-conventions#315

Co-Authored-By: Claude noreply@anthropic.com

Introduce a new `llmModelMetadata` global config that extends the existing model cost data with context window size. The new `ModelMetadata` struct replaces `ModelCosts` throughout the normalization pipeline, with `ModelCosts` only retained for backwards-compatible deserialization on GlobalConfig.

When `ai_model_metadata` is present it is used entirely; otherwise `ai_model_costs` is converted to the new format as a fallback.

For each AI span, if the model has a configured context size, set `gen_ai.context.window_size` and compute `gen_ai.context.utilization` as `total_tokens / context_window_size`.

Co-Authored-By: Claude <noreply@anthropic.com>
@constantinius constantinius requested a review from a team as a code owner April 10, 2026 17:19
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 10, 2026

Comment thread relay-dynamic-config/src/global.rs
Comment thread relay-server/src/processing/spans/process.rs Outdated
Comment thread relay-event-normalization/src/eap/ai.rs
@constantinius constantinius requested a review from a team April 10, 2026 17:35
Comment thread relay-event-normalization/src/event.rs
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c5f4e71. Configure here.

Comment thread relay-server/src/services/processor/span.rs Outdated
@jjbayer
Copy link
Copy Markdown
Member

jjbayer commented Apr 13, 2026

See comment here getsentry/sentry#112656 (comment)

Comment thread relay-event-normalization/src/eap/ai.rs
Copy link
Copy Markdown
Member

@obostjancic obostjancic left a comment

Choose a reason for hiding this comment

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

lgtm, cc @vgrozdanic

Copy link
Copy Markdown
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

Please update the PR description, the rest LGTM!

Comment thread CHANGELOG.md Outdated
@constantinius constantinius changed the title feat(ai): Add ModelMetadata config with context size and utilization feat(ai): Compute context utilization on AI spans Apr 16, 2026
@constantinius constantinius added this pull request to the merge queue Apr 16, 2026
Merged via the queue into master with commit 3ad9ecf Apr 16, 2026
31 checks passed
@constantinius constantinius deleted the constantinius/feat/event-normalization/model-context-usage branch April 16, 2026 16:31
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.

3 participants