---
url: /config/opentelemetry.md
---

# openTelemetry 5.2.0 {#opentelemetry}

* **Type:**

```ts
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](https://opentelemetry.io/) support. Vitest imports the SDK file in the main thread and before every test file, if `enabled` is set to `true`.

::: danger PERFORMANCE CONCERNS
OpenTelemetry may significantly impact Vitest performance; enable it only for local debugging.
:::

You can use a [custom service](/guide/open-telemetry) together with Vitest to pinpoint which tests or files are slowing down your test suite.

For browser mode, see the [Browser Mode](/guide/open-telemetry#browser-mode) section of the OpenTelemetry guide.

## openTelemetry.enabled {#opentelemetry-enabled}

* **Type:** `boolean`
* **Default:** `false`
* **CLI:** `--openTelemetry.enabled`

Enable OpenTelemetry traces.

## openTelemetry.sdkPath {#opentelemetry-sdkpath}

* **Type:** `string`
* **CLI:** `--openTelemetry.sdkPath=<path>`

An `sdkPath` is resolved relative to the [`root`](/config/root) of the project and should point to a module that exposes a started SDK instance as a default export. For example:

::: code-group

```js [otel.js]
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 sdk
```

```js [vitest.config.js]
import { 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](/guide/open-telemetry) on how to work with OpenTelemetry inside of Vitest.
:::

## openTelemetry.browserSdkPath {#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`](/config/root) of the project. Vitest collects traces from the browser runtime only if this option is set. See the [Browser Mode](/guide/open-telemetry#browser-mode) section of the OpenTelemetry guide for an example.
