From b11f928dea1d044528d02fb5ac1de87011c49957 Mon Sep 17 00:00:00 2001 From: Warnar Boekkooi Date: Tue, 21 Oct 2025 13:56:06 +0200 Subject: [PATCH] chore(redisotel): use metric.WithAttributeSet to avoid copy (#3552) In order to improve performance replace `WithAttributes` with `WithAttributeSet`. This avoids the slice allocation and copy that is done in `WithAttributes`. For more information see https://github.com/open-telemetry/opentelemetry-go/blob/v1.38.0/metric/instrument.go#L357-L376 --- extra/redisotel/metrics.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/redisotel/metrics.go b/extra/redisotel/metrics.go index 3a3c96a3..7fe55452 100644 --- a/extra/redisotel/metrics.go +++ b/extra/redisotel/metrics.go @@ -275,7 +275,7 @@ func (mh *metricsHook) DialHook(hook redis.DialHook) redis.DialHook { attrs = append(attrs, mh.attrs...) attrs = append(attrs, statusAttr(err)) - mh.createTime.Record(ctx, milliseconds(dur), metric.WithAttributes(attrs...)) + mh.createTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...))) return conn, err } } @@ -293,7 +293,7 @@ func (mh *metricsHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook { attrs = append(attrs, attribute.String("type", "command")) attrs = append(attrs, statusAttr(err)) - mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributes(attrs...)) + mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...))) return err } @@ -314,7 +314,7 @@ func (mh *metricsHook) ProcessPipelineHook( attrs = append(attrs, attribute.String("type", "pipeline")) attrs = append(attrs, statusAttr(err)) - mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributes(attrs...)) + mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...))) return err }