Tracing Plugin
Trace Redis operations across your distributed system.
Overview
| Question | Without Tracing | With Tracing Plugin |
|---|---|---|
| Where is latency? | Unknown | Redis GET: 2ms |
| Request flow? | Guesswork | Trace visualization |
| Which cache missed? | Logs search | Span attributes |
| Error origin? | Stack trace | Distributed 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 ioredisbash
npm install @nestjs-redisx/core @nestjs-redisx/tracing redisBasic 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 setTrace 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
| Topic | Description |
|---|---|
| Core Concepts | Understanding distributed tracing |
| Configuration | Configuration reference |
| OpenTelemetry | OTel integration |
| Exporters | Exporter configuration |
| Spans | Span details |
| Plugin Tracing | Per-plugin tracing |
| Sampling | Sampling strategies |
| Visualization | Viewing traces |
| Troubleshooting | Debugging common issues |