Reference
SDK API
Functions, options and types exported by @openperf/sdk.
@openperf/sdk ships two entry points with the same functions — only the options of init differ:
@openperf/sdk/browser— Browser (ESM)@openperf/sdk/node— Node.js 24.11.1+ and Bun (ESM and CommonJS)
The package also includes the openperf CLI — see CLI reference.
Initialization
init(options?)
Starts the SDK and registers automatic instrumentation.
import { init } from "@openperf/sdk/browser";
init({
dsn: import.meta.env.VITE_OPENPERF_DSN,
environment: "production",
release: "1.4.0",
tracesSampleRate: 0.5,
tracePropagationTargets: [location.origin, "https://api.example.com/"],
ignoreErrors: ["ResizeObserver loop", /^AbortError: /],
denyUrls: ["https://widgets.example.net/"],
beforeSend: (error) => error,
});Prop
Type
replay takes these options, see Session replay:
Prop
Type
Errors & tracing
captureException(error, context?)
Reports an error with the active user, tags and breadcrumbs.
import { captureException } from "@openperf/sdk/node";
captureException(new Error("Card declined"), {
fingerprint: "payment-declined",
handled: true,
});Prop
Type
startSpan(options, callback)
Runs a synchronous or async callback inside a span and returns its result. If the callback throws or rejects, the span is marked failed, the error is captured, and the exception is rethrown.
import { startSpan } from "@openperf/sdk/node";
const total = startSpan(
{ name: "sum order lines", op: "function", attributes: { currency: "USD" } },
(span) => {
const prices = [19.9, 5, 12.5];
span.setAttribute("lines", prices.length);
return prices.reduce((sum, price) => sum + price, 0);
},
);Prop
Type
Context
setUser, setTag and addBreadcrumb attach context to subsequent errors and spans:
- Browser: applies globally to the current page.
- Node.js & Bun: scoped to the active trace (request) when called inside one, or applied to future traces when called at startup.
setUser(user)
Attaches user identity (user.id, user.email, user.name) to later errors and spans. Pass null to clear.
import { setUser } from "@openperf/sdk/browser";
setUser({ id: "42", email: "ada@example.com", name: "Ada" });Prop
Type
setTag(key, value)
Attaches a key / value attribute to later errors and spans.
import { setTag } from "@openperf/sdk/node";
setTag("plan", "pro");addBreadcrumb(breadcrumb)
Records a step leading up to an error. The SDK keeps the last 100 breadcrumbs.
import { addBreadcrumb } from "@openperf/sdk/browser";
addBreadcrumb({
category: "auth",
message: "Signed in",
level: "info",
data: { method: "password" },
});Prop
Type
Lifecycle
flush()
Flushes all queued spans, errors and logs. Await it before process.exit() or at the end of a serverless handler.
import { flush } from "@openperf/sdk/node";
await flush();
process.exit(0);SDK_VERSION
Version string of the installed @openperf/sdk package.
import { SDK_VERSION } from "@openperf/sdk/node";Types
import type {
Breadcrumb,
BreadcrumbLevel,
CaptureContext,
CapturedError,
InitOptions as BrowserInitOptions,
Primitive,
Span,
StartSpanOptions,
TextPattern,
TracePropagationTarget,
User,
} from "@openperf/sdk/browser";
import type { InitOptions as NodeInitOptions } from "@openperf/sdk/node";