1
0
mirror of https://github.com/redis/go-redis.git synced 2025-10-24 19:32:57 +03:00

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
This commit is contained in:
Warnar Boekkooi
2025-10-21 13:56:06 +02:00
committed by Nedyalko Dyakov
parent 3211b13e4f
commit b11f928dea

View File

@@ -275,7 +275,7 @@ func (mh *metricsHook) DialHook(hook redis.DialHook) redis.DialHook {
attrs = append(attrs, mh.attrs...) attrs = append(attrs, mh.attrs...)
attrs = append(attrs, statusAttr(err)) 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 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, attribute.String("type", "command"))
attrs = append(attrs, statusAttr(err)) 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 return err
} }
@@ -314,7 +314,7 @@ func (mh *metricsHook) ProcessPipelineHook(
attrs = append(attrs, attribute.String("type", "pipeline")) attrs = append(attrs, attribute.String("type", "pipeline"))
attrs = append(attrs, statusAttr(err)) 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 return err
} }