Trapify

SDK reference

The full API surface of @trapify-tech/browser. If you just want to get started, read the Quickstart instead. A machine-readable version of this page lives at /llms.txt.

Entry points

Import
import {
  init, captureException, captureMessage,
  setUser, setTag, addBreadcrumb, close,
} from '@trapify-tech/browser';

init options

Option Type Default Description
dsn string required The 32-character hex key from project settings.
environment string null Attached to every event, e.g. production.
release string null Your app version, for release tracking.
maxBreadcrumbs number 50 How many breadcrumbs are kept in memory.
autoCapture boolean true Hook uncaught errors and unhandled rejections.
captureConsole boolean true (browser) / false (Node) Record console calls as breadcrumbs. Off by default in Node — server logs are noisy.
captureFetch boolean true Record fetch requests as breadcrumbs. Browser entry point only.
debug boolean false Log the SDK’s own failures to the console.
beforeSend function Inspect, mutate or drop each event before it is sent.
endpoint string production Override the ingest URL. For testing.

Functions

beforeSend — scrubbing data before it leaves

Trapify does no server-side scrubbing: what you send is what is stored (see Security & data handling). beforeSend is the place to strip anything you do not want to leave your process. Return the event to send it, or null to drop it.

beforeSend
init({
  dsn: process.env.TRAPIFY_DSN,
  beforeSend(event) {
    if (event.environment === 'development') return null;  // drop entirely
    delete event.user?.email;                              // or scrub and send
    return event;
  },
});

Node.js

Node
import { init, withTrapify, errorHandler, flush } from '@trapify-tech/browser/node';

init({
  dsn: process.env.TRAPIFY_DSN,
  environment: 'production',
  captureConsole: false, // default false in Node — server logs are noisy
});

withTrapify(handler) wraps an async handler — Cloud Functions, route handlers — capturing unexpected errors and re-throwing them. Deliberate control-flow throws such as Firebase HttpsError pass through uncaptured. errorHandler is the Express-style middleware equivalent. In short-lived environments call flush() before the process exits, or in-flight events are lost.

Multiple projects in one process

The module-level functions wrap a single default client. To send to more than one project, construct clients directly with new TrapifyClient(options) — or new TrapifyNodeClient(options) from the Node entry point — and call the same methods on each instance. Pass autoCapture: false on all but one, or every uncaught error is reported several times.