@@ -102,7 +102,9 @@ def __init__(
102
102
# "team",
103
103
# "team_alias",
104
104
# ],
105
- labelnames = self .get_labels_for_metric ("litellm_llm_api_time_to_first_token_metric" ),
105
+ labelnames = self .get_labels_for_metric (
106
+ "litellm_llm_api_time_to_first_token_metric"
107
+ ),
106
108
buckets = LATENCY_BUCKETS ,
107
109
)
108
110
@@ -240,14 +242,14 @@ def __init__(
240
242
self .litellm_deployment_state = self ._gauge_factory (
241
243
"litellm_deployment_state" ,
242
244
"LLM Deployment Analytics - The state of the deployment: 0 = healthy, 1 = partial outage, 2 = complete outage" ,
243
- labelnames = self .get_labels_for_metric ("litellm_deployment_state" )
245
+ labelnames = self .get_labels_for_metric ("litellm_deployment_state" ),
244
246
)
245
247
246
248
self .litellm_deployment_cooled_down = self ._counter_factory (
247
249
"litellm_deployment_cooled_down" ,
248
250
"LLM Deployment Analytics - Number of times a deployment has been cooled down by LiteLLM load balancing logic. exception_status is the status of the exception that caused the deployment to be cooled down" ,
249
251
# labelnames=_logged_llm_labels + [EXCEPTION_STATUS],
250
- labelnames = self .get_labels_for_metric ("litellm_deployment_cooled_down" )
252
+ labelnames = self .get_labels_for_metric ("litellm_deployment_cooled_down" ),
251
253
)
252
254
253
255
self .litellm_deployment_success_responses = self ._counter_factory (
@@ -1039,20 +1041,12 @@ def _increment_top_level_request_and_spend_metrics(
1039
1041
1040
1042
_labels = prometheus_label_factory (
1041
1043
supported_enum_labels = self .get_labels_for_metric (
1042
- metric_name = "litellm_proxy_total_requests_metric "
1044
+ metric_name = "litellm_spend_metric "
1043
1045
),
1044
1046
enum_values = enum_values ,
1045
1047
)
1046
1048
1047
- self .litellm_spend_metric .labels (
1048
- end_user_id ,
1049
- user_api_key ,
1050
- user_api_key_alias ,
1051
- model ,
1052
- user_api_team ,
1053
- user_api_team_alias ,
1054
- user_id ,
1055
- ).inc (response_cost )
1049
+ self .litellm_spend_metric .labels (** _labels ).inc (response_cost )
1056
1050
1057
1051
def _set_virtual_key_rate_limit_metrics (
1058
1052
self ,
@@ -2280,7 +2274,9 @@ def get_custom_labels_from_metadata(metadata: dict) -> Dict[str, str]:
2280
2274
return result
2281
2275
2282
2276
2283
- def _tag_matches_wildcard_configured_pattern (tags : List [str ], configured_tag : str ) -> bool :
2277
+ def _tag_matches_wildcard_configured_pattern (
2278
+ tags : List [str ], configured_tag : str
2279
+ ) -> bool :
2284
2280
"""
2285
2281
Check if any of the request tags matches a wildcard configured pattern
2286
2282
@@ -2305,6 +2301,7 @@ def _tag_matches_wildcard_configured_pattern(tags: List[str], configured_tag: st
2305
2301
import re
2306
2302
2307
2303
from litellm .router_utils .pattern_match_deployments import PatternMatchRouter
2304
+
2308
2305
pattern_router = PatternMatchRouter ()
2309
2306
regex_pattern = pattern_router ._pattern_to_regex (configured_tag )
2310
2307
return any (re .match (pattern = regex_pattern , string = tag ) for tag in tags )
@@ -2313,11 +2310,11 @@ def _tag_matches_wildcard_configured_pattern(tags: List[str], configured_tag: st
2313
2310
def get_custom_labels_from_tags (tags : List [str ]) -> Dict [str , str ]:
2314
2311
"""
2315
2312
Get custom labels from tags based on admin configuration.
2316
-
2313
+
2317
2314
Supports both exact matches and wildcard patterns:
2318
2315
- Exact match: "prod" matches "prod" exactly
2319
- - Wildcard pattern: "User-Agent: curl/*" matches "User-Agent: curl/7.68.0"
2320
-
2316
+ - Wildcard pattern: "User-Agent: curl/*" matches "User-Agent: curl/7.68.0"
2317
+
2321
2318
Reuses PatternMatchRouter for wildcard pattern matching.
2322
2319
2323
2320
Returns dict of label_name: "true" if the tag matches the configured tag, "false" otherwise
@@ -2345,17 +2342,19 @@ def get_custom_labels_from_tags(tags: List[str]) -> Dict[str, str]:
2345
2342
2346
2343
for configured_tag in configured_tags :
2347
2344
label_name = _sanitize_prometheus_label_name (f"tag_{ configured_tag } " )
2348
-
2345
+
2349
2346
# Check for exact match first (backwards compatibility)
2350
2347
if configured_tag in tags :
2351
2348
result [label_name ] = "true"
2352
2349
continue
2353
-
2350
+
2354
2351
# Use PatternMatchRouter for wildcard pattern matching
2355
- if "*" in configured_tag and _tag_matches_wildcard_configured_pattern (tags = tags , configured_tag = configured_tag ):
2352
+ if "*" in configured_tag and _tag_matches_wildcard_configured_pattern (
2353
+ tags = tags , configured_tag = configured_tag
2354
+ ):
2356
2355
result [label_name ] = "true"
2357
2356
continue
2358
-
2357
+
2359
2358
# No match found
2360
2359
result [label_name ] = "false"
2361
2360
0 commit comments