Documentation ¶
Overview ¶
Package redigo provides functions to trace the gomodule/redigo package (https://github.com/gomodule/redigo).
Example ¶
To start tracing Redis commands, use the TracedDial function to create a connection, passing in a service name of choice.
package main import ( "context" "log" redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" ) func main() { c, err := redigotrace.Dial("tcp", "127.0.0.1:6379") if err != nil { log.Fatal(err) } // Emit spans per command by using your Redis connection as usual c.Do("SET", "vehicle", "truck") // Use a context to pass information down the call chain root, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request", tracer.ServiceName("web"), tracer.ResourceName("/home"), ) // When passed a context as the final argument, c.Do will emit a span inheriting from 'parent.request' c.Do("SET", "food", "cheese", ctx) root.Finish() }
Output:
Example (DialURL) ¶
Alternatively, provide a redis URL to the TracedDialURL function
package main import ( "log" redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" ) func main() { c, err := redigotrace.DialURL("redis://127.0.0.1:6379") if err != nil { log.Fatal(err) } c.Do("SET", "vehicle", "truck") }
Output:
Example (Pool) ¶
When using a redigo Pool, set your Dial function to return a traced connection
package main import ( redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" "github.com/gomodule/redigo/redis" ) func main() { pool := &redis.Pool{ Dial: func() (redis.Conn, error) { return redigotrace.Dial("tcp", "127.0.0.1:6379", redigotrace.WithServiceName("my-redis-backend"), ) }, } c := pool.Get() c.Do("SET", " whiskey", " glass") }
Output:
Example (TracedConn) ¶
package main import ( "context" "log" "time" redigotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" "github.com/gomodule/redigo/redis" ) func main() { c, err := redigotrace.Dial("tcp", "127.0.0.1:6379", redigotrace.WithServiceName("my-redis-backend"), redis.DialKeepAlive(time.Minute), ) if err != nil { log.Fatal(err) } // Emit spans per command by using your Redis connection as usual c.Do("SET", "vehicle", "truck") // Use a context to pass information down the call chain root, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request", tracer.ServiceName("web"), tracer.ResourceName("/home"), ) // When passed a context as the final argument, c.Do will emit a span inheriting from 'parent.request' c.Do("SET", "food", "cheese", ctx) root.Finish() }
Output:
Index ¶
- func Dial(network, address string, options ...interface{}) (redis.Conn, error)
- func DialContext(ctx context.Context, network, address string, options ...interface{}) (redis.Conn, error)
- func DialURL(rawurl string, options ...interface{}) (redis.Conn, error)
- type Conn
- type ConnWithContext
- type ConnWithTimeout
- type DialOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
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 DialContext ¶ added in v1.44.0
func DialContext(ctx context.Context, network, address string, options ...interface{}) (redis.Conn, error)
DialContext dials into the network address using redis.DialContext and returns a traced redis.Conn. The set of supported options must be either of type redis.DialOption or this package's DialOption.
func DialURL ¶
DialURL 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.
Types ¶
type ConnWithContext ¶ added in v1.44.0
type ConnWithContext = v2.ConnWithContext
ConnWithContext is an implementation of the redis.ConnWithContext interface that supports tracing
type ConnWithTimeout ¶ added in v1.24.0
type ConnWithTimeout = v2.ConnWithTimeout
ConnWithTimeout is an implementation of the redis.ConnWithTimeout interface that supports tracing
type DialOption ¶
type DialOption = v2.DialOption
DialOption represents an option that can be passed to Dial.
func WithAnalytics ¶
func WithAnalytics(on bool) DialOption
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
func WithAnalyticsRate(rate float64) DialOption
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithContextConnection ¶ added in v1.44.0
func WithContextConnection() DialOption
WithContextConnection wraps the connection with redis.ConnWithContext.
func WithDefaultConnection ¶ added in v1.44.0
func WithDefaultConnection() DialOption
WithDefaultConnection overrides the default connectionType to not be connectionTypeWithTimeout.
func WithServiceName ¶
func WithServiceName(name string) DialOption
WithServiceName sets the given service name for the dialled connection.
func WithTimeoutConnection ¶ added in v1.44.0
func WithTimeoutConnection() DialOption
WithTimeoutConnection wraps the connection with redis.ConnWithTimeout.