Skip to content

Tracing Plugin

Trace Redis operations across your distributed system.

Overview

QuestionWithout TracingWith Tracing Plugin
Where is latency?UnknownRedis GET: 2ms
Request flow?GuessworkTrace visualization
Which cache missed?Logs searchSpan attributes
Error origin?Stack traceDistributed context

Key Features

  • Spans — Redis commands, cache operations, lock acquire/release, rate limit checks
  • Context Propagation — Trace propagation, parent-child spans
  • Exporters — OTLP, Jaeger, Zipkin, Console
  • Sampling — Always, Never, Ratio, Parent-based

Installation

bash
npm install @nestjs-redisx/core @nestjs-redisx/tracing ioredis
bash
npm install @nestjs-redisx/core @nestjs-redisx/tracing redis

Basic Configuration

typescript
import { Module } from '@nestjs/common';
import { RedisModule } from '@nestjs-redisx/core';
import { TracingPlugin } from '@nestjs-redisx/tracing';

@Module({
  imports: [
    RedisModule.forRoot({
      clients: {
        host: 'localhost',
        port: 6379,
      },
      plugins: [
        new TracingPlugin({
          serviceName: 'my-service',
          exporter: {
            type: 'otlp',
            endpoint: 'http://jaeger:4318',
          },
        }),
      ],
    }),
  ],
})
export class AppModule {}

Viewing Traces

Open Jaeger UI at http://localhost:16686:

Trace: GET /api/users/123
├── HTTP GET /api/users/123 (50ms)
│   ├── redis.GET user:123 (1ms) ← Cache miss
│   ├── database.query (35ms)
│   └── redis.SET user:123 (2ms) ← Cache set

Trace Flow

Span Attributes

Each Redis span includes:

json
{
  "name": "redis.GET",
  "attributes": {
    "db.system": "redis",
    "db.operation": "GET",
    "db.redis.key": "user:123",
    "redisx.plugin": "cache",
    "redisx.cache.hit": false,
    "redisx.duration_ms": 1.23
  }
}

Architecture

Documentation

TopicDescription
Core ConceptsUnderstanding distributed tracing
ConfigurationConfiguration reference
OpenTelemetryOTel integration
ExportersExporter configuration
SpansSpan details
Plugin TracingPer-plugin tracing
SamplingSampling strategies
VisualizationViewing traces
TroubleshootingDebugging common issues

Released under the MIT License.