From 89a51983054696e4c36b41b5c357a8dd31a627a2 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Wed, 4 Feb 2026 14:10:17 +0100 Subject: [PATCH 1/5] chore(ai): track reason for missing cost in ai cost calculation --- relay-event-normalization/src/eap/ai.rs | 20 +++++++++++++------ .../src/normalize/span/ai.rs | 2 +- relay-event-normalization/src/statsd.rs | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/relay-event-normalization/src/eap/ai.rs b/relay-event-normalization/src/eap/ai.rs index d5932befb6..b9ae812395 100644 --- a/relay-event-normalization/src/eap/ai.rs +++ b/relay-event-normalization/src/eap/ai.rs @@ -6,7 +6,7 @@ use relay_protocol::Annotated; use crate::ModelCosts; use crate::span::ai; -use crate::statsd::{map_origin_to_integration, platform_tag}; +use crate::statsd::{Counters, map_origin_to_integration, platform_tag}; /// Normalizes AI attributes. /// @@ -120,7 +120,18 @@ fn normalize_ai_costs(attributes: &mut Attributes, model_costs: Option<&ModelCos .and_then(|v| v.as_str()) .and_then(|model| model_costs?.cost_per_token(model)); - let Some(model_cost) = model_cost else { return }; + let integration = map_origin_to_integration(origin); + let platform_tag = platform_tag(platform); + + let Some(model_cost) = model_cost else { + relay_statsd::metric!( + counter(Counters::GenAiCostCalculationResult) += 1, + result = "calculation_no_model_cost_available", + integration = integration, + platform = platform_tag, + ); + return; + }; let get_tokens = |key| { attributes @@ -137,10 +148,7 @@ fn normalize_ai_costs(attributes: &mut Attributes, model_costs: Option<&ModelCos output_reasoning_tokens: get_tokens(GEN_AI_USAGE_OUTPUT_REASONING_TOKENS), }; - let integration = map_origin_to_integration(origin); - let platform = platform_tag(platform); - - let Some(costs) = ai::calculate_costs(model_cost, tokens, integration, platform) else { + let Some(costs) = ai::calculate_costs(model_cost, tokens, integration, platform_tag) else { return; }; diff --git a/relay-event-normalization/src/normalize/span/ai.rs b/relay-event-normalization/src/normalize/span/ai.rs index 36a3c9c578..81aed4a29a 100644 --- a/relay-event-normalization/src/normalize/span/ai.rs +++ b/relay-event-normalization/src/normalize/span/ai.rs @@ -94,7 +94,7 @@ pub fn calculate_costs( if !tokens.has_usage() { relay_statsd::metric!( counter(Counters::GenAiCostCalculationResult) += 1, - result = "calculation_none", + result = "calculation_no_tokens", integration = integration, platform = platform, ); diff --git a/relay-event-normalization/src/statsd.rs b/relay-event-normalization/src/statsd.rs index 088218f890..e49da1ce32 100644 --- a/relay-event-normalization/src/statsd.rs +++ b/relay-event-normalization/src/statsd.rs @@ -8,7 +8,8 @@ pub enum Counters { /// `calculation_negative`, /// `calculation_zero`, /// `calculation_positive`, - /// `calculation_none` + /// `calculation_no_tokens` + /// `calculation_no_model_cost_available` /// - `integration`: The integration used for the cost calculation. /// - `platform`: The platform used for the cost calculation. GenAiCostCalculationResult, From e9d2f701451e087c263d0710096329ac674b0fd6 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Thu, 5 Feb 2026 08:12:16 +0100 Subject: [PATCH 2/5] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91931fbb0f..e2bbff8539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - 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)) ## 26.1.0 From 9b5ea29e392eff051fa44434ed7834e7113d2c10 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Thu, 5 Feb 2026 08:37:43 +0100 Subject: [PATCH 3/5] add span pipeline --- .../src/normalize/span/ai.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/relay-event-normalization/src/normalize/span/ai.rs b/relay-event-normalization/src/normalize/span/ai.rs index 81aed4a29a..13dbca5ff3 100644 --- a/relay-event-normalization/src/normalize/span/ai.rs +++ b/relay-event-normalization/src/normalize/span/ai.rs @@ -189,11 +189,20 @@ fn extract_ai_model_cost_data( origin: Option<&str>, platform: Option<&str>, ) { - let Some(model_cost) = model_cost else { return }; - - let used_tokens = UsedTokens::from_span_data(&*data); let integration = map_origin_to_integration(origin); let platform = platform_tag(platform); + + let Some(model_cost) = model_cost else { + relay_statsd::metric!( + counter(Counters::GenAiCostCalculationResult) += 1, + result = "calculation_no_model_cost_available", + integration = integration, + platform = platform, + ); + return; + }; + + let used_tokens = UsedTokens::from_span_data(&*data); let Some(costs) = calculate_costs(model_cost, used_tokens, integration, platform) else { return; }; From a86743e96012cc0c7131d0356f4b47f6064da3d5 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Fri, 6 Feb 2026 09:00:40 +0100 Subject: [PATCH 4/5] add missing metric emission when model id is not present --- relay-event-normalization/src/normalize/span/ai.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/relay-event-normalization/src/normalize/span/ai.rs b/relay-event-normalization/src/normalize/span/ai.rs index 13dbca5ff3..e03391d26c 100644 --- a/relay-event-normalization/src/normalize/span/ai.rs +++ b/relay-event-normalization/src/normalize/span/ai.rs @@ -297,6 +297,13 @@ fn extract_ai_data( origin, platform, ) + } else { + relay_statsd::metric!( + counter(Counters::GenAiCostCalculationResult) += 1, + result = "calculation_no_model_cost_available", + integration = map_origin_to_integration(origin), + platform = platform_tag(platform), + ); } } From 9b2d09e4c561840e49d28be739ede1286ad09831 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Fri, 6 Feb 2026 09:01:24 +0100 Subject: [PATCH 5/5] add missing metric emission when model id is not present --- relay-event-normalization/src/normalize/span/ai.rs | 2 +- relay-event-normalization/src/statsd.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/relay-event-normalization/src/normalize/span/ai.rs b/relay-event-normalization/src/normalize/span/ai.rs index e03391d26c..d363486fe1 100644 --- a/relay-event-normalization/src/normalize/span/ai.rs +++ b/relay-event-normalization/src/normalize/span/ai.rs @@ -300,7 +300,7 @@ fn extract_ai_data( } else { relay_statsd::metric!( counter(Counters::GenAiCostCalculationResult) += 1, - result = "calculation_no_model_cost_available", + result = "calculation_no_model_id_available", integration = map_origin_to_integration(origin), platform = platform_tag(platform), ); diff --git a/relay-event-normalization/src/statsd.rs b/relay-event-normalization/src/statsd.rs index e49da1ce32..427f384b41 100644 --- a/relay-event-normalization/src/statsd.rs +++ b/relay-event-normalization/src/statsd.rs @@ -10,6 +10,7 @@ pub enum Counters { /// `calculation_positive`, /// `calculation_no_tokens` /// `calculation_no_model_cost_available` + /// `calculation_no_model_id_available` /// - `integration`: The integration used for the cost calculation. /// - `platform`: The platform used for the cost calculation. GenAiCostCalculationResult,