Registry / devops / opentelemetry-instrumentation-node-cache

opentelemetry-instrumentation-node-cache

JSON →
library0.41.0jsnpmunverified

Automatic OpenTelemetry instrumentation for node-cache (versions >=5.0.0). Version 0.41.0 is current. Provides tracing for node-cache operations like get, set, del, mget, mset, keys, ttl, has, close, flushAll, stats. Configurable via requestHook and responseHook for adding custom attributes. Requires @opentelemetry/api ^1.8.0. Developed by Aspecto.

npm install opentelemetry-instrumentation-node-cache
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-node-cache
devopsjavascriptv0.41.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.

NodeCacheInstrumentation
import { NodeCacheInstrumentation } from 'opentelemetry-instrumentation-node-cache'
const NodeCacheInstrumentation = require('opentelemetry-instrumentation-node-cache').NodeCacheInstrumentation
CommonJS require is still supported. Named export only, no default export.
NodeCacheInstrumentationConfig
import type { NodeCacheInstrumentationConfig } from 'opentelemetry-instrumentation-node-cache'
import { NodeCacheInstrumentationConfig } from 'opentelemetry-instrumentation-node-cache'
Config type is a TypeScript type, use type import to avoid runtime import.
default
import NodeCacheInstrumentation from 'opentelemetry-instrumentation-node-cache'
import { default as NodeCacheInstrumentation } from 'opentelemetry-instrumentation-node-cache'
Module does not export a default export. Use named import instead.

Setup OpenTelemetry tracing for node-cache with custom hooks and example operations.

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { NodeCacheInstrumentation } = require('opentelemetry-instrumentation-node-cache'); const NodeCache = require('node-cache'); const provider = new NodeTracerProvider(); provider.register(); registerInstrumentations({ provider, instrumentations: [ new NodeCacheInstrumentation({ requestHook: (span, { operation, args }) => { span.setAttribute('node-cache.operation', operation); }, responseHook: (span, { operation, response }) => { if (response === undefined) { span.setAttribute('node-cache.hit', false); } }, requireParentSpan: false, }), ], }); const cache = new NodeCache(); cache.set('key', 'value'); cache.get('key'); cache.del('key'); console.log('Tracing active');
Debug
Known issues
gotcharequireParentSpan option defaults to false, which means all operations are traced. If you set it to true, operations without a parent span will be skipped.
fix
Set requireParentSpan: true only if you want to filter out top-level operations.
affects: >=0.1.0
gotchaThe responseHook callback receives the operation name and response, but for some operations (e.g., del, keys) the response may be primitives. Check type before accessing properties.
fix
Use typeof or type guards when accessing response attributes in hooks.
affects: >=0.1.0
deprecatedOlder versions of this instrumentation (pre-0.30.0) used a different configuration object shape (e.g., 'tracerProvider' instead of 'provider').
fix
Update to v0.30+ and use registerInstrumentations with 'provider' option.
affects: <0.30.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'startSpan')
@opentelemetry/api not registered or global tracer provider missing.
fix
Ensure a TracerProvider is registered and provider.register() is called before creating instrumentation.
Error: @opentelemetry/api: No loaded instrumentation for module node-cache
node-cache imported before instrumentation was registered.
fix
Call registerInstrumentations before requiring node-cache, or lazy-load node-cache after setup.
Module not found: Can't resolve 'opentelemetry-instrumentation-node-cache'
Package not installed or incorrect import path in bundler setup.
fix
Run npm install opentelemetry-instrumentation-node-cache. For bundler, add it to externals or disable node-globals.
Upgrade
Version history
0.41.0latest on npm
Audit
Dependencies
@opentelemetry/apirequiredPeer dependency required for OpenTelemetry API types and globals
Agent activity
2 hits · last 30 days
node
2
Resources
opentelemetry-instrumentation-node-cache — npm install opentelemetry-instrumentation-node-cache · libregistry