Redis

Redis is observed through the client span each command produces. This page lists the OpenTelemetry instrumentation for each language and what the span records about the command.

The Redis client in your application is instrumented by OpenTelemetry, and every command becomes a client span inside the trace of the request that issued it. Nothing is installed on the server, so the same setup applies to a self-hosted Redis, ElastiCache, Memorystore, and Redis-compatible servers that the same client connects to.

What is collected

SpanOne CLIENT span per command, named after the command (GET, HSET)
Identitydb.system.name = redis (db.system in instrumentation releases that predate the stable database conventions)
StatementThe command, with its arguments reduced as described under Command text
TargetServer address and port
OutcomeDuration, and an error status when the command fails

A single command is usually fast. The spans are most useful in aggregate within one trace: a request that issues the same GET two hundred times, or a cache lookup that takes longer than the query it was meant to avoid.

Enabling it

The Sophonz Node.js SDK loads the instrumentation for both redis (2.6 up to, not including, 7) and ioredis (2 up to, not including, 6). Command spans are produced with no configuration.

The two differ in one default. ioredis creates a span only when a parent span is active, so commands issued outside a request, from a timer or at startup, produce nothing. redis records those as well. The option is requireParentSpan.

import { init } from '@sophonz/node-sdk';
 
init({
  service: 'checkout-api',
  apiKey: process.env.SOPHONZ_API_KEY,
  instrumentations: {
    '@opentelemetry/instrumentation-ioredis': {
      requireParentSpan: false,
    },
  },
});

Command text

Values written to Redis are often user data, and the instrumentations do not record them by default.

LanguageDefault
Node.jsThe command name and, for common commands, the key. Remaining arguments are replaced with a count, as in SET session:42 [1 other arguments]. dbStatementSerializer overrides this
PythonThe command name with every argument replaced, as in SET ? ?. The key is not recorded
JavaSanitized. Values are replaced with ?

Keys are recorded in Node.js. Where a key embeds an identifier that should not leave the application, pass a dbStatementSerializer that returns only the command name.

In Sophonz

Command spans sit under the request span in the trace, together with the browser or mobile session that started the request. They belong to the application's service: the Service Flow panel draws a node per service, so Redis does not appear as a node of its own.

Because the attributes are stored with the span, they can be queried in Grafana.

SELECT serviceName, name, count() AS calls, avg(durationNano) / 1e6 AS avg_ms
FROM sophonz_traces.distributed_sophonz_index_v2
WHERE $__timeFilter(timestamp)
  AND (stringTagMap['db.system.name'] = 'redis' OR stringTagMap['db.system'] = 'redis')
GROUP BY serviceName, name
ORDER BY calls DESC
LIMIT 20

Server-side figures such as memory use, evictions, and connected clients are metrics. Sophonz does not accept metrics, so they are not part of this path. See Connecting infrastructure.