From 518f5ce6b4f6b95eaf3c480b1fc6c8067b1ab672 Mon Sep 17 00:00:00 2001 From: Allan Guigou <34221163+AllanGuigou@users.noreply.github.com> Date: Tue, 15 Jul 2025 14:57:24 +0000 Subject: [PATCH 1/3] 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. --- extra/redisotel/tracing.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/extra/redisotel/tracing.go b/extra/redisotel/tracing.go index 40df5a202..f0ca28da6 100644 --- a/extra/redisotel/tracing.go +++ b/extra/redisotel/tracing.go @@ -21,7 +21,7 @@ const ( instrumName = "github.com/redis/go-redis/extra/redisotel" ) -func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error { +func InstrumentTracing(ctx context.Context, rdb redis.UniversalClient, opts ...TracingOption) error { switch rdb := rdb.(type) { case *redis.Client: opt := rdb.Options() @@ -36,6 +36,13 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error { connString := formatDBConnString(opt.Network, opt.Addr) rdb.AddHook(newTracingHook(connString, opts...)) }) + + rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error { + opt := rdb.Options() + opts = addServerAttributes(opts, opt.Addr) + connString := formatDBConnString(opt.Network, opt.Addr) + rdb.AddHook(newTracingHook(connString, opts...)) + }) return nil case *redis.Ring: rdb.OnNewNode(func(rdb *redis.Client) { @@ -44,6 +51,13 @@ func InstrumentTracing(rdb redis.UniversalClient, opts ...TracingOption) error { connString := formatDBConnString(opt.Network, opt.Addr) rdb.AddHook(newTracingHook(connString, opts...)) }) + + rdb.ForEachShard(ctx, func(ctx context.Context, rdb *redis.Client) error { + opt := rdb.Options() + opts = addServerAttributes(opts, opt.Addr) + connString := formatDBConnString(opt.Network, opt.Addr) + rdb.AddHook(newTracingHook(connString, opts...)) + }) return nil default: return fmt.Errorf("redisotel: %T not supported", rdb) From 5287a9c86db094895dc8b5f0b71a9cc94d3fed3b Mon Sep 17 00:00:00 2001 From: Allan Guigou <34221163+AllanGuigou@users.noreply.github.com> Date: Tue, 15 Jul 2025 15:12:11 +0000 Subject: [PATCH 2/3] Bump to v9.12.0 From 78c8b28c268797f0aac1e72506e203074c16ad26 Mon Sep 17 00:00:00 2001 From: Allan Guigou <34221163+AllanGuigou@users.noreply.github.com> Date: Tue, 15 Jul 2025 15:27:41 +0000 Subject: [PATCH 3/3] Fix missing return --- extra/redisotel/tracing.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extra/redisotel/tracing.go b/extra/redisotel/tracing.go index f0ca28da6..95f7031f2 100644 --- a/extra/redisotel/tracing.go +++ b/extra/redisotel/tracing.go @@ -42,6 +42,7 @@ func InstrumentTracing(ctx context.Context, rdb redis.UniversalClient, opts ...T opts = addServerAttributes(opts, opt.Addr) connString := formatDBConnString(opt.Network, opt.Addr) rdb.AddHook(newTracingHook(connString, opts...)) + return nil }) return nil case *redis.Ring: @@ -57,6 +58,7 @@ func InstrumentTracing(ctx context.Context, rdb redis.UniversalClient, opts ...T opts = addServerAttributes(opts, opt.Addr) connString := formatDBConnString(opt.Network, opt.Addr) rdb.AddHook(newTracingHook(connString, opts...)) + return nil }) return nil default: