Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Add redigo.WithSpanOptions #157

Merged
merged 3 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions contrib/gomodule/redigo/option.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package redigo // import "github.com/signalfx/signalfx-go-tracing/contrib/gomodule/redigo"

import "github.com/signalfx/signalfx-go-tracing/ddtrace"

type dialConfig struct {
serviceName string
analyticsRate float64
spanOpts []ddtrace.StartSpanOption
}

// DialOption represents an option that can be passed to Dial.
Expand Down Expand Up @@ -35,3 +38,11 @@ func WithAnalyticsRate(rate float64) DialOption {
cfg.analyticsRate = rate
}
}

// WithSpanOptions defines a set of additional ddtrace.StartSpanOption to be added
// to spans started by the integration.
func WithSpanOptions(opts ...ddtrace.StartSpanOption) DialOption {
return func(cfg *dialConfig) {
cfg.spanOpts = append(cfg.spanOpts, opts...)
}
}
4 changes: 2 additions & 2 deletions contrib/gomodule/redigo/redigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func DialURL(rawurl string, options ...interface{}) (redis.Conn, error) {
// newChildSpan creates a span inheriting from the given context. It adds to the span useful metadata about the traced Redis connection
func (tc Conn) newChildSpan(ctx context.Context) ddtrace.Span {
p := tc.params
opts := []ddtrace.StartSpanOption{
opts := append([]ddtrace.StartSpanOption{
tracer.SpanType(ext.SpanTypeRedis),
tracer.ServiceName(p.config.serviceName),
tracer.Tag(ext.DBType, "redis"),
tracer.Tag(ext.SpanKind, ext.SpanKindClient),
}
}, p.config.spanOpts...)
if rate := p.config.analyticsRate; rate > 0 {
opts = append(opts, tracer.Tag(ext.EventSampleRate, rate))
}
Expand Down
3 changes: 2 additions & 1 deletion contrib/gomodule/redigo/redigo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestClient(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()

c, err := Dial("tcp", "127.0.0.1:6379", WithServiceName("my-service"))
c, err := Dial("tcp", "127.0.0.1:6379", WithServiceName("my-service"), WithSpanOptions(tracer.Tag("foo", "bar")))
assert.Nil(err)
c.Do("SET", 1, "truck")

Expand All @@ -46,6 +46,7 @@ func TestClient(t *testing.T) {
assert.Equal("redis", span.Tag(ext.DBType))
assert.Equal("SET 1 truck", span.Tag("redis.raw_command"))
assert.Equal("2", span.Tag("redis.args_length"))
assert.Equal("bar", span.Tag("foo"))
}

func TestCommandError(t *testing.T) {
Expand Down