API reference
@fixback/node reference
@fixback/node. For a narrative walkthrough, see the Backend errors guide.Exports
import { init, captureException, captureMessage, setUser, setTag, mintHostIdentity,} from "@fixback/node";// framework adapters (optional, subpath imports):import { fixbackRequestContext, fixbackErrorHandler } from "@fixback/node/express";import { FixbackModule } from "@fixback/node/nestjs";init(options)
Call once, as early in the process as possible.
| Option | Type | Description |
|---|---|---|
secretKey | string | Required. A secret key (sk_…) of the environment this server runs as — its errors land in that environment, so there is no environment option. Server-side only. |
release | string | The build identifier, symbolicated against sourcemaps uploaded for the same release. Falls back to FIXBACK_RELEASE. |
serviceName | string | Which service this process is (checkout-api), shown on every Issue it files so several services in one environment can be told apart. Falls back to FIXBACK_SERVICE_NAME. Up to 128 characters on one line; an unusable one is ignored with a warning. |
enabled | boolean | Gate capture on or off — e.g. process.env.NODE_ENV === "production" to stay quiet in local dev. |
beforeSend | (event) => event | null | Redact fields, or drop an event entirely by returning null. |
scrub | boolean | Run the built-in PII scrubbers before beforeSend. Defaults to true. |
apiUrl | string | The Fixback API origin. Override for a self-hosted deployment. Falls back to FIXBACK_API_URL, then https://api.fixback.dev. |
autoCapture | boolean | The umbrella for the two process handlers below. Defaults to true; false installs neither. |
captureUncaughtException | boolean | Install the uncaughtException handler, which captures, then exits 1 as Node would unless your app has its own handler. Defaults to autoCapture. |
captureUnhandledRejection | boolean | Install the unhandledRejection handler, which captures, then does what your --unhandled-rejections mode says unless your app has its own handler (details). Defaults to autoCapture. |
requestIdHeader | string | The header a request's Correlation id is read from when it carries no traceparent. Defaults to x-request-id. |
captureClientErrors | boolean | number[] | Whether the Express and NestJS adapters file a request answered with a 4xx, such as a bot's 404, an expired session's 401 or a validation 400. Defaults to false, so only 5xx and errors with no HTTP status are filed. true files every 4xx; a list files only those statuses, e.g. [403, 409]. A manual captureException is always filed. |
captureBodies | boolean | Attach the failing request's body (the parsed req.body) and the response it sent (via res.json / res.send) to its errors, so the server Issue's request row shows the payload that failed and the response that explains it. Defaults to false — an opt-in, useful for debugging on staging. The built-in scrubbers redact PII from bodies before they leave the process, and Fixback redacts them again on arrival. |
maxBodyBytes | number | The per-body cap, in bytes, under captureBodies: a bigger body is dropped whole, never cut short. Defaults to 16384; at most 65536. An error whose bodies would make it too large to send in one request is sent without them. |
maxBreadcrumbs | number | The most breadcrumbs one error carries — the newest of its request's console lines and outgoing calls. Defaults to 50; at most 100; 0 records none. |
capture | { console?, network? } | Which breadcrumbs are recorded: console calls (level and message), and network — outgoing http/https/fetch requests (method, URL without its query string, status, duration, outcome). Both default to true. |
beforeBreadcrumb | (crumb) => crumb | null | See each breadcrumb as it is recorded: edit it, or drop it by returning null. A hook that throws keeps the breadcrumb. |
debug | boolean | Say on standard error what the SDK is doing: why it is inert, what every send answered, what is retried or given up. Defaults to false. A refused secret key (401) or a suspended workspace (403) is said once either way. |
Set the two per-signal flags to override the umbrella individually — e.g. { autoCapture: false, captureUnhandledRejection: true } installs only the
rejection handler. An explicit release or apiUrl wins over its
environment variable.
Transport tuning
Sensible by default; reach for these only when your traffic shape asks for it.
| Option | Default | Description |
|---|---|---|
maxBatchSize | 100 | Flush once the buffer reaches this many errors. Capped at the server's limit of 500. A flush too large for the API's request size limit goes out in several requests. |
flushIntervalMs | 5000 | Flush a non-empty buffer at least this often. |
maxQueueSize | 1024 | The most distinct errors held in memory — while Fixback is unreachable or asks the SDK to wait, too. A repeat of a held error folds into it; a new one past the bound drops the oldest. |
timeoutMs | 30000 | Per-request transport timeout; 0 disables it. A request that times out is retried. |
The single init call also wires a batched secret-key transport that keeps an error until Fixback has filed it — retrying a failed send, honouring Retry-After, and flushing on beforeExit, SIGTERM and SIGINT without changing how the process ends (see Delivery) — and process-level uncaughtException / unhandledRejection capture that leaves your process to do what Node would — see Crashes and unhandled rejections. Each error carries the instant it was captured, so a batch flushed seconds later still records when every error happened. Every batch also says which process sent it: the SDK's name and version, the serviceName, and the host name, Node.js version and OS, read once at init.
Capture functions
| Function | Description |
|---|---|
captureException(err, context?) | Report a handled error (handled: true). context.fingerprint (string[]) groups it your own way, "{{ default }}" standing for the fingerprint the SDK computed — see Grouping. |
captureMessage(message, level?, context?) | Report a message string with a level — fatal, error, warning, info (the default) or debug — shown on the Issue, grouped by its text with every number collapsed, or by context.fingerprint. |
setUser(ref) | Attach an app-supplied, opaque user reference (up to 256 characters) to the errors captured in the current request — or, outside a request, to every error, as the process-wide user. null clears it. |
setTag(key, value) | Set a tag on the current request — or process-wide outside one; a request's value wins. A key is up to 32 letters, digits, _, ., : or -; a value a string, number or boolean up to 200 characters on one line; at most 50 per error. null removes it. |
flush(timeoutMs?) | Send what is buffered now — through a retry wait, never through a Retry-After. With timeoutMs, resolves within it, and what is still in flight stays buffered. A serverless handler awaits it before returning. |
close() | Remove the SDK's process listeners and send what is buffered, once. Await it in your own SIGTERM handler before you exit. |
mintHostIdentity(options)
A Host identity is the escape hatch for a product that already knows who its
users are: your server mints a short-lived token from one of an environment's secret keys and
hands it to a capture SDK (web or Expo) as its hostIdentity. Fixback verifies it and
tiers the Reporter — Internal when the token's email is an Org
Member, otherwise Invited — with no Connect round trip. A verified Host identity
whose email matches a Fixback Account resolves to that same person, so the host and the platform
are one Reporter.
It verifies only against the secret keys of the environment whose publishable key that capture SDK presents, so sign it with a key of the same environment — a staging server's secret mints nothing production accepts.
import { mintHostIdentity } from "@fixback/node";// On your server, for a user you already authenticated:const hostIdentity = mintHostIdentity({ secretKey: process.env.FIXBACK_SECRET_KEY!, // sk_… — never ship it to a client subject: user.id, // your stable id for the user (JWT sub) email: user.email, // optional — Member ⇒ internal tier expiresInSeconds: 3600, // optional — defaults to one hour});// Hand it to a capture SDK as its hostIdentity option:// web: Fixback.init({ key: "pk_…", hostIdentity })// expo: <FixbackProvider options={{ key, origin, hostIdentity }} />| Option | Type | Description |
|---|---|---|
secretKey | string | Required. A secret key (sk_…) of the same environment as the capture SDK's publishable key, issued in the dashboard. Signs the token; keep it server-side. |
subject | string | Required. Your stable identifier for the user — the JWT sub, which keys the Reporter. |
email | string | The user's email. Decides internal vs invited, and unifies the Reporter with a matching Account. Omit for a valid-but-external identity (invited). |
expiresInSeconds | number | Token lifetime; defaults to one hour. An exp is always set — an identity assertion must expire. |
The token is an HS256 JWT signed with sha256(secretKey). This helper
builds it for you, so you never hand-roll JWT signing. Issue and revoke
secret keys on the Project's Keys page, for the environment picked in the
switcher; a revoked key stops
verifying at once.
Express adapter — @fixback/node/express
| Middleware | Where | Description |
|---|---|---|
fixbackRequestContext() | before your routes | Opens per-request context so captures carry request metadata. |
fixbackErrorHandler() | after your routes | Captures errors that reach next(err). One answered with a 4xx is skipped unless captureClientErrors asks for it. |
Errors carry the route's full pattern, a mounted router's prefix included
(/orgs/:org/posts/:postId), on Express 4 and 5. When a mount's pattern can't be
worked out for certain, the route is left out rather than sent with a concrete value — see Express.
NestJS adapter — @fixback/node/nestjs
| Export | Description |
|---|---|
FixbackModule.forRoot() | Registers the request-context middleware and a global exception filter. The filter captures every exception (a 4xx HttpException only under captureClientErrors), then hands it to Nest's own handling for its context: the usual HTTP response, or the default for a microservice (RPC) or GraphQL call. Your own error handling is unchanged. |
FixbackExceptionFilter | The filter itself. Global filters don't reach WebSocket gateways, so apply it to a gateway with @UseFilters(FixbackExceptionFilter). The client still gets Nest's usual exception event. |
The Correlation id
The request-context middleware (either adapter) gives every request one id, and errors captured during the request carry it. It takes the first source that has one:
- the trace id of an inbound W3C
traceparentheader — what the browser SDK sends on your page's same-origin requests and to the origins listed in itspropagateTo, and what the Expo SDK sends to the origins listed in its own; - the
requestIdHeader—x-request-idunless you configured another; - a freshly minted id.
A malformed traceparent is ignored whole, never partly used, and the next source
applies. When the page's request carried the id, the server Issue's request row and the browser
Issue's network row show the same Correlation id, and the server Issue lists the page Issues it
was seen from — with their replay — while each of those names it as the server
error behind its request. Both capture SDKs send the sampled flag
(01) by default, so a parent-based OpenTelemetry sampler on this server records
those requests rather than dropping them; the browser SDK's traceparentSampled: false sends 00 instead. The id, and so the link, is the same either way — this SDK reads the
id, never the flag.