redis/node-redis · error · OpenTelemetryError
@opentelemetry/api not found
Error message
@opentelemetry/api not found
What it means
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.
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
Example fix
# before # (missing dependency) OpenTelemetry.init(config); // throws # after npm install @opentelemetry/api OpenTelemetry.init(config);
Defensive patterns
Strategy: validation
Validate before calling
// Verify @opentelemetry/api is resolvable before calling init.
try {
require.resolve('@opentelemetry/api');
} catch {
throw new Error('@opentelemetry/api must be installed: npm install @opentelemetry/api');
}
OpenTelemetry.init(config); Try / catch
try {
OpenTelemetry.init(config);
} catch (e) {
if (e instanceof OpenTelemetryError && e.message.includes('not found')) {
console.error('Install the peer dependency: npm install @opentelemetry/api');
}
throw e;
} Prevention
- 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
When it happens
Trigger: Calling OpenTelemetry.init() without @opentelemetry/api in node_modules, or in a monorepo workspace where the package is hoisted to a different location.
Common situations: 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.
Related errors
AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11).
Data as JSON: /api/errors/66e59217ca42735d.
Report an issue: GitHub.
Appendix: source
Thrown at packages/client/lib/opentelemetry/index.ts:64
* metrics: {
* enabled: true,
* enabledMetricGroups: ["pubsub", "connection-basic", "resiliency"],
* includeCommands: ["GET", "SET"],
* hidePubSubChannelNames: true
* }
* });
* ```
*/
public static init(config: ObservabilityConfig) {
if (OpenTelemetry._instance) {
throw new OpenTelemetryError("OpenTelemetry already initialized");
}
const api: OpenTelemetryApiModule = (() => {
try {
return require("@opentelemetry/api");
} catch {
throw new OpenTelemetryError("@opentelemetry/api not found");
}
})();
OpenTelemetry._instance = new OpenTelemetry();
ClientRegistry.init();
OTelMetrics.init({ api, config });
}
}
export {
OTelClientAttributes,
OTEL_ATTRIBUTES,
CONNECTION_CLOSE_REASON,
CSC_RESULT,
CSC_EVICTION_REASON,
} from "./types";
export { OTelMetrics } from "./metrics";
export {View on GitHub (pinned to 90fd0652bc)