{"record":{"id":"66e59217ca42735d","repo":"redis/node-redis","slug":"opentelemetry-api-not-found","errorCode":null,"errorMessage":"@opentelemetry/api not found","messagePattern":"@opentelemetry/api not found","errorType":"exception","errorClass":"OpenTelemetryError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/opentelemetry/index.ts","lineNumber":64,"sourceCode":"   *   metrics: {\n   *     enabled: true,\n   *     enabledMetricGroups: [\"pubsub\", \"connection-basic\", \"resiliency\"],\n   *     includeCommands: [\"GET\", \"SET\"],\n   *     hidePubSubChannelNames: true\n   *   }\n   * });\n   * ```\n   */\n  public static init(config: ObservabilityConfig) {\n    if (OpenTelemetry._instance) {\n      throw new OpenTelemetryError(\"OpenTelemetry already initialized\");\n    }\n\n    const api: OpenTelemetryApiModule = (() => {\n      try {\n        return require(\"@opentelemetry/api\");\n      } catch {\n        throw new OpenTelemetryError(\"@opentelemetry/api not found\");\n      }\n    })();\n\n    OpenTelemetry._instance = new OpenTelemetry();\n    ClientRegistry.init();\n    OTelMetrics.init({ api, config });\n  }\n}\n\nexport {\n  OTelClientAttributes,\n  OTEL_ATTRIBUTES,\n  CONNECTION_CLOSE_REASON,\n  CSC_RESULT,\n  CSC_EVICTION_REASON,\n} from \"./types\";\nexport { OTelMetrics } from \"./metrics\";\nexport {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/redis/node-redis/blob/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/packages/client/lib/opentelemetry/index.ts#L46-L82","documentation":"OpenTelemetry.init() tried to require('@opentelemetry/api') and it threw — the peer dependency is not installed or not resolvable from the current working directory. The OTel integration needs this package to access the global MeterProvider and trace APIs.","triggerScenarios":"Calling OpenTelemetry.init() without @opentelemetry/api in node_modules, or in a monorepo workspace where the package is hoisted to a different location.","commonSituations":"Forgot to install the peer dependency; package was hoisted in a monorepo and not resolvable from the calling workspace; tree-shaking or bundler configuration removed it; npm install with --omit=optional or --production excluding it.","solutions":["Install the peer dependency: npm install @opentelemetry/api","In monorepos, install @opentelemetry/api in the specific workspace that calls init","Verify resolution: node -e \"require.resolve('@opentelemetry/api')\" from the calling directory","Check package.json includes @opentelemetry/api in dependencies or peerDependencies"],"exampleFix":"# before\n# (missing dependency)\nOpenTelemetry.init(config); // throws\n\n# after\nnpm install @opentelemetry/api\nOpenTelemetry.init(config);","handlingStrategy":"validation","validationCode":"// Verify @opentelemetry/api is resolvable before calling init.\ntry {\n  require.resolve('@opentelemetry/api');\n} catch {\n  throw new Error('@opentelemetry/api must be installed: npm install @opentelemetry/api');\n}\n\nOpenTelemetry.init(config);","typeGuard":null,"tryCatchPattern":"try {\n  OpenTelemetry.init(config);\n} catch (e) {\n  if (e instanceof OpenTelemetryError && e.message.includes('not found')) {\n    console.error('Install the peer dependency: npm install @opentelemetry/api');\n  }\n  throw e;\n}","preventionTips":["Add @opentelemetry/api to package.json dependencies explicitly","In monorepos, install it in the workspace that calls init, not just the root","Verify with node -e \"require.resolve('@opentelemetry/api')\" after install","Do not use --omit=optional or --production flags that might exclude peer dependencies"],"tags":["opentelemetry","dependencies","initialization"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}