Skip to content

Commit 8ca21d2

Browse files
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
1 parent 7aa4a60 commit 8ca21d2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

extra/redisotel/metrics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func (mh *metricsHook) DialHook(hook redis.DialHook) redis.DialHook {
275275
attrs = append(attrs, mh.attrs...)
276276
attrs = append(attrs, statusAttr(err))
277277

278-
mh.createTime.Record(ctx, milliseconds(dur), metric.WithAttributes(attrs...))
278+
mh.createTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))
279279
return conn, err
280280
}
281281
}
@@ -293,7 +293,7 @@ func (mh *metricsHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {
293293
attrs = append(attrs, attribute.String("type", "command"))
294294
attrs = append(attrs, statusAttr(err))
295295

296-
mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributes(attrs...))
296+
mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))
297297

298298
return err
299299
}
@@ -314,7 +314,7 @@ func (mh *metricsHook) ProcessPipelineHook(
314314
attrs = append(attrs, attribute.String("type", "pipeline"))
315315
attrs = append(attrs, statusAttr(err))
316316

317-
mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributes(attrs...))
317+
mh.useTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))
318318

319319
return err
320320
}

0 commit comments

Comments
 (0)