Skip to content

Commit d96a16a

Browse files
feat: add SetOriginalModel method to ImageGenerationMetrics interface
- Add SetOriginalModel method to ImageGenerationMetrics interface to track original model from request body - Implement SetOriginalModel in imageGeneration struct to delegate to baseMetrics - Update tests to use separate SetOriginalModel, SetRequestModel, SetResponseModel calls instead of SetModel Signed-off-by: Hrushikesh Patil <[email protected]>
1 parent 66cb1da commit d96a16a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

internal/metrics/image_generation_metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type imageGeneration struct {
2525
type ImageGenerationMetrics interface {
2626
// StartRequest initializes timing for a new request.
2727
StartRequest(headers map[string]string)
28+
// SetOriginalModel sets the original model from the incoming request body before any virtualization applies.
29+
// This is usually called after parsing the request body. Example: dall-e-3
30+
SetOriginalModel(originalModel internalapi.OriginalModel)
2831
// SetRequestModel sets the request model name.
2932
SetRequestModel(requestModel internalapi.RequestModel)
3033
// SetResponseModel sets the response model name.
@@ -53,6 +56,11 @@ func (i *imageGeneration) StartRequest(headers map[string]string) {
5356
i.baseMetrics.StartRequest(headers)
5457
}
5558

59+
// SetOriginalModel sets the original model from the incoming request body before any virtualization applies.
60+
func (i *imageGeneration) SetOriginalModel(originalModel internalapi.OriginalModel) {
61+
i.baseMetrics.SetOriginalModel(originalModel)
62+
}
63+
5664
// SetRequestModel sets the request model for the request.
5765
func (i *imageGeneration) SetRequestModel(requestModel internalapi.RequestModel) {
5866
i.baseMetrics.SetRequestModel(requestModel)

internal/metrics/image_generation_metrics_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestImageGeneration_RecordTokenUsage(t *testing.T) {
2828
attrsBase = []attribute.KeyValue{
2929
attribute.Key(genaiAttributeOperationName).String(genaiOperationImageGeneration),
3030
attribute.Key(genaiAttributeProviderName).String(genaiProviderOpenAI),
31+
attribute.Key(genaiAttributeOriginalModel).String("test-model"),
3132
attribute.Key(genaiAttributeRequestModel).String("test-model"),
3233
attribute.Key(genaiAttributeResponseModel).String("test-model"),
3334
}
@@ -36,7 +37,9 @@ func TestImageGeneration_RecordTokenUsage(t *testing.T) {
3637
)
3738

3839
// Set labels and record usage.
39-
im.SetModel("test-model", "test-model")
40+
im.SetOriginalModel("test-model")
41+
im.SetRequestModel("test-model")
42+
im.SetResponseModel("test-model")
4043
im.SetBackend(&filterapi.Backend{Schema: filterapi.VersionedAPISchema{Name: filterapi.APISchemaOpenAI}})
4144
im.RecordTokenUsage(t.Context(), 3, 7, nil)
4245

@@ -60,6 +63,7 @@ func TestImageGeneration_RecordImageGeneration(t *testing.T) {
6063
attrs := attribute.NewSet(
6164
attribute.Key(genaiAttributeOperationName).String(genaiOperationImageGeneration),
6265
attribute.Key(genaiAttributeProviderName).String(genaiProviderOpenAI),
66+
attribute.Key(genaiAttributeOriginalModel).String("img-model"),
6367
attribute.Key(genaiAttributeRequestModel).String("img-model"),
6468
attribute.Key(genaiAttributeResponseModel).String("img-model"),
6569
attribute.Key("gen_ai.image.count").Int(2),
@@ -68,7 +72,9 @@ func TestImageGeneration_RecordImageGeneration(t *testing.T) {
6872
)
6973

7074
im.StartRequest(nil)
71-
im.SetModel("img-model", "img-model")
75+
im.SetOriginalModel("img-model")
76+
im.SetRequestModel("img-model")
77+
im.SetResponseModel("img-model")
7278
im.SetBackend(&filterapi.Backend{Schema: filterapi.VersionedAPISchema{Name: filterapi.APISchemaOpenAI}})
7379

7480
time.Sleep(10 * time.Millisecond)
@@ -94,13 +100,16 @@ func TestImageGeneration_HeaderLabelMapping(t *testing.T) {
94100
"x-org-id": "org456",
95101
}
96102

97-
im.SetModel("test-model", "test-model")
103+
im.SetOriginalModel("test-model")
104+
im.SetRequestModel("test-model")
105+
im.SetResponseModel("test-model")
98106
im.SetBackend(&filterapi.Backend{Schema: filterapi.VersionedAPISchema{Name: filterapi.APISchemaOpenAI}})
99107
im.RecordTokenUsage(t.Context(), 5, 0, requestHeaders)
100108

101109
attrs := attribute.NewSet(
102110
attribute.Key(genaiAttributeOperationName).String(genaiOperationImageGeneration),
103111
attribute.Key(genaiAttributeProviderName).String(genaiProviderOpenAI),
112+
attribute.Key(genaiAttributeOriginalModel).String("test-model"),
104113
attribute.Key(genaiAttributeRequestModel).String("test-model"),
105114
attribute.Key(genaiAttributeResponseModel).String("test-model"),
106115
attribute.Key(genaiAttributeTokenType).String(genaiTokenTypeInput),

0 commit comments

Comments
 (0)