Skip to Content
OpenPerf

Platforms

Node.js & Bun

Trace requests, collect logs and report errors from a Node.js or Bun service.

Node.js (24.11.1+) and Bun share the same entry point, @openperf/sdk/node. It builds on OpenTelemetry and sets up tracing, log collection and error reporting in one call.

Install the SDK

npm i @openperf/sdk

Create the instrument file

Put init in its own file so it runs before your app imports any libraries:

instrument.mjs
import { init } from "@openperf/sdk/node";

init({
  dsn: process.env.OPENPERF_DSN,
  environment: process.env.NODE_ENV,
  release: process.env.APP_RELEASE,
});

Without a dsn and without the OPENPERF_DSN variable, init does nothing, so the same file is safe to load locally. Copy the DSN from Settings → Projects → Connection.

Preload it before your app

Start with --import (ESM):

node --import ./instrument.mjs app.mjs

For CommonJS, name the file instrument.cjs, load the SDK with require("@openperf/sdk/node") and use --require:

node --require ./instrument.cjs app.cjs

A library loaded before init is not traced.

See the first trace

Send a request to your app and open Traces in the dashboard. After a few seconds the request appears under its method and route, such as GET /users/:id.

What the SDK collects

DataDetails
RequestsIncoming HTTP requests (Bun.serve, Express, Fastify, Koa, hapi, Restify, Connect, NestJS, GraphQL, gRPC, Socket.IO).
Outgoing HTTPfetch, node:http and node:https calls, each carrying a traceparent header.
Databases and cachesPostgreSQL (pg), MySQL (mysql, mysql2), MongoDB (mongodb, mongoose), Redis (redis, ioredis), Memcached, Cassandra, Oracle Database, SQL Server (tedious) and Knex.
QueuesRabbitMQ (amqplib) and Kafka (kafkajs).
Cloud and AIAWS SDK, AWS Lambda and OpenAI.
LogsRecords written with pino or bunyan, linked to the active trace. For winston, also install @opentelemetry/winston-transport.
ErrorsUncaught exceptions, unhandled promise rejections and framework request errors.

The default set is the OpenTelemetry Node.js auto-instrumentations plus Fastify (without fs, dns, net, router, host metrics or runtime metrics). Pass extra ones in instrumentations.

Bun specifics

  • Bun.serve & streams: routes handlers produce traces named by method and route (GET /users/:id); text/event-stream spans stay open until the stream ends or the client disconnects. Static Response routes are not traced.
  • Hot reload: bun --hot is supported without duplicating spans.
  • Library instrumentation: Because Bun has no ESM loader hooks, init preloads supported libraries listed in package.json (dependencies / devDependencies). Libraries not listed in package.json (or in bundled apps without node_modules) are not auto-instrumented.

Crashes and shutdown

Queued telemetry flushes on normal exit, SIGTERM, SIGINT and crashes (up to a 2-second wait). If your app calls process.exit() directly or runs in a serverless handler, await flush() first:

import { flush } from "@openperf/sdk/node";

await flush();
process.exit(0);

Apps that already use OpenTelemetry

If another SDK already registered OpenTelemetry, init prints a warning and stays off. Call OpenPerf's init first, or export directly over OpenTelemetry.

Next steps

On this page