Registry / testing / zipkin-instrumentation-redis

zipkin-instrumentation-redis

JSON →
library0.22.0jsnpmunverified

Interceptor for Redis clients that automatically creates spans for Redis commands and adds Zipkin tracing context. Part of the Zipkin JavaScript library (v0.22.0), maintained by OpenZipkin. This package wraps the 'redis' npm client to produce distributed tracing spans. Release cadence is tied to the monorepo release cycle (approximately quarterly). Key differentiators: native Zipkin integration, support for Redis callbacks and promises, and automatic span propagation without manual instrumentation. Requires 'zipkin' and 'redis' as peer dependencies.

npm install zipkin-instrumentation-redis
INSTALL
IMPORT
SIG · ZIPKIN-INSTRUMENTA
Z
zipkin-instrumentation-redis
testingjavascriptv0.22.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wrapRedisClient
import { wrapRedisClient } from 'zipkin-instrumentation-redis'
const { wrapRedisClient } = require('zipkin-instrumentation-redis')
Package is ESM-only; requires 'type': 'module' in package.json or use of .mjs extension
wrapRedisClient
const { wrapRedisClient } = await import('zipkin-instrumentation-redis')
const wrapRedisClient = require('zipkin-instrumentation-redis')
For CommonJS projects, use dynamic import()
Tracer
import { Tracer } from 'zipkin'
import { Tracer } from 'zipkin-instrumentation-redis'
Tracer is exported from the core 'zipkin' package, not from this instrumentation

Creates a Zipkin tracer, wraps a Redis client to automatically trace commands, and sets a key with a callback.

import { Tracer, BatchRecorder, jsonEncoder } from 'zipkin'; import { HttpLogger } from 'zipkin-transport-http'; import { wrapRedisClient } from 'zipkin-instrumentation-redis'; import redis from 'redis'; const tracer = new Tracer({ ctxImpl: new ExplicitContext(), recorder: new BatchRecorder({ logger: new HttpLogger({ endpoint: 'http://localhost:9411/api/v2/spans', jsonEncoder: jsonEncoder.JSON_V2 }) }), localServiceName: 'redis-service' }); const client = redis.createClient({ host: 'localhost', port: 6379 }); const tracedClient = wrapRedisClient(client, { tracer }); tracedClient.set('key', 'value', (err, reply) => { if (err) console.error(err); else console.log(reply); });
Debug
Known issues
gotchawrapRedisClient requires the tracer option to be passed in the second argument. If you omit it, no tracing will occur silently.
fix
Always pass { tracer } as the second argument to wrapRedisClient.
affects: <0.22.0
deprecatedThe old API (wrapRedisClient(redis, { tracer })) where redis is the module object is deprecated. Use the new API that takes an existing client instance.
fix
Wrap a client instance: wrapRedisClient(client, { tracer }).
affects: >=0.22.0
gotchawrapRedisClient modifies the original client object in place. The returned client is the same reference with added tracing.
fix
Use the returned tracedClient, but note that the original client is also traced after this call.
affects: >=0.22.0
gotchaThis package only supports the 'redis' npm package (v2, v3, v4). It does NOT support ioredis.
fix
For ioredis, use 'zipkin-instrumentation-ioredis' instead.
affects: >=0.22.0
breakingThe import path changed from 'zipkin-instrumentation-redis/wrapRedisClient' to just 'zipkin-instrumentation-redis' in v0.22.0.
fix
Use 'import { wrapRedisClient } from 'zipkin-instrumentation-redis''
affects: >=0.22.0
Errors
Common errors & fixes
TypeError: Cannot read property 'createClient' of undefined
wrapRedisClient expects a Redis client instance, not the module object.
fix
Create a client first: const client = redis.createClient(); const traced = wrapRedisClient(client, { tracer });
Error: tracer is required
Missing tracer option in the second argument to wrapRedisClient.
fix
Pass { tracer: yourTracer } as second argument.
TypeError: Cannot read properties of undefined (reading 'record')
Tracer not initialized or recorder not set up correctly.
fix
Ensure tracer has a recorder (e.g., ConsoleRecorder for testing).
Upgrade
Version history
0.22.0latest on npm
Audit
Dependencies
zipkinrequiredCore Zipkin tracing library required for creating and recording spans
redisrequiredRedis client that will be instrumented
Agent activity
33 hits · last 30 days
node
28
OpenAI (training)
1
Resources
zipkin-instrumentation-redis — npm install zipkin-instrumentation-redis · libregistry