Skip to content

Commit 518f5ce

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 518f5ce

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

extra/redisotel/tracing.go

Lines changed: 15 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,13 @@ 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+
})
3946
return nil
4047
case *redis.Ring:
4148
rdb.OnNewNode(func(rdb *redis.Client) {
@@ -44,6 +51,13 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error {
4451
connString := formatDBConnString(opt.Network, opt.Addr)
4552
rdb.AddHook(newTracingHook(connString, opts...))
4653
})
54+
55+
rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error {
56+
opt := rdb.Options()
57+
opts = addServerAttributes(opts, opt.Addr)
58+
connString := formatDBConnString(opt.Network, opt.Addr)
59+
rdb.AddHook(newTracingHook(connString, opts...))
60+
})
4761
return nil
4862
default:
4963
return fmt.Errorf("redisotel: %T not supported", rdb)

0 commit comments

Comments
 (0)