openTelemetry 5.2.0+
- Type:
interface OpenTelemetryOptions {
enabled: boolean
/**
* A path to a file that exposes an OpenTelemetry SDK for Node.js.
*/
sdkPath?: string
/**
* A path to a file that exposes an OpenTelemetry SDK for the browser.
*/
browserSdkPath?: string
}- Default:
{ enabled: false } - CLI:
--openTelemetry,--openTelemetry.enabled
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.
For browser mode, see the Browser Mode section of the OpenTelemetry guide.
openTelemetry.enabled
- Type:
boolean - Default:
false - CLI:
--openTelemetry.enabled
Enable OpenTelemetry traces.
openTelemetry.sdkPath
- Type:
string - CLI:
--openTelemetry.sdkPath=<path>
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: {
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.
openTelemetry.browserSdkPath
- Type:
string - CLI:
--openTelemetry.browserSdkPath=<path>
A path to a module that exposes a started OpenTelemetry SDK for the browser as a default export. It is resolved relative to the root of the project. Vitest collects traces from the browser runtime only if this option is set. See the Browser Mode section of the OpenTelemetry guide for an example.