Skip to content

chore(ai): Track reason for missing cost in ai cost calculation#5611

Open
shellmayr wants to merge 6 commits intomasterfrom
shellmayr/chore/track-reason-for-no-cost-in-ai
Open

chore(ai): Track reason for missing cost in ai cost calculation#5611
shellmayr wants to merge 6 commits intomasterfrom
shellmayr/chore/track-reason-for-no-cost-in-ai

Conversation

@shellmayr
Copy link
Member

  • Just returning that the cost calculation had result none does not tell us what went wrong
  • Track whether the missing cost data comes from lack of token data on the span, or lack of model pricing information

Closes TET-1892

@linear
Copy link

linear bot commented Feb 4, 2026

@shellmayr shellmayr marked this pull request as ready for review February 5, 2026 07:12
@shellmayr shellmayr requested a review from a team as a code owner February 5, 2026 07:12
@shellmayr shellmayr changed the title chore(ai): track reason for missing cost in ai cost calculation chore(ai): Track reason for missing cost in ai cost calculation Feb 5, 2026
- Add `gen_ai.cost_calculation.result` metric to track AI cost calculation outcomes by integration and platform. ([#5560](https://github.com/getsentry/relay/pull/5560))
- Normalizes and validates trace metric names. ([#5589](https://github.com/getsentry/relay/pull/5589))
- Add manual category to cost calculation metric origin tag ([#5603](https://github.com/getsentry/relay/pull/5603))
- Differentiate between reasons for missing cost calculation([#5611](https://github.com/getsentry/relay/pull/5611))
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to skip the changelog for changes which aren't "outside" visible

Copy link
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

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

Can't tell if cursor is correct :shipit:

Copy link

@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 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

result = "calculation_no_model_id_available",
integration = map_origin_to_integration(origin),
platform = platform_tag(platform),
);
Copy link

Choose a reason for hiding this comment

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

Missing metric when model costs config is unavailable

Medium Severity

When model_costs is None in enrich_ai_span_data, no cost calculation metric is emitted. The code silently skips the extract_ai_data call, meaning no tracking occurs for this failure case. This is inconsistent with the EAP path in eap/ai.rs where the "calculation_no_model_cost_available" metric is correctly emitted when model_costs is None. This defeats the PR's purpose of differentiating between reasons for missing cost calculation.

Fix in Cursor Fix in Web

platform = platform_tag,
);
return;
};
Copy link

Choose a reason for hiding this comment

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

EAP path missing distinct "no model ID" metric

Low Severity

The EAP path emits "calculation_no_model_cost_available" when no model ID attribute exists (GEN_AI_REQUEST_MODEL/GEN_AI_RESPONSE_MODEL), but the span path emits "calculation_no_model_id_available" for the same scenario. The PR introduces "calculation_no_model_id_available" as a distinct metric (documented in statsd.rs and used in normalize/span/ai.rs), but the EAP path doesn't distinguish this case. This inconsistency makes telemetry data harder to interpret since the same condition produces different metric values.

Fix in Cursor Fix in Web

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