Skip to content

feat(attributes): Add additional_context to gen_ai cost and usage attributes#397

Merged
matejminar merged 1 commit into
mainfrom
feat/gen-ai-additional-context
May 21, 2026
Merged

feat(attributes): Add additional_context to gen_ai cost and usage attributes#397
matejminar merged 1 commit into
mainfrom
feat/gen-ai-additional-context

Conversation

@matejminar
Copy link
Copy Markdown
Member

@matejminar matejminar commented May 21, 2026

Populates the additional_context field (introduced in #393) for all 11 gen_ai cost and usage attributes.

Context

Each attribute gets notes about:

  • Double-counting: all cost/usage attributes appear on both agent parent spans (aggregated totals) and LLM child spans (per-call values). Summing without filtering to gen_ai.operation.type:ai_client will over-report.
  • Naming confusion: cost attributes contain USD values despite having "tokens" in the name.
  • Subset relationships: cached input tokens are a subset of input tokens, reasoning tokens are a subset of output tokens, and total tokens is the sum of input + output. These should not be summed together.

Attributes updated

Attribute Notes
gen_ai.cost.total_tokens Double-counting + "USD not tokens"
gen_ai.cost.input_tokens Double-counting + "USD not tokens" + cached excluded
gen_ai.cost.output_tokens Double-counting + "USD not tokens" + reasoning excluded
gen_ai.usage.input_tokens Double-counting + cached is a subset
gen_ai.usage.input_tokens.cached Double-counting + subset of input_tokens
gen_ai.usage.input_tokens.cache_write Double-counting
gen_ai.usage.output_tokens Double-counting + reasoning is a subset
gen_ai.usage.output_tokens.reasoning Double-counting + subset of output_tokens
gen_ai.usage.total_tokens Double-counting + sum of input + output
gen_ai.usage.completion_tokens (deprecated) Double-counting
gen_ai.usage.prompt_tokens (deprecated) Double-counting

See proposal: https://www.notion.so/sentry/Proposal-Query-Guidance-for-Span-Attributes-3598b10e4b5d806d8c75e2a5b1caa42c

Closes TET-2316, TET-2317

@matejminar matejminar requested review from a team, Lms24, cleptric, mjq and nsdeschenes as code owners May 21, 2026 08:38
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (attributes) Add additional_context to gen_ai cost and usage attributes by matejminar in #397
  • (schema) Add additional_context field to attribute definitions by matejminar in #393

🤖 This preview updates automatically when you update the PR.

Copy link
Copy Markdown
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

One request:
Can we add a changelog entry to each attribute where we added the additional context fields?

Something along the lines of:

{
  "version": "next",
  "prs": [397],
  "description": "Add additional_context"
}

Otherwise LGTM!

…ributes

Populates the `additional_context` field (introduced in #393) for all 11 gen_ai
cost and usage attributes. Each attribute gets notes about:

- Double-counting: all cost/usage attributes appear on both agent parent spans
  (aggregated totals) and LLM child spans (per-call values). Summing without
  filtering to gen_ai.operation.type:ai_client will over-report.
- Naming confusion: cost attributes contain USD values despite having "tokens"
  in the name.
- Subset relationships: cached input tokens are a subset of input tokens,
  reasoning tokens are a subset of output tokens, and total tokens is the sum
  of input + output. These should not be summed together.

Attributes updated:
- gen_ai.cost.input_tokens, gen_ai.cost.output_tokens, gen_ai.cost.total_tokens
- gen_ai.usage.input_tokens, gen_ai.usage.input_tokens.cached,
  gen_ai.usage.input_tokens.cache_write
- gen_ai.usage.output_tokens, gen_ai.usage.output_tokens.reasoning
- gen_ai.usage.total_tokens
- gen_ai.usage.completion_tokens (deprecated), gen_ai.usage.prompt_tokens
  (deprecated)
@matejminar matejminar force-pushed the feat/gen-ai-additional-context branch from 9f16a4b to 09a03ed Compare May 21, 2026 10:13
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 21, 2026

TET-2316

TET-2317

@matejminar matejminar merged commit 7a0e289 into main May 21, 2026
16 checks passed
@matejminar matejminar deleted the feat/gen-ai-additional-context branch May 21, 2026 10:17
matejminar added a commit that referenced this pull request May 21, 2026
Surfaces the `additional_context` field (added in #393, populated in #397) in
the Astro docs site and the plain text LLM export.

Changes:

- content.config.ts: Added additional_context to the Zod schema
- AttributeCard.astro: Renders notes as a collapsible section (open by default)
  above the changelog, matching the existing disclosure pattern
- llms-full.txt.ts: Includes additional_context as nested list items in the
  plain text export for LLM consumption
matejminar added a commit that referenced this pull request May 21, 2026
Surfaces the `additional_context` field (added in #393, populated in #397) in
the Astro docs site and the plain text LLM export.

Changes:

- content.config.ts: Added additional_context to the Zod schema
- AttributeCard.astro: Renders notes as a collapsible section (open by default)
  above the changelog, matching the existing disclosure pattern
- llms-full.txt.ts: Includes additional_context as nested list items in the
  plain text export for LLM consumption
matejminar added a commit that referenced this pull request May 21, 2026
…rt (#399)

Surfaces the `additional_context` field (added in #393, populated in #397) in
the Astro docs site and the plain text LLM export.

Changes:

- content.config.ts: Added additional_context to the Zod schema
- AttributeCard.astro: Renders notes as a collapsible section (open by default)
  above the changelog, matching the existing disclosure pattern
- llms-full.txt.ts: Includes additional_context as nested list items in the
  plain text export for LLM consumption
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.

2 participants