Monitoring Go Redis Performance and Errors
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework for distributed tracing (including logs and errors) and metrics.
Otel allows developers to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation, for example, here is a list popular DataDog alternatives that support OpenTelemetry.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
OpenTelemetry instrumentation
go-redis comes with an OpenTelemetry instrumentation called redisotel that is distributed as a separate module:
go get github.com/go-redis/redis/extra/redisotel/v8
To instrument Redis client, you need to add the hook provided by redisotel:
import (
"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/extra/redisotel/v8"
)
rdb := redis.NewClient(&redis.Options{...})
rdb.AddHook(redisotel.NewTracingHook())
For Redis Cluster and Ring you need to instrument each node separately:
rdb := redis.NewClusterClient(&redis.ClusterOptions{
// ...
NewClient: func(opt *redis.Options) *redis.Client {
node := redis.NewClient(opt)
node.AddHook(redisotel.NewTracingHook())
return node
},
})
rdb.AddHook(redisotel.NewTracingHook())
To make tracing work, you must pass the active trace context to go-redis commands, for example:
ctx := req.Context()
val, err := rdb.Get(ctx, "key").Result()
Uptrace
Uptrace is an open source DataDog competitor with an intuitive query builder, rich dashboards, automatic alerts, and integrations for most languages and frameworks.
You can install Uptrace by downloading a DEB/RPM package or a pre-compiled binary.
As expected, redisotel creates spans for processed Redis commands and records any errors as they occur. Here is how the collected information is displayed at Uptrace tracing tool:
You can find a runnable example at GitHub.
Prometheus
You can send OpenTelemetry metrics to Prometheus using OpenTelemetry Prometheus exporter.
Monitoring Redis Server performance
See Monitoring Redis Performance using OpenTelemetry.