Monitoring performance and errors

Monitoring go-redis client

You can monitor Redis performance and errors using distributed tracingopen in new window. Tracing allows you to see how a request progresses through different services and systems, timings of every operation, any logs and errors as they occur.

go-redis supports tracing using OpenTelemetryopen in new window API. OpenTelemetry is a vendor-neutral API for distributed traces and metrics. It specifies how to collect and send telemetry data to backend platforms. It means that you can instrument your application once and then add or change vendors (backends) as required.

go-redis comes with an OpenTelemetry instrumentation called redisotelopen in new window 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())

As expected, redisotel creates spansopen in new window for processed Redis commands and records any errors as they occur. Here is how the collected information is displayed at Uptraceopen in new window:

Redis trace

If you need an example, see GitHubopen in new window.

Monitoring Redis Server

See Monitoring Redis Server with OpenTelemetry Collectoropen in new window.