Documentation ¶
Overview ¶
Package redigo provides tracing for the Redigo Redis client (https://github.com/garyburd/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" redigotrace "github.com/DataDog/dd-trace-go/contrib/garyburd/redigo" "github.com/DataDog/dd-trace-go/tracer" ) func main() { c, _ := redigotrace.TracedDial("my-redis-backend", tracer.DefaultTracer, "tcp", "127.0.0.1:6379") // 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 := tracer.NewRootSpan("parent.request", "web", "/home") ctx := root.Context(context.Background()) // 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 ( redigotrace "github.com/DataDog/dd-trace-go/contrib/garyburd/redigo" "github.com/DataDog/dd-trace-go/tracer" ) func main() { c, _ := redigotrace.TracedDialURL("my-redis-backend", tracer.DefaultTracer, "redis://127.0.0.1:6379") 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 "github.com/DataDog/dd-trace-go/contrib/garyburd/redigo" "github.com/DataDog/dd-trace-go/tracer" "github.com/garyburd/redigo/redis" ) func main() { pool := &redis.Pool{ Dial: func() (redis.Conn, error) { return redigotrace.TracedDial("my-redis-backend", tracer.DefaultTracer, "tcp", "127.0.0.1:6379") }, } c := pool.Get() c.Do("SET", " whiskey", " glass") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type TracedConn ¶
TracedConn is an implementation of the redis.Conn interface that supports tracing
Example ¶
package main import ( "context" redigotrace "github.com/DataDog/dd-trace-go/contrib/garyburd/redigo" "github.com/DataDog/dd-trace-go/tracer" ) func main() { c, _ := redigotrace.TracedDial("my-redis-backend", tracer.DefaultTracer, "tcp", "127.0.0.1:6379") // 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 := tracer.NewRootSpan("parent.request", "web", "/home") ctx := root.Context(context.Background()) // 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:
func (TracedConn) Do ¶
func (tc TracedConn) Do(commandName string, args ...interface{}) (reply interface{}, err error)
Do wraps redis.Conn.Do. It sends a command to the Redis server and returns the received reply. In the process it emits a span containing key information about the command sent. When passed a context.Context as the final argument, Do will ensure that any span created inherits from this context. The rest of the arguments are passed through to the Redis server unchanged
func (TracedConn) NewChildSpan ¶
func (tc TracedConn) NewChildSpan(ctx context.Context) *tracer.Span
NewChildSpan creates a span inheriting from the given context. It adds to the span useful metadata about the traced Redis connection