Skip to content

Commit 0ec464e

Browse files
e2bclaude
authored andcommitted
fix: compute metric attribute set once in Stopwatch.end()
Reuse a single MeasurementOption across histogram/sum/count recordings instead of calling metric.WithAttributes three times independently. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a5d84c1 commit 0ec464e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/shared/pkg/telemetry/meters.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,10 @@ func (t Stopwatch) Failure(ctx context.Context, total int64, kv ...attribute.Key
422422
func (t Stopwatch) end(ctx context.Context, result string, total int64, kv ...attribute.KeyValue) {
423423
kv = append(kv, attribute.KeyValue{Key: resultAttr, Value: attribute.StringValue(result)})
424424
kv = append(t.kv, kv...)
425+
opt := metric.WithAttributeSet(attribute.NewSet(kv...))
425426

426427
amount := time.Since(t.start).Milliseconds()
427-
t.histogram.Record(ctx, amount, metric.WithAttributes(kv...))
428-
t.sum.Add(ctx, total, metric.WithAttributes(kv...))
429-
t.count.Add(ctx, 1, metric.WithAttributes(kv...))
428+
t.histogram.Record(ctx, amount, opt)
429+
t.sum.Add(ctx, total, opt)
430+
t.count.Add(ctx, 1, opt)
430431
}

0 commit comments

Comments
 (0)