From 1d5a7e88f2bc591ad3018bb89d467b0749fe161a Mon Sep 17 00:00:00 2001 From: Scott Hollingsworth Date: Fri, 23 Dec 2022 01:17:53 -0800 Subject: [PATCH] fix(redisotel): prevent race condition by passing a copy of attrs rather than a reference --- extra/redisotel/metrics.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extra/redisotel/metrics.go b/extra/redisotel/metrics.go index 76f545b8eb..b41417b6f9 100644 --- a/extra/redisotel/metrics.go +++ b/extra/redisotel/metrics.go @@ -193,7 +193,11 @@ func (mh *metricsHook) DialHook(hook redis.DialHook) redis.DialHook { conn, err := hook(ctx, network, addr) - mh.createTime.Record(ctx, milliseconds(time.Since(start)), mh.attrs...) + attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+1) + attrs = append(attrs, mh.attrs...) + attrs = append(attrs, statusAttr(err)) + + mh.createTime.Record(ctx, milliseconds(time.Since(start)), attrs...) return conn, err } }