npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

autotel-vitest

v0.3.1

Published

Vitest fixture for OpenTelemetry: one span per test so all instrumented code is filterable by test run

Downloads

396

Readme

autotel-vitest

autotel-vitest gives each Vitest test a parent OpenTelemetry span, so all autotel instrumented calls made during that test become child spans.

How test and server appear as one trace

When you test an API over HTTP, the test runs in the Vitest worker process and the server runs in another process. Use injectTraceContext() from autotel/http so the request carries a traceparent header. Your server uses extractTraceContext() and creates its spans in that context, so the same trace ID is used on both sides. In your OTLP backend, look up the test’s trace ID to see the full trace: test span and all server spans (HTTP, handlers, db.userId, etc.). When you test in-process (no HTTP), all code runs in the same process and the fixture’s context automatically links test and handler spans in one trace.

sequenceDiagram
  participant Test as Test process
  participant Server as Server process
  participant OTLP as OTLP backend

  Note over Test: One span per test (trace ID = X)
  Test->>Server: fetch() with traceparent (injectTraceContext)
  Note over Server: extractTraceContext()<br/>HTTP span + child spans
  Test->>OTLP: Export spans (trace X)
  Server->>OTLP: Export spans (trace X)
  Note over OTLP: One trace = test + API

Install

Install autotel-vitest, autotel, and vitest:

# pnpm
pnpm add -D vitest
pnpm add autotel autotel-vitest

# npm
npm install --save-dev vitest
npm install autotel autotel-vitest

# yarn
yarn add --dev vitest
yarn add autotel autotel-vitest

Quick Start

1. Initialize autotel in globalSetup

// globalSetup.ts
import { init } from 'autotel';

export default function globalSetup() {
  init({ service: 'unit-tests' });
}

2. Register globalSetup in Vitest config

// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    globalSetup: './globalSetup.ts',
  },
});

3. Import test from autotel-vitest

import { test, expect } from 'autotel-vitest';

test('creates user', async () => {
  await userService.createUser({ email: '[email protected]' });
  expect(true).toBe(true);
});

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

What You Get

  • One span per test named test:${task.name}
  • Span attributes: test.name, test.file, test.suite
  • If a test throws, the span is marked as error and records the exception
  • Any trace() / span() calls in the test flow become children of the active test span

Optional: Reporter (runner-side spans)

Use the reporter when you also want runner-process spans for test/suite timing:

// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    globalSetup: './globalSetup.ts',
    reporters: ['default', 'autotel-vitest/reporter'],
  },
});

Reporter spans:

  • test span: test:${name}
  • suite span: suite:${name}

Testing Utilities

autotel-vitest re-exports helpers from autotel/testing:

  • createTraceCollector
  • assertTraceCreated
  • assertTraceSucceeded
  • assertTraceFailed
  • assertNoErrors
  • assertTraceDuration
  • waitForTrace
  • getTraceDuration
  • createMockLogger

Example:

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

test('traces user creation', async () => {
  const collector = createTraceCollector();
  await userService.createUser({ email: '[email protected]' });
  assertTraceCreated(collector, 'user.createUser');
});

Troubleshooting

  • No spans exported: verify init() runs in globalSetup before tests start.
  • No child spans under test span: ensure your test imports test from autotel-vitest, not vitest.
  • Reporter not running: ensure reporters includes 'autotel-vitest/reporter'.

API

  • test: extended Vitest test with auto per-test span fixture
  • expect, describe, beforeEach, afterEach, beforeAll, afterAll: re-exported from vitest
  • autotel/testing helpers listed above: re-exported from this package