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:
committed by
Nedyalko Dyakov
parent
3211b13e4f
commit
b11f928dea
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user