redis/node-redis · error · OpenTelemetryError
@opentelemetry/api not found
Error message
@opentelemetry/api not found
What it means
OpenTelemetry.init() requires the @opentelemetry/api package; it attempts require('@opentelemetry/api') and throws OpenTelemetryError if the require fails. The metrics instrumentation depends on the OpenTelemetry API to obtain a meter and register instruments, so without it initialization cannot proceed.
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 bb5beb5657)
Solutions
- Install the dependency: npm install @opentelemetry/api (and @opentelemetry/sdk-metrics for a MeterProvider).
- Verify the package resolves from the same node_modules tree as the redis import.
- If you did not mean to enable metrics, remove the OpenTelemetry.init call.
- For bundlers, ensure @opentelemetry/api is not marked external-only without being installed.
Example fix
// before
OpenTelemetry.init({ metrics: { enabled: true } }); // throws, api missing
// after
// npm install @opentelemetry/api @opentelemetry/sdk-metrics
import { metrics } from '@opentelemetry/api';
OpenTelemetry.init({ metrics: { enabled: true } }); Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'node:module';
// Pre-check resolution:
try { require.resolve('@opentelemetry/api'); } catch { throw new Error('install @opentelemetry/api first'); } Try / catch
try { OpenTelemetry.init(config); } catch (e) { if (/@opentelemetry\/api not found/.test(e.message)) { console.error('Run: npm install @opentelemetry/api'); } throw e; } Prevention
- Add @opentelemetry/api (and sdk-metrics) to dependencies before enabling metrics.
- Verify the package resolves from the redis import's node_modules tree.
- In bundlers, do not externalize without installing.
When it happens
Trigger: Calling OpenTelemetry.init({...}) in a project that has not installed @opentelemetry/api (and optionally @opentelemetry/sdk-metrics). The dependency is a peer/optional and is not bundled with redis.
Common situations: Enabling the new metrics config without adding the OTel dependencies to package.json; monorepo where the package with init() call lacks the dependency; tree-shaking/externalization that drops @opentelemetry/api from the bundle.
Related errors
AI-assisted analysis of redis/node-redis@bb5beb5657 (2026-08-03).
Data as JSON: /data/errors/66e59217ca42735d.json.
Report an issue: GitHub.