Registry /
devops / opentelemetry-instrumentation-node-cache
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');
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'startSpan')
@opentelemetry/api not registered or global tracer provider missing.
fixEnsure 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.
fixCall 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.
fixRun npm install opentelemetry-instrumentation-node-cache. For bundler, add it to externals or disable node-globals.
Audit
Dependencies
@opentelemetry/apirequiredPeer dependency required for OpenTelemetry API types and globals