Skip to content

feat(ai): data & measurement normalization #4768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 30, 2025

Conversation

tobias-wilfert
Copy link
Member

@tobias-wilfert tobias-wilfert commented May 23, 2025

Maps old and depreciated measurements and data to new fields in line with our conventions.
Fixes: https://linear.app/getsentry/issue/RELAY-69/normalise-ai-related-span-data

Updates cost calcuation and metric extraction to use data rather than measurements.
Fixes: https://linear.app/getsentry/issue/RELAY-70/update-metrics-extraction-to-new-span-data-names

@tobias-wilfert tobias-wilfert self-assigned this May 23, 2025
@tobias-wilfert tobias-wilfert changed the title WIP feat(ai): normalization feat(ai): data & measurement normalization May 27, 2025
@tobias-wilfert tobias-wilfert marked this pull request as ready for review May 27, 2025 09:48
@tobias-wilfert tobias-wilfert requested a review from a team as a code owner May 27, 2025 09:48
Comment on lines -1237 to +1238
"measurements": {
"ai_total_tokens_used": {
"value": 20
},
"ai_total_cost": {
"value": 0.0002
}
},
"data": {
"gen_ai.usage.total_tokens": 20,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the total cost measurement removed? A corresponding field exists in data, right?

Side note: should we move this test input out of the file? It's literally over 1000 lines long.

Copy link
Member Author

@tobias-wilfert tobias-wilfert May 27, 2025

Choose a reason for hiding this comment

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

Talk with Anton and apparently that is never send by the SDKs in the first place, so I removed it to keep the test consistent with the real world.

Comment on lines +2274 to +2276
.and_then(|span| span.value())
.and_then(|span| span.data.value())
.and_then(|data| data.gen_ai_usage_total_cost.value()),
Copy link
Member

Choose a reason for hiding this comment

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

nice

@tobias-wilfert tobias-wilfert merged commit 4081fe2 into master May 30, 2025
28 checks passed
@tobias-wilfert tobias-wilfert deleted the tobias-wilfert/feat/normalize-ai branch May 30, 2025 11:06
ArthurKnaus added a commit to getsentry/sentry that referenced this pull request Jun 2, 2025
Access span properties via the new keys while also using the old ones as
fallback.

- part of [TET-498: Trace View - AI Span
details](https://linear.app/getsentry/issue/TET-498/trace-view-ai-span-details)
- relay started mapping to new keys in
getsentry/relay#4768
andrewshie-sentry pushed a commit to getsentry/sentry that referenced this pull request Jun 2, 2025
Access span properties via the new keys while also using the old ones as
fallback.

- part of [TET-498: Trace View - AI Span
details](https://linear.app/getsentry/issue/TET-498/trace-view-ai-span-details)
- relay started mapping to new keys in
getsentry/relay#4768
AbhiPrasad added a commit to getsentry/sentry-javascript that referenced this pull request Jun 4, 2025
resolves #16453

In getsentry/sentry-conventions#57 we deprecated
some of the `ai.X` attributes in favour of OTEL's `gen_ai.X` attributes.
This updates the Vercel AI integration to address these deprecations.

These changes are based on
https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data, and we
created `attributes.ts` to track these as constants.

See the relay change here to switch to new attributes for measuring
token usage: getsentry/relay#4768
antonpirker added a commit to getsentry/sentry-python that referenced this pull request Jul 10, 2025
Store AI token usage in `span.data` instead of deprecated
`measurements`.

In `relay` there is already code in place that copies the data from the
deprecated `span.measurements` to `span.data` and uses `span.data` for
calculating the cost of token usage. So this PR can be deployed in a
minor without risk.

See also `relay` PR: getsentry/relay#4768
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