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.
// 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.
// create a client opts := &redis.Options{Addr: "127.0.0.1", Password: "", DB: 0} c := redistrace.NewClient(opts, redistrace.WithServiceName("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.ExecContext(context.Background())
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(opt *redis.Options, opts ...ClientOption) *redis.Client
NewClient returns a new Client that is traced with the default tracer under the service name "redis".
func WrapClient ¶
func WrapClient(client redis.UniversalClient, opts ...ClientOption)
WrapClient adds a hook to the given client that traces with the default tracer under the service name "redis".
Types ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption represents an option that can be used to create or wrap a client.
func WithAnalytics ¶
func WithAnalytics(on bool) ClientOption
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
func WithAnalyticsRate(rate float64) ClientOption
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithErrorCheck ¶ added in v1.53.0
func WithErrorCheck(fn func(err error) bool) ClientOption
WithErrorCheck specifies a function fn which determines whether the passed error should be marked as an error.
func WithServiceName ¶
func WithServiceName(name string) ClientOption
WithServiceName sets the given service name for the client.