Skip to content

Commit 98c4c64

Browse files
committed
modify appending token metrics for bedrock usage
1 parent c266461 commit 98c4c64

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ddtrace/llmobs/_integrations/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ def get_llmobs_metrics_tags(integration_name, span):
125125
if integration_name == "bedrock":
126126
input_tokens = int(span.get_tag("bedrock.usage.prompt_tokens") or 0)
127127
output_tokens = int(span.get_tag("bedrock.usage.completion_tokens") or 0)
128-
usage[INPUT_TOKENS_METRIC_KEY] = input_tokens
129-
usage[OUTPUT_TOKENS_METRIC_KEY] = output_tokens
130-
usage[TOTAL_TOKENS_METRIC_KEY] = input_tokens + output_tokens
128+
total_tokens = input_tokens + output_tokens
129+
if input_tokens:
130+
usage[INPUT_TOKENS_METRIC_KEY] = input_tokens
131+
if output_tokens:
132+
usage[OUTPUT_TOKENS_METRIC_KEY] = output_tokens
133+
if total_tokens:
134+
usage[TOTAL_TOKENS_METRIC_KEY] = total_tokens
131135
return usage
132136

133137
# check for both prompt / completion or input / output tokens

0 commit comments

Comments
 (0)