Skip to content

feat(ai): Add gen_ai.response.tokens_per_second span attribute on AI spans - #4883

Merged
vgrozdanic merged 2 commits into
masterfrom
vg/tokens-per-second-calculation
Jul 2, 2025
Merged

vgrozdanic merged 2 commits into
masterfrom
vg/tokens-per-second-calculation

Conversation

@vgrozdanic

@vgrozdanic vgrozdanic commented Jul 1, 2025 •

Copy link
Copy Markdown
Member

Adds new span attribute gen_ai.response.tokens_per_second defined by Nvidia.

This is calculated as: output_tokens / span.duration

Closes TET-618: tokens per second

@vgrozdanic
vgrozdanic force-pushed the vg/tokens-per-second-calculation branch from f18e68b to 8341652 Compare July 1, 2025 12:04
@vgrozdanic
vgrozdanic marked this pull request as ready for review July 1, 2025 12:30
@vgrozdanic
vgrozdanic requested a review from a team as a code owner July 1, 2025 12:30
"spans": [
{
"timestamp": 1702474613.0495,
"timestamp": 1702474614.0175,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume this is so the span lasts for exactly 1s?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, to avoid floating point errors in tests, and make it easier to write tests :)

@Dav1dde Dav1dde left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume you're also updating the sentry conventions repo?

Comment thread relay-event-normalization/src/event.rs Outdated
Comment on lines +2667 to +2673
let span_data = event
.value()
.and_then(|event| event.spans.value())
.and_then(|spans| spans.first())
.and_then(|span| span.value())
.and_then(|span| span.data.value())
.unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The get_value! macro should work here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TIL, this is really cool macro, thanks!

@vgrozdanic
vgrozdanic added this pull request to the merge queue Jul 2, 2025
Merged via the queue into master with commit c956506 Jul 2, 2025
@vgrozdanic
vgrozdanic deleted the vg/tokens-per-second-calculation branch July 2, 2025 08:27
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