Skip to content

Commit 24befd7

Browse files
committed
Add tracing hooks for existing connections
Previously the redis/go-redis library would call newTracingHook with no connString as default tracing, but that was recently removed in 9.8.0 which has caused our clients to lose oteltracing if connections are created before tracing can be instrumented.
1 parent 9c1655e commit 24befd7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

extra/redisotel/tracing.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
instrumName = "github.com/redis/go-redis/extra/redisotel"
2222
)
2323

24-
func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error {
24+
func InstrumentTracing(ctx context.Context, rdb redis.UniversalClient, opts ...TracingOption) error {
2525
switch rdb := rdb.(type) {
2626
case *redis.Client:
2727
opt := rdb.Options()
@@ -36,6 +36,14 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error {
3636
connString := formatDBConnString(opt.Network, opt.Addr)
3737
rdb.AddHook(newTracingHook(connString, opts...))
3838
})
39+
40+
rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error {
41+
opt := rdb.Options()
42+
opts = addServerAttributes(opts, opt.Addr)
43+
connString := formatDBConnString(opt.Network, opt.Addr)
44+
rdb.AddHook(newTracingHook(connString, opts...))
45+
return nil
46+
})
3947
return nil
4048
case *redis.Ring:
4149
rdb.OnNewNode(func(rdb *redis.Client) {
@@ -44,6 +52,14 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error {
4452
connString := formatDBConnString(opt.Network, opt.Addr)
4553
rdb.AddHook(newTracingHook(connString, opts...))
4654
})
55+
56+
rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error {
57+
opt := rdb.Options()
58+
opts = addServerAttributes(opts, opt.Addr)
59+
connString := formatDBConnString(opt.Network, opt.Addr)
60+
rdb.AddHook(newTracingHook(connString, opts...))
61+
return nil
62+
})
4763
return nil
4864
default:
4965
return fmt.Errorf("redisotel: %T not supported", rdb)

0 commit comments

Comments
 (0)