Skip to content

feat(ai): Attach granular cost data to spans#6167

Merged
Dav1dde merged 3 commits into
masterfrom
vg/granular-cost-attrs-and-otel-renames
Jul 16, 2026
Merged

feat(ai): Attach granular cost data to spans#6167
Dav1dde merged 3 commits into
masterfrom
vg/granular-cost-attrs-and-otel-renames

Conversation

@vgrozdanic

@vgrozdanic vgrozdanic commented Jul 2, 2026

Copy link
Copy Markdown
Member

Since we introduced cost calculation we were correctly calculating the cost by taking into account input, cached, output and reasoning tokens, but we have never attached that information to spans.

We already have this attributes in our conventions since forever, this PR just adds the better cost breakdown to spans

@vgrozdanic
vgrozdanic force-pushed the vg/granular-cost-attrs-and-otel-renames branch 2 times, most recently from 72bc739 to 6e66700 Compare July 15, 2026 13:29
… cost fields

Rename three SpanData usage fields to their new OTEL semantic convention
names, keeping the old names as legacy_alias for backward compatibility:
- gen_ai.usage.input_tokens.cached → gen_ai.usage.cache_read.input_tokens
- gen_ai.usage.input_tokens.cache_write → gen_ai.usage.cache_creation.input_tokens
- gen_ai.usage.output_tokens.reasoning → gen_ai.usage.reasoning.output_tokens

Add three new granular cost fields mirroring the usage token breakdown:
- gen_ai.cost.cache_read.input_tokens
- gen_ai.cost.cache_creation.input_tokens
- gen_ai.cost.reasoning.output_tokens

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vgrozdanic
vgrozdanic force-pushed the vg/granular-cost-attrs-and-otel-renames branch from 6e66700 to 64c8410 Compare July 15, 2026 13:38
@vgrozdanic
vgrozdanic force-pushed the vg/granular-cost-attrs-and-otel-renames branch from 64c8410 to 4bc177b Compare July 15, 2026 14:41
@vgrozdanic vgrozdanic changed the title feat(ai): Rename deprecated span attrs to OTEL names and add granular cost fields feat(ai): Attach granular cost data to spans Jul 15, 2026
@vgrozdanic
vgrozdanic marked this pull request as ready for review July 15, 2026 14:57
@vgrozdanic
vgrozdanic requested a review from a team as a code owner July 15, 2026 14:57
Comment thread relay-event-normalization/src/eap/ai.rs

@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.

Integration tests need fixing/changing

Cost calculation now always emits cache_read, cache_creation, and
reasoning cost fields. Update the AI span integration fixture so those
zero values are asserted.

Co-Authored-By: x-ai/grok-4.5 <noreply@opencode.ai>
@vgrozdanic
vgrozdanic added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 16, 2026
@Dav1dde
Dav1dde added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@Dav1dde
Dav1dde added this pull request to the merge queue Jul 16, 2026
Merged via the queue into master with commit 2f790c6 Jul 16, 2026
35 checks passed
@Dav1dde
Dav1dde deleted the vg/granular-cost-attrs-and-otel-renames branch July 16, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants