CControxity Docs
GuidesReferenceHTTP APIOpen Controxity
Reference

Node SDK

Every function in controxity for Node.js (1.132.0 of Controxity, SDK 0.25.6), what it takes and what it sends.

init(options)#

Starts reporting. Call it once, as early as you can.

OptionTypeDefaultMeaning
keystringrequiredThe place's server key (dep_…). Never in a browser.
urlstringrequiredYour Controxity's address.
versionstring""The version this server runs: 1.4.2, or a git commit. Left out: CONTROXITY_VERSION, else the controxity-release.json that controxity deploy writes (0.16.0).
everynumber60000Milliseconds between sends.
rootstringprocess.cwd()Paths in frames are made relative to it.
captureUncaughtbooleantrueReport uncaught exceptions and unhandled rejections.
sourceMapsbooleantrueUse Node's source maps, so frames name your .ts files.
heartbeatbooleantrueSend a heartbeat each minute (servers only).
breadcrumbsbooleantrueKeep the last 20 steps to send with an error, and note fetch calls among them.
captureInputbooleantrueWith an error, send the shape of its input: key names and types, never values.

Without a key or a url it says why in the log and reports nothing. It never throws.

controxity.init({
  key: process.env.CONTROXITY_KEY,
  url: process.env.CONTROXITY_URL,
  version: "1.4.2",
});

check()#

Asks Controxity whether this key works. Resolves to { ok, why }, with what's wrong in words when it isn't.

const { ok, why } = await controxity.check();
// { ok: true, why: "Connected to controxity.example.com" }

captureError(error, options?)#

Reports an error your code caught. It's added up with the same error from anywhere, and shows on Problems within a minute.

OptionTypeMeaning
wherestringWhich part of your app, in your words: "orders", "purchases.refunds".
crashbooleanIt stopped what the person was doing.
inputanyWhat the failing code was given. Only its shape is sent: {cart: {items: undefined}, coupon: string}.

Sent: the error's type, its frames, where, its code (see codeOf), whether it crashed, and the shape of input. Never its message, never a value.

try {
  await googlePlay.voided(since);
} catch (error) {
  controxity.captureError(error, { where: "purchases.refunds" });
  throw error;
}

flag(name, options?)#

A switch: is it on? It's off until someone turns it on in Controxity (the product's page → Switches), and it turns itself off when errors are plainly worse where it's on. See Switches.

OptionTypeMeaning
defaultbooleanWhat a switch Controxity was never told about gives. false unless you say.
idstringA steady id (a user's, an account's), so a switch on for a share gives each the same answer. Only a hash of it is used, on your server: nothing is sent.
if (controxity.flag("new-checkout", { id: user.id })) return newCheckout(cart);

step(name), trail()#

step(name) notes a step, so an error after it shows how the app got there. A short code, never a value. Routes, fetch calls (method, site, answer, time), event(), failing health checks and earlier errors are noted by themselves. See Steps before an error.

Each request to a server Node's http starts (Express, Fastify, NestJS, Koa…) has its own steps by itself. trail() is middleware that does the same for a server that isn't, app.use(controxity.trail()) before your routes; SDK 0.14.0 and older needed it for Express. It's harmless where it isn't needed.

controxity.step("cart.loaded");

expect(name, condition, options?)#

Says what must always be true. When condition is falsy, that's a problem in Controxity, like an error, but nothing is thrown: the app carries on. Every check is counted, held or broken, so the problem says how rare it is. Returns condition as a boolean. See Expectations.

OptionTypeMeaning
inputanyWhat the code was working on. Only its shape is sent.
wherestringAs in captureError.
controxity.expect("total-not-negative", total >= 0, { input: { cart } });

shape(value)#

What captureError sends for input: the value's key names and types, never the value. Strings are string (or "" when empty), numbers number (or NaN). A key that looks like data (an id, an email) is [key].

controxity.shape({ items: undefined, lines: [{ sku: "A-1", qty: 2 }] });
// { items: "undefined", lines: [{ sku: "string", qty: "number" }] }

codeOf(error)#

The short code captureError sends for an error, from what it carries: its own code (play-403, 23505), else http-<status> from status, statusCode, response.status or cause.status, else timeout, else the network's errno from cause.code (ENOTFOUND). "" when there's none. Controxity explains known codes: see Error codes.

controxity.codeOf(Object.assign(new Error("…"), { status: 403 }));   // "http-403"

captureClient(details)#

Passes on a crash an app sent your server, so the app needs no key. Only the type (the word before the first : of message) and the frames leave your server.

FieldMeaning
message, stackWhat the app sent.
versionThe app's version.
platformandroid, ios, huawei, windows, mac, linux or web.
componentWhich part of the product: "mobile".
whereOptional, as in captureError.
controxity.captureClient({ message, stack, version, platform: "android", component: "mobile" });

express(), fastify(app), nest(app)#

Connects a framework, so a route's error that the framework turns into a 500 is reported. A 4xx isn't. Each one carries the shape of the request's route params, query and body.

app.use(controxity.express());   // Express: after your routes
controxity.fastify(app);          // Fastify: before your routes
controxity.nest(app);             // NestJS: after NestFactory.create

nextOnRequestError(error, request, context)#

Next.js answers errors in routes, server components, server actions and middleware itself, so they aren't "uncaught". Give this to Next as onRequestError in instrumentation.ts, and start the SDK in register() for the Node.js runtime only:

It sends the request's method and its route's pattern (GET /shop/[id] render), never the address asked for, which can hold values. Before init() it does nothing.

export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") require("./controxity").init({ key: process.env.CONTROXITY_KEY, url: process.env.CONTROXITY_URL });
}
export const onRequestError = (...args) => require("./controxity").nextOnRequestError(...args);

health(code, ok, severity?, reason?)#

Something you depend on is working or failing. Shown on Today's Health panel; a failing one also under Problems.

ArgumentMeaning
codelowercase snake_case: "database", "google_play".
oktrue working, false failing.
severity"high", "medium" (default), "low".
reasonWhen failing: a code like "play-403".
controxity.health("google_play", false, "high", "play-403");
controxity.health("google_play", true);

event(name, count?)#

Counts something that happened. Shown with the product's numbers.

controxity.event("payment_failed");

clientVersion(platform, version, options?)#

A phone or browser on that version talked to your server, with no error. Lets Controxity see a fix reach people.

controxity.clientVersion("android", req.headers["x-app-version"], {
  native: req.headers["x-app-native"],
  runtime: req.headers["x-app-runtime"],
});

problems()#

Where your product's errors stand: open, fixed in which version (and where that runs), or came back. Resolves to { version, problems: […] }. See GET /api/v1/problems.

const { problems } = await controxity.problems();

problemFor(list, report)#

The problem in a problems() list that an error belongs to: pass what you gave captureClient, or the error itself. Lets your app tell a person "we know, it's fixed in 1.4.3".

const p = controxity.problemFor(problems, { message, stack, component: "mobile" });

report(details)#

What a person told you went wrong, as a bug report: { title, what, expected, steps }. Resolves to its id. This is the one call that sends text you give it.

const id = await controxity.report({ title: "Booking failed", what: text });

rollouts(), inRollout(rollout, deviceId)#

For a server that gives phones their over-the-air updates in stages. rollouts() lists { platform, version, percent, state, previous }; inRollout says whether this phone gets it, the same answer each time.

const r = (await controxity.rollouts()).find((x) => x.platform === "android");
serve(controxity.inRollout(r, installId) ? r.version : r.previous);

verifyUpdate(body, signature, secret)#

Checks that a post to your server really came from Controxity (problem updates). Pass the raw body, the X-Controxity-Signature header and your secret.

if (!controxity.verifyUpdate(rawBody, req.headers["x-controxity-signature"], secret)) return res.sendStatus(401);

flush(), shutdown()#

flush() sends what's waiting now. shutdown() sends it and says the server is stopping on purpose, so it isn't counted as an outage.

process.on("SIGTERM", async () => { await controxity.shutdown(); process.exit(0); });
Controxity 1.132.0These pages are in the repository: docs/site