redigo

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

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

func TracedDial

func TracedDial(service string, tracer *tracer.Tracer, network, address string, options ...redis.DialOption) (redis.Conn, error)

TracedDial takes a Conn returned by redis.Dial and configures it to emit spans with the given service name

func TracedDialURL

func TracedDialURL(service string, tracer *tracer.Tracer, rawurl string, options ...redis.DialOption) (redis.Conn, error)

TracedDialURL takes a Conn returned by redis.DialURL and configures it to emit spans with the given service name

Types

type TracedConn

type TracedConn struct {
	redis.Conn
	// contains filtered or unexported fields
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL