Skip to content

Commit 24a5e94

Browse files
metrics: refine image generation metrics and labels
Signed-off-by: Hrushikesh Patil <[email protected]>
1 parent c28ea9a commit 24a5e94

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/metrics/image_generation_metrics.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func (i *imageGeneration) StartRequest(headers map[string]string) {
5050
i.baseMetrics.StartRequest(headers)
5151
}
5252

53+
// SetModel sets the model for the request.
54+
func (i *imageGeneration) SetModel(model string) {
55+
i.baseMetrics.SetModel(model, model)
56+
}
57+
5358
// RecordTokenUsage implements [ImageGeneration.RecordTokenUsage].
5459
func (i *imageGeneration) RecordTokenUsage(ctx context.Context, inputTokens, outputTokens, totalTokens uint32, requestHeaders map[string]string) {
5560
attrs := i.buildBaseAttributes(requestHeaders)
@@ -63,10 +68,8 @@ func (i *imageGeneration) RecordTokenUsage(ctx context.Context, inputTokens, out
6368
metric.WithAttributeSet(attrs),
6469
metric.WithAttributes(attribute.Key(genaiAttributeTokenType).String(genaiTokenTypeOutput)),
6570
)
66-
i.metrics.tokenUsage.Record(ctx, float64(totalTokens),
67-
metric.WithAttributeSet(attrs),
68-
metric.WithAttributes(attribute.Key(genaiAttributeTokenType).String(genaiTokenTypeTotal)),
69-
)
71+
// Note: We don't record totalTokens separately as it causes double counting.
72+
// The OTEL spec only defines "input" and "output" token types.
7073
}
7174

7275
// RecordImageGeneration implements [ImageGeneration.RecordImageGeneration].

0 commit comments

Comments
 (0)