-
Notifications
You must be signed in to change notification settings - Fork 108
chore(ai): Track reason for missing cost in ai cost calculation #5611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
89a5198
e9d2f70
0e978b2
9b5ea29
a86743e
9b2d09e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| }; | ||
shellmayr marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EAP path missing distinct "no model ID" metricLow Severity The EAP path emits |
||
|
|
||
| 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; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| ); | ||
|
|
@@ -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); | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let Some(costs) = calculate_costs(model_cost, used_tokens, integration, platform) else { | ||
| return; | ||
| }; | ||
|
|
@@ -288,6 +297,13 @@ fn extract_ai_data( | |
| origin, | ||
| platform, | ||
| ) | ||
| } else { | ||
| relay_statsd::metric!( | ||
| counter(Counters::GenAiCostCalculationResult) += 1, | ||
| result = "calculation_no_model_id_available", | ||
| integration = map_origin_to_integration(origin), | ||
| platform = platform_tag(platform), | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing metric when model costs config is unavailableMedium Severity When |
||
| } | ||
| } | ||
|
|
||
|
|
||


There was a problem hiding this comment.
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