experimental
openTelemetry 4.0.10+
- Type:
interface OpenTelemetryOptions {
enabled: boolean
/**
* A path to a file that exposes an OpenTelemetry SDK.
*/
sdkPath?: string
}- Default:
{ enabled: false }
This option controls OpenTelemetry support. Vitest imports the SDK file in the main thread and before every test file, if enabled is set to true.
PERFORMANCE CONCERNS
OpenTelemetry may significantly impact Vitest performance; enable it only for local debugging.
You can use a custom service together with Vitest to pinpoint which tests or files are slowing down your test suite.
BROWSER SUPPORT
At the moment, Vitest does not start any spans when running in the browser.
An sdkPath is resolved relative to the root of the project and should point to a module that exposes a started SDK instance as a default export. For example:
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
import { NodeSDK } from '@opentelemetry/sdk-node'
const sdk = new NodeSDK({
serviceName: 'vitest',
traceExporter: new OTLPTraceExporter(),
instrumentations: [getNodeAutoInstrumentations()],
})
sdk.start()
export default sdkimport { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
experimental: {
openTelemetry: {
enabled: true,
sdkPath: './otel.js',
},
},
},
})WARNING
It's important that Node can process sdkPath content because it is not transformed by Vitest. See the guide on how to work with OpenTelemetry inside of Vitest.