dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis Index | Examples | Files

package redis

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis"

Package redis provides tracing functions for tracing the go-redis/redis package (https://github.com/go-redis/redis). This package supports versions up to go-redis 6.15.

To start tracing Redis, simply create a new client using the library and continue using as you normally would.


// create a new Client
opts := &redis.Options{Addr: "", Password: "", DB: 0}
c := redistrace.NewClient(opts)

// any action emits a span
c.Set("test_key", "test_value", 0)

// optionally, create a new root span
root, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",

// set the context on the client
c = c.WithContext(ctx)

// commit further commands, which will inherit from the parent in the context.
c.Set("food", "cheese", 0)

You can also trace Redis Pipelines. Simply use as usual and the traces will be automatically picked up by the underlying implementation.


// create a client
opts := &redis.Options{Addr: "", Password: "", DB: 0}
c := redistrace.NewClient(opts, redistrace.WithServiceName("my-redis-service"))

// open the pipeline
pipe := c.Pipeline()

// submit some commands
pipe.Expire("pipeline_counter", time.Hour)

// execute with trace



Package Files

option.go redis.go

type Client Uses

type Client struct {
    // contains filtered or unexported fields

Client is used to trace requests to a redis server.

func NewClient Uses

func NewClient(opt *redis.Options, opts ...ClientOption) *Client

NewClient returns a new Client that is traced with the default tracer under the service name "redis".

func WrapClient Uses

func WrapClient(c *redis.Client, opts ...ClientOption) *Client

WrapClient wraps a given redis.Client with a tracer under the given service name.

func (*Client) Pipeline Uses

func (c *Client) Pipeline() redis.Pipeliner

Pipeline creates a Pipeline from a Client

func (*Client) WithContext Uses

func (c *Client) WithContext(ctx context.Context) *Client

WithContext sets a context on a Client. Use it to ensure that emitted spans have the correct parent.

type ClientOption Uses

type ClientOption func(*clientConfig)

ClientOption represents an option that can be used to create or wrap a client.

func WithAnalytics Uses

func WithAnalytics(on bool) ClientOption

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) ClientOption

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName Uses

func WithServiceName(name string) ClientOption

WithServiceName sets the given service name for the client.

type Pipeliner Uses

type Pipeliner struct {
    // contains filtered or unexported fields

Pipeliner is used to trace pipelines executed on a Redis server.

func (*Pipeliner) Exec Uses

func (c *Pipeliner) Exec() ([]redis.Cmder, error)

Exec calls Pipeline.Exec() ensuring that the resulting Redis calls are traced.

func (*Pipeliner) ExecWithContext Uses

func (c *Pipeliner) ExecWithContext(ctx context.Context) ([]redis.Cmder, error)

ExecWithContext calls Pipeline.Exec(). It ensures that the resulting Redis calls are traced, and that emitted spans are children of the given Context.

Package redis imports 12 packages (graph) and is imported by 3 packages. Updated 2020-08-05. Refresh now. Tools for package owners.