redisopentracing

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 5 Imported by: 0

README

go-redis-opentracing

go-redis hook to collect OpenTracing spans.

There are similar older libs that do not benefit from go-redis newer hooks feature. This is heavily inspired by https://github.com/go-redis/redis/blob/master/extra/redisotel/redisotel.go, but with support for OpenTracing instead of OpenTelemetry.

Also check out our lib https://github.com/globocom/go-redis-prometheus.

Installation

go get github.com/globocom/go-redis-opentracing

Usage

package main

import (
	redisopentracing "github.com/globocom/go-redis-opentracing"
	"github.com/go-redis/redis/v8"
	jaegerConfig "github.com/uber/jaeger-client-go/config"
)

func main() {
	cfg := &jaegerConfig.Configuration{
		ServiceName: "my-service-name",
	}
	tracer, _, _ := cfg.NewTracer()

	hook := redisopentracing.NewHook(tracer)

	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "",
	})
	client.AddHook(hook)

	// run redis commands...
}

Note on pipelines

Pipelines generate a single span. For each error that occurs on the pipeline, a tag db.error<commandIndex> will be set.

API stability

The API is unstable at this point, and it might change before v1.0.0 is released.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHook

func NewHook(tracer opentracing.Tracer) redis.Hook

NewHook creates a new go-redis hook instance and that will collect spans using the provided tracer.

Types

type RedisTracingHook

type RedisTracingHook struct {
	// contains filtered or unexported fields
}

func (RedisTracingHook) AfterProcess

func (hook RedisTracingHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error

func (RedisTracingHook) AfterProcessPipeline

func (hook RedisTracingHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error

func (RedisTracingHook) BeforeProcess

func (hook RedisTracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)

func (RedisTracingHook) BeforeProcessPipeline

func (hook RedisTracingHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)

Jump to

Keyboard shortcuts

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