Documentation ¶
Overview ¶
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.
Example ¶
To start tracing Redis, simply create a new client using the library and continue using as you normally would.
package main import ( "context" redistrace "github.com/DataDog/dd-trace-go/v2/contrib/go-redis/redis" "github.com/DataDog/dd-trace-go/v2/ddtrace/ext" "github.com/DataDog/dd-trace-go/v2/ddtrace/tracer" "github.com/go-redis/redis" ) func main() { // create a new Client opts := &redis.Options{Addr: "127.0.0.1", 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", tracer.SpanType(ext.SpanTypeRedis), tracer.ServiceName("web"), tracer.ResourceName("/home"), ) // 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) root.Finish() }
Output:
Example (Pipeliner) ¶
You can also trace Redis Pipelines. Simply use as usual and the traces will be automatically picked up by the underlying implementation.
package main import ( "time" redistrace "github.com/DataDog/dd-trace-go/v2/contrib/go-redis/redis" "github.com/go-redis/redis" ) func main() { // create a client opts := &redis.Options{Addr: "127.0.0.1", Password: "", DB: 0} c := redistrace.NewClient(opts, redistrace.WithService("my-redis-service")) // open the pipeline pipe := c.Pipeline() // submit some commands pipe.Incr("pipeline_counter") pipe.Expire("pipeline_counter", time.Hour) // execute with trace pipe.Exec() }
Output:
Index ¶
- type Client
- func (c *Client) Pipeline() redis.Pipeliner
- func (c *Client) Pipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
- func (c *Client) TxPipeline() redis.Pipeliner
- func (c *Client) TxPipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
- func (c *Client) WithContext(ctx context.Context) *Client
- type ClientOption
- type ClientOptionFn
- type Pipeliner
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is used to trace requests to a redis server.
func NewClient ¶
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 ¶
func WrapClient(c *redis.Client, opts ...ClientOption) *Client
WrapClient wraps a given redis.Client with a tracer under the given service name.
func (*Client) Pipelined ¶
Pipelined executes a function parameter to build a Pipeline and then immediately executes it.
func (*Client) TxPipeline ¶
TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
func (*Client) TxPipelined ¶
TxPipelined executes a function parameter to build a Transactional Pipeline and then immediately executes it.
type ClientOption ¶
type ClientOption interface {
// contains filtered or unexported methods
}
ClientOption describes options for the Redis integration.
type ClientOptionFn ¶
type ClientOptionFn func(*clientConfig)
ClientOptionFn represents options applicable to NewClient and WrapClient.
func WithAnalytics ¶
func WithAnalytics(on bool) ClientOptionFn
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
func WithAnalyticsRate(rate float64) ClientOptionFn
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithService ¶
func WithService(name string) ClientOptionFn
WithService sets the given service name for the client.
type Pipeliner ¶
Pipeliner is used to trace pipelines executed on a Redis server.
func (*Pipeliner) Exec ¶
Exec calls Pipeline.Exec() ensuring that the resulting Redis calls are traced.
func (*Pipeliner) ExecWithContext ¶
ExecWithContext calls Pipeline.Exec(). It ensures that the resulting Redis calls are traced, and that emitted spans are children of the given Context.