Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/gomodule/redigo: adds the DialURLContext method #3016

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions contrib/gomodule/redigo/redigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,7 @@ func wrapConn(c redis.Conn, p *params) redis.Conn {
// Dial dials into the network address and returns a traced redis.Conn.
// The set of supported options must be either of type redis.DialOption or this package's DialOption.
func Dial(network, address string, options ...interface{}) (redis.Conn, error) {
dialOpts, cfg := parseOptions(options...)
log.Debug("contrib/gomodule/redigo: Dialing %s %s, %#v", network, address, cfg)
c, err := redis.Dial(network, address, dialOpts...)
if err != nil {
return nil, err
}
host, port, err := net.SplitHostPort(address)
if err != nil {
return nil, err
}
tc := wrapConn(c, &params{cfg, network, host, port})
return tc, nil
return DialContext(context.Background(), network, address, options...)
}

// DialContext dials into the network address using redis.DialContext and returns a traced redis.Conn.
Expand All @@ -132,6 +121,14 @@ func DialContext(ctx context.Context, network, address string, options ...interf
// scheme (https://www.iana.org/assignments/uri-schemes/prov/redis).
// The returned redis.Conn is traced.
func DialURL(rawurl string, options ...interface{}) (redis.Conn, error) {
return DialURLContext(context.Background(), rawurl, options...)
}

// DialURLContext connects to a Redis server at the given URL using the Redis
// URI scheme. URLs should follow the draft IANA specification for the
// scheme (https://www.iana.org/assignments/uri-schemes/prov/redis).
// The returned redis.Conn is traced.
func DialURLContext(ctx context.Context, rawurl string, options ...interface{}) (redis.Conn, error) {
dialOpts, cfg := parseOptions(options...)
log.Debug("contrib/gomodule/redigo: Dialing %s, %#v", rawurl, cfg)
u, err := url.Parse(rawurl)
Expand All @@ -147,7 +144,7 @@ func DialURL(rawurl string, options ...interface{}) (redis.Conn, error) {
host = "localhost"
}
network := "tcp"
c, err := redis.DialURL(rawurl, dialOpts...)
c, err := redis.DialURLContext(ctx, rawurl, dialOpts...)
tc := wrapConn(c, &params{cfg, network, host, port})
return tc, err
}
Expand Down
15 changes: 15 additions & 0 deletions contrib/gomodule/redigo/redigo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ func TestTracingDialUrl(t *testing.T) {
assert.True(len(spans) > 0)
}

func TestTracingDialUrlContext(t *testing.T) {
assert := assert.New(t)
mt := mocktracer.Start()
defer mt.Stop()

ctx := context.Background()
url := "redis://127.0.0.1:6379"
client, err := DialURLContext(ctx, url, WithServiceName("redis-service"))
assert.Nil(err)
client.Do("SET", "ONE", " TWO", context.Background())

spans := mt.FinishedSpans()
assert.True(len(spans) > 0)
}

func TestTracingDialContext(t *testing.T) {
assert := assert.New(t)
mt := mocktracer.Start()
Expand Down
Loading