redisotel

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: BSD-2-Clause Imports: 18 Imported by: 0

README

goredisotel

ci codecov

A fork of go-redis/extra/redisotel/v9 that follows Semantic Conventions v1.30.

Installation

go get github.com/wzy9607/goredisotel

Usage

Tracing is enabled by adding a hook:

import (
"github.com/redis/go-redis/v9"
"github.com/wzy9607/goredisotel"
)

rdb := rdb.NewClient(&rdb.Options{...})

// Enable tracing and metrics instrumentation.
if err := goredisotel.InstrumentClientWithHooks(rdb); err != nil {
panic(err)
}

// Enable tracing instrumentation only.
if err := goredisotel.InstrumentClientWithHooks(rdb, goredisotel.DisableMetrics()); err != nil {
panic(err)
}

// Enable pool statistics metrics instrumentation.
if err := goredisotel.InstrumentPoolStatsMetrics(rdb); err != nil {
panic(err)
}

See example for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentClientWithHooks

func InstrumentClientWithHooks(rdb redis.UniversalClient, opts ...Option) error

InstrumentClientWithHooks starts reporting OpenTelemetry Tracing and Metrics.

Based on https://opentelemetry.io/docs/specs/semconv/database/.

func InstrumentPoolStatsMetrics

func InstrumentPoolStatsMetrics(rdb redis.UniversalClient, opts ...Option) error

InstrumentPoolStatsMetrics starts reporting OpenTelemetry Metrics for the connection pool.

func SetBuckets

func SetBuckets(b []float64)

SetBuckets sets the buckets used for OpenTelemetry metrics. The default buckets of .001, .005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10 are used if SetBuckets is not called. The default buckets are finer than the one in the Semantic Conventions.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the instrumentation.

func DisableMetrics

func DisableMetrics() Option

DisableMetrics tells the hook not to record metrics.

func EnableDBQueryText added in v0.3.0

func EnableDBQueryText() Option

EnableDBQueryText tells the tracing hook to log raw redis commands.

func WithAttributes

func WithAttributes(attrs ...attribute.KeyValue) Option

WithAttributes specifies additional attributes to be added to the span.

func WithMeterProvider

func WithMeterProvider(mp metric.MeterProvider) Option

WithMeterProvider configures a metric.Meter used to create instruments.

func WithPoolName

func WithPoolName(poolName string) Option

WithPoolName specifies the pool name to use in the attributes.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

Jump to

Keyboard shortcuts

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