From ba0880836e4b9159362dbf44c21d65d765f8eeb8 Mon Sep 17 00:00:00 2001 From: Eliott Bouhana Date: Wed, 23 Oct 2024 11:43:40 +0200 Subject: [PATCH] update samples Signed-off-by: Eliott Bouhana --- .../builtin/testdata/client/redis.go.snap | 65 +++++++++++++++---- samples/client/redis.go | 7 +- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/internal/injector/builtin/testdata/client/redis.go.snap b/internal/injector/builtin/testdata/client/redis.go.snap index 98582bf12..ef865663b 100644 --- a/internal/injector/builtin/testdata/client/redis.go.snap +++ b/internal/injector/builtin/testdata/client/redis.go.snap @@ -9,6 +9,7 @@ package main import ( "context" "fmt" + "time" redisv0 "github.com/go-redis/redis" redisv7 "github.com/go-redis/redis/v7" @@ -19,23 +20,23 @@ import ( __orchestrion_trace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis" __orchestrion_trace1 "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis.v7" __orchestrion_trace2 "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis.v8" - __orchestrion_redigo "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" + __orchestrion_redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" __orchestrion_trace3 "gopkg.in/DataDog/dd-trace-go.v1/contrib/redis/go-redis.v9" ) -//line samples/client/redis.go:19 +//line samples/client/redis.go:20 func redisV0Client() { client := //line func() (client *redisv0.Client) { client = -//line samples/client/redis.go:20 +//line samples/client/redis.go:21 redisv0.NewClient(&redisv0.Options{Addr: "127.0.0.1", Password: "", DB: 0}) //line __orchestrion_trace.WrapClient(client) return }() -//line samples/client/redis.go:21 +//line samples/client/redis.go:22 defer client.Close() if res := client.Set("test_key", "test_value", 0); res.Err() != nil { panic(res.Err()) @@ -47,13 +48,13 @@ func redisV7Client() { //line func() (client *redisv7.Client) { client = -//line samples/client/redis.go:28 +//line samples/client/redis.go:29 redisv7.NewClient(&redisv7.Options{Addr: "127.0.0.1", Password: "", DB: 0}) //line __orchestrion_trace1.WrapClient(client) return }() -//line samples/client/redis.go:29 +//line samples/client/redis.go:30 defer client.Close() if res := client.Set("test_key", "test_value", 0); res.Err() != nil { panic(res.Err()) @@ -65,13 +66,13 @@ func redisV8Client(ctx context.Context) { //line func() (client *redisv8.Client) { client = -//line samples/client/redis.go:36 +//line samples/client/redis.go:37 redisv8.NewClient(&redisv8.Options{Addr: "127.0.0.1", Password: "", DB: 0}) //line __orchestrion_trace2.WrapClient(client) return }() -//line samples/client/redis.go:37 +//line samples/client/redis.go:38 defer client.Close() if res := client.Set(ctx, "test_key", "test_value", 0); res.Err() != nil { panic(res.Err()) @@ -83,13 +84,13 @@ func redisV9Client(ctx context.Context) { //line func() (client *redisv9.Client) { client = -//line samples/client/redis.go:44 +//line samples/client/redis.go:45 redisv9.NewClient(&redisv9.Options{Addr: "127.0.0.1", Password: "", DB: 0}) //line __orchestrion_trace3.WrapClient(client) return }() -//line samples/client/redis.go:45 +//line samples/client/redis.go:46 defer client.Close() if res := client.Set(ctx, "test_key", "test_value", 0); res.Err() != nil { panic(res.Err()) @@ -101,19 +102,57 @@ func redigoClient(ctx context.Context, net, addr string) { conn.Do("SET", "test_key", "test_value", ctx) } - if conn, err := __orchestrion_redigo.Dial(net, addr); err != nil { + if conn, err := +//line + func() (redis.Conn, error) { + return __orchestrion_redigotrace.Dial( +//line samples/client/redis.go:57 + net, addr) + }(); +//line samples/client/redis.go:57 + err != nil { panic(err) } else { use(conn) } - if conn, err := __orchestrion_redigo.DialContext(ctx, net, addr); err != nil { + if conn, err := +//line + func() (redis.Conn, error) { + return __orchestrion_redigotrace.DialContext( +//line samples/client/redis.go:63 + ctx, net, addr) + }(); +//line samples/client/redis.go:63 + err != nil { panic(err) } else { use(conn) } - if conn, err := __orchestrion_redigo.DialURL(fmt.Sprintf("%s://%s", net, addr)); err != nil { + options := []redigo.DialOption{ + redigo.DialConnectTimeout(5 * time.Second), + } + + if conn, err := +//line + func() (redis.Conn, error) { + opts := +//line samples/client/redis.go:73 + options +//line + anyOpts := make([]interface{}, len(opts)) + for i, v := range opts { + anyOpts[i] = v + } + return __orchestrion_redigotrace.DialToto( +//line samples/client/redis.go:73 + fmt.Sprintf("%s://%s", net, addr), +//line + anyOpts...) + }(); +//line samples/client/redis.go:73 + err != nil { panic(err) } else { use(conn) diff --git a/samples/client/redis.go b/samples/client/redis.go index aea6afd69..7a503aacb 100644 --- a/samples/client/redis.go +++ b/samples/client/redis.go @@ -8,6 +8,7 @@ package main import ( "context" "fmt" + "time" redisv0 "github.com/go-redis/redis" redisv7 "github.com/go-redis/redis/v7" @@ -65,7 +66,11 @@ func redigoClient(ctx context.Context, net, addr string) { use(conn) } - if conn, err := redigo.DialURL(fmt.Sprintf("%s://%s", net, addr)); err != nil { + options := []redigo.DialOption{ + redigo.DialConnectTimeout(5 * time.Second), + } + + if conn, err := redigo.DialURL(fmt.Sprintf("%s://%s", net, addr), options...); err != nil { panic(err) } else { use(conn)