Skip to content

Commit b9ccec2

Browse files
committed
feat: Enable Redis OTEL
Signed-off-by: Johan Sim <[email protected]>
1 parent 1d759c9 commit b9ccec2

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

common/component/redis/v9client.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ package redis
1616
import (
1717
"context"
1818
"crypto/tls"
19+
"fmt"
1920
"strings"
2021
"time"
2122

23+
redisotel "github.com/redis/go-redis/extra/redisotel/v9"
2224
v9 "github.com/redis/go-redis/v9"
2325
)
2426

@@ -460,8 +462,17 @@ func newV9Client(s *Settings) (RedisClient, error) {
460462
}
461463
}
462464

465+
client := v9.NewClient(options)
466+
467+
if err := redisotel.InstrumentTracing(client); err != nil {
468+
return nil, fmt.Errorf("failed to instrument Redis tracing: %w", err)
469+
}
470+
if err := redisotel.InstrumentMetrics(client); err != nil {
471+
return nil, fmt.Errorf("failed to instrument Redis metrics: %w", err)
472+
}
473+
463474
return v9Client{
464-
client: v9.NewClient(options),
475+
client: client,
465476
readTimeout: s.ReadTimeout,
466477
writeTimeout: s.WriteTimeout,
467478
dialTimeout: s.DialTimeout,

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ require (
110110
github.com/pkg/sftp v1.13.7
111111
github.com/puzpuzpuz/xsync/v3 v3.0.0
112112
github.com/rabbitmq/amqp091-go v1.9.0
113-
github.com/redis/go-redis/v9 v9.6.3
113+
github.com/redis/go-redis/extra/redisotel/v9 v9.16.0
114+
github.com/redis/go-redis/v9 v9.16.0
114115
github.com/riferrei/srclient v0.7.2
115116
github.com/sendgrid/sendgrid-go v3.13.0+incompatible
116117
github.com/sijms/go-ora/v2 v2.8.22
@@ -368,6 +369,7 @@ require (
368369
github.com/prometheus/procfs v0.16.1 // indirect
369370
github.com/prometheus/statsd_exporter v0.22.7 // indirect
370371
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 // indirect
372+
github.com/redis/go-redis/extra/rediscmd/v9 v9.16.0 // indirect
371373
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
372374
github.com/rs/zerolog v1.31.0 // indirect
373375
github.com/russross/blackfriday v1.6.0 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,12 @@ github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv
15121512
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
15131513
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 h1:bsUq1dX0N8AOIL7EB/X911+m4EHsnWEHeJ0c+3TTBrg=
15141514
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
1515-
github.com/redis/go-redis/v9 v9.6.3 h1:8Dr5ygF1QFXRxIH/m3Xg9MMG1rS8YCtAgosrsewT6i0=
1516-
github.com/redis/go-redis/v9 v9.6.3/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
1515+
github.com/redis/go-redis/extra/rediscmd/v9 v9.16.0 h1:zAFQyFxJ3QDwpPUY/CKn22LI5+B8m/lUyffzq2+8ENs=
1516+
github.com/redis/go-redis/extra/rediscmd/v9 v9.16.0/go.mod h1:ouOc8ujB2wdUG6o0RrqaPl2tI6cenExC0KkJQ+PHXmw=
1517+
github.com/redis/go-redis/extra/redisotel/v9 v9.16.0 h1:+a9h9qxFXdf3gX0FXnDcz7X44ZBFUPq58Gblq7aMU4s=
1518+
github.com/redis/go-redis/extra/redisotel/v9 v9.16.0/go.mod h1:EtTTC7vnKWgznfG6kBgl9ySLqd7NckRCFUBzVXdeHeI=
1519+
github.com/redis/go-redis/v9 v9.16.0 h1:OotgqgLSRCmzfqChbQyG1PHC3tLNR89DG4jdOERSEP4=
1520+
github.com/redis/go-redis/v9 v9.16.0/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
15171521
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
15181522
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
15191523
github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=

0 commit comments

Comments
 (0)