diff --git a/packages/vitest/src/utils/traces.ts b/packages/vitest/src/utils/traces.ts index c3cc2946cec3..fb301fd102dc 100644 --- a/packages/vitest/src/utils/traces.ts +++ b/packages/vitest/src/utils/traces.ts @@ -51,7 +51,11 @@ export class Traces { constructor(options: TracesOptions) { if (options.enabled) { - const apiInit = import('@opentelemetry/api').then((api) => { + // @ts-expect-error injected global + const id = typeof __vitest_browser__ === 'undefined' + ? '@opentelemetry/api' + : '/@id/@opentelemetry/api' + const apiInit = import(/* @vite-ignore */ id).then((api) => { const otel = { tracer: api.trace.getTracer(options.tracerName || 'vitest'), context: api.context,