Skip to content

Vitest

autotel-vitest gives each Vitest test a parent span, so all instrumented calls become child spans filterable by test.

Terminal window
npm install autotel autotel-vitest
npm install --save-dev vitest
globalSetup.ts
import { init } from 'autotel';
export default function globalSetup() {
init({ service: 'unit-tests' });
}
vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globalSetup: './globalSetup.ts',
},
});
import { test, expect } from 'autotel-vitest';
test('creates user', async () => {
await userService.createUser({ email: 'test@example.com' });
});

The fixture is auto: true, so every test gets a parent span automatically.

  • One span per test with attributes: test.name, test.file, test.suite
  • All autotel calls during the test become child spans
  • Test spans and server spans appear as one trace in your OTLP backend

Add the optional reporter for runner-level test/suite spans:

vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globalSetup: './globalSetup.ts',
reporters: [['autotel-vitest/reporter', {}]],
},
});
  • example-vitest — Vitest with per-test spans, runner reporter, and HTTP trace-context propagation to a self-contained server.

Re-exported from autotel/testing:

import {
createTraceCollector,
assertTraceCreated,
assertTraceSucceeded,
} from 'autotel-vitest';