{"id":45702,"library":"opentelemetry-instrumentation-node-cache","title":"OpenTelemetry node-cache Instrumentation","description":"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.","status":"active","version":"0.41.0","language":"javascript","source_language":"en","source_url":"https://github.com/aspecto-io/opentelemetry-ext-js","tags":["javascript","node-cache","opentelemetry","typescript"],"install":[{"cmd":"npm install opentelemetry-instrumentation-node-cache","lang":"bash","label":"npm"},{"cmd":"yarn add opentelemetry-instrumentation-node-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add opentelemetry-instrumentation-node-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for OpenTelemetry API types and globals","package":"@opentelemetry/api","optional":false}],"imports":[{"note":"CommonJS require is still supported. Named export only, no default export.","wrong":"const NodeCacheInstrumentation = require('opentelemetry-instrumentation-node-cache').NodeCacheInstrumentation","symbol":"NodeCacheInstrumentation","correct":"import { NodeCacheInstrumentation } from 'opentelemetry-instrumentation-node-cache'"},{"note":"Config type is a TypeScript type, use type import to avoid runtime import.","wrong":"import { NodeCacheInstrumentationConfig } from 'opentelemetry-instrumentation-node-cache'","symbol":"NodeCacheInstrumentationConfig","correct":"import type { NodeCacheInstrumentationConfig } from 'opentelemetry-instrumentation-node-cache'"},{"note":"Module does not export a default export. Use named import instead.","wrong":"import { default as NodeCacheInstrumentation } from 'opentelemetry-instrumentation-node-cache'","symbol":"default","correct":"import NodeCacheInstrumentation from 'opentelemetry-instrumentation-node-cache'"}],"quickstart":{"code":"const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');\nconst { registerInstrumentations } = require('@opentelemetry/instrumentation');\nconst { NodeCacheInstrumentation } = require('opentelemetry-instrumentation-node-cache');\nconst NodeCache = require('node-cache');\n\nconst provider = new NodeTracerProvider();\nprovider.register();\n\nregisterInstrumentations({\n  provider,\n  instrumentations: [\n    new NodeCacheInstrumentation({\n      requestHook: (span, { operation, args }) => {\n        span.setAttribute('node-cache.operation', operation);\n      },\n      responseHook: (span, { operation, response }) => {\n        if (response === undefined) {\n          span.setAttribute('node-cache.hit', false);\n        }\n      },\n      requireParentSpan: false,\n    }),\n  ],\n});\n\nconst cache = new NodeCache();\ncache.set('key', 'value');\ncache.get('key');\ncache.del('key');\nconsole.log('Tracing active');","lang":"javascript","description":"Setup OpenTelemetry tracing for node-cache with custom hooks and example operations."},"warnings":[{"fix":"Set requireParentSpan: true only if you want to filter out top-level operations.","message":"requireParentSpan option defaults to false, which means all operations are traced. If you set it to true, operations without a parent span will be skipped.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use typeof or type guards when accessing response attributes in hooks.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Update to v0.30+ and use registerInstrumentations with 'provider' option.","message":"Older versions of this instrumentation (pre-0.30.0) used a different configuration object shape (e.g., 'tracerProvider' instead of 'provider').","severity":"deprecated","affected_versions":"<0.30.0"}],"env_vars":null,"search_vec":"'0.41.0':16 '1.8.0':49 '5.0.0':14 'ad':44 'aspecto':52 'attribut':46 'automat':6 'cach':4,12,24,56 'close':35 'configur':38 'current':18 'custom':45 'del':29 'develop':50 'flushal':36 'get':27 'instrument':5,8 'javascript':53 'key':32 'like':26 'mget':30 'mset':31 'node':3,11,23,55 'node-cach':2,10,22,54 'opentelemetri':1,7,57 'opentelemetry/api':48 'oper':25 'provid':19 'requesthook':40 'requir':47 'responsehook':42 'set':28 'stat':37 'trace':20 'ttl':33 'typescript':58 'version':13,15 'via':39","created_at":"2026-06-07T12:56:18.915839+00:00","updated_at":"2026-06-07T12:56:18.915839+00:00","problems":[{"fix":"Ensure a TracerProvider is registered and provider.register() is called before creating instrumentation.","cause":"@opentelemetry/api not registered or global tracer provider missing.","error":"TypeError: Cannot read properties of undefined (reading 'startSpan')"},{"fix":"Call registerInstrumentations before requiring node-cache, or lazy-load node-cache after setup.","cause":"node-cache imported before instrumentation was registered.","error":"Error: @opentelemetry/api: No loaded instrumentation for module node-cache"},{"fix":"Run npm install opentelemetry-instrumentation-node-cache. For bundler, add it to externals or disable node-globals.","cause":"Package not installed or incorrect import path in bundler setup.","error":"Module not found: Can't resolve 'opentelemetry-instrumentation-node-cache'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/aspecto-io/opentelemetry-ext-js","github":"https://github.com/aspecto-io/opentelemetry-ext-js","docs":null,"changelog":null,"pypi":null,"npm":"opentelemetry-instrumentation-node-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}