Monitoring Go Redis Performance and Errors
This document explains how to monitor Go Redis client performace using OpenTelemetry. To monitor Redis server performance and metrics, see OpenTelemetry Redis Monitoring.
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework for OpenTelemetry tracing (including logs and errors) and OpenTelemetry 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 competitors 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/redis/go-redis/extra/redisotel/v9
To instrument Redis client, you need to add the hook provided by redisotel. The same methods can be used to instrument redis.Client
, redis.ClusterClient
, and redis.Ring
.
import (
"github.com/redis/go-redis/v9"
"github.com/redis/go-redis/extra/redisotel/v9"
)
rdb := redis.NewClient(&redis.Options{...})
// Enable tracing instrumentation.
if err := redisotel.InstrumentTracing(rdb); err != nil {
panic(err)
}
// Enable metrics instrumentation.
if err := redisotel.InstrumentMetrics(rdb); err != nil {
panic(err)
}
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 APM that supports distributed tracing, metrics, and logs. You can use it to monitor applications and set up automatic alerts to receive notifications via email, Slack, Telegram, and more.
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:
You can find a runnable example at GitHub.
Prometheus
You can also send OpenTelemetry metrics to Prometheus using OpenTelemetry Prometheus exporter.
What's next?
Next, start using Uptrace by following the Getting started guide.
Popular instrumentations: