{"id":"2981a1e4288fd27d","repo":"vitest-dev/vitest","slug":"opentelemetry-api-is-not-installed-locally-mak","errorCode":null,"errorMessage":"\"@opentelemetry/api\" is not installed locally. Make sure you have setup OpenTelemetry instrumentation: https://vitest.dev/guide/open-telemetry","messagePattern":"\"@opentelemetry/api\" is not installed locally\\. Make sure you have setup OpenTelemetry instrumentation: https://vitest\\.dev/guide/open-telemetry","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/utils/traces.ts","lineNumber":65,"sourceCode":"  #noopContext = createNoopContext()\n  #initStartTime = performance.now()\n  #initEndTime = 0\n  #initRecorded = false\n\n  constructor(options: TracesOptions) {\n    if (options.enabled) {\n      const apiInit = import('@opentelemetry/api').then((api) => {\n        const otel = {\n          tracer: api.trace.getTracer(options.tracerName || 'vitest'),\n          context: api.context,\n          propagation: api.propagation,\n          trace: api.trace,\n          SpanKind: api.SpanKind,\n          SpanStatusCode: api.SpanStatusCode,\n        }\n        this.#otel = otel\n      }).catch(() => {\n        throw new Error(`\"@opentelemetry/api\" is not installed locally. Make sure you have setup OpenTelemetry instrumentation: https://vitest.dev/guide/open-telemetry`)\n      })\n      const sdkInit = (options.sdkPath ? import(/* @vite-ignore */ options.sdkPath!) : Promise.resolve()).catch((cause) => {\n        throw new Error(`Failed to import custom OpenTelemetry SDK script (${options.sdkPath}): ${cause.message}`)\n      })\n      this.#init = Promise.all([sdkInit, apiInit]).then(([sdk]) => {\n        if (sdk != null) {\n          if (sdk.default != null && typeof sdk.default === 'object' && typeof sdk.default.shutdown === 'function') {\n            this.#sdk = sdk.default\n          }\n          else if (options.watchMode !== true && process.env.VITEST_MODE !== 'watch') {\n            console.warn(`OpenTelemetry instrumentation module (${options.sdkPath}) does not have a default export with a \"shutdown\" method. Vitest won't be able to ensure that all traces are processed in time. Try running Vitest in watch mode instead.`)\n          }\n        }\n      }).finally(() => {\n        this.#initEndTime = performance.now()\n        this.#init = null\n      })\n    }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/utils/traces.ts#L47-L83","documentation":"The Traces constructor (traces.ts:54-66) dynamically imports @opentelemetry/api when tracing is enabled; if that import rejects (package not installed), it throws this error pointing to the OpenTelemetry setup guide. OpenTelemetry tracing is opt-in and requires the user to install the API package and an SDK.","triggerScenarios":"Enabling tracing (e.g. via the --tracing flag or programmatic config with traces.enabled: true) in a project where @opentelemetry/api is not installed as a dependency. The dynamic import at line 54 rejects and the .catch rethrows this error during Traces construction/waitInit.","commonSituations":"Following the OpenTelemetry guide but forgetting `npm i @opentelemetry/api`; enabling tracing in CI without adding the dependency; the package being hoisted away in a monorepo so the worker cannot resolve it.","solutions":["Install @opentelemetry/api: `pnpm add @opentelemetry/api` (and your chosen OTel SDK + exporter).","Follow https://vitest.dev/guide/open-telemetry to wire the SDK and exporter.","If you did not mean to enable tracing, remove the --tracing flag / set traces.enabled: false."],"exampleFix":"# before: tracing enabled without the dependency\nvitest run --tracing\n\n# after: install then run\npnpm add @opentelemetry/api\nvitest run --tracing","handlingStrategy":"validation","validationCode":"import { isBuiltin } from 'node:module'\n\nasync function assertOpenTelemetryInstalled() {\n  try {\n    await import('@opentelemetry/api')\n  } catch {\n    throw new Error(\n      '@opentelemetry/api is not installed. Run `npm i @opentelemetry/api` before enabling tracing.'\n    )\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add @opentelemetry/api (and an SDK + exporter) as a real dependency before enabling --tracing.","Verify the package resolves in every workspace/worker (monorepo hoisting).","Gate tracing behind a config flag so CI does not enable it without the dependency."],"tags":["opentelemetry","tracing","missing-dependency","config"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}