Skip to content

Configuration ​

Everything is set when the Flare is constructed, and durations are in milliseconds everywhere.

ts
import { Flare, isSensitiveKey } from "@priemskiyyy/flare";
import { console } from "@priemskiyyy/flare-console";
import { http } from "@priemskiyyy/flare-http";

const flare = new Flare({
  destinations: {
    backend: http({ request: sendReport }),
    console: console(),
  },
  defaults: { to: ["backend"] },
  privacy: { redact: (key) => isSensitiveKey(key) || key === "iban" },
  timeout: 3_000,
  rateLimits: { perMinute: 60 },
});
OptionDefaultMeaning
destinationsrequiredNamed adapters. The names are typed everywhere.
schemanoneStandard Schema validators for tags, contexts and breadcrumbs. See metadata.
defaults.toevery destinationWhere a report goes: a list of names, or a function of { report } that returns one. A report's own to replaces it. See routing.
defaults.tags, defaults.contextsnoneTags and contexts every report carries, across account changes. A report's own are merged over them.
privacy.redactisSensitiveKeyDecides which values are replaced with [Redacted]. See privacy.
privacy.scrubnoneRewrites free text.
privacy.limitssee boundsBounds on every report's size.
buffer.capacity30Reports each destination holds until it is ready.
buffer.maxAge60000How long a report may wait there.
timeout5000How long a destination may take before its outcome is indeterminate.
dedupe.window1000How long the same thrown object counts as a repeat. 0 turns this check off.
rateLimits.perMinute120Reports admitted per minute. The rest are dropped as rate-limited.
nowDate.nowThe clock, for tests. One that throws or answers no number gives way to Date.now.

flare.flush({ timeout }) waits 2000 ms unless told otherwise. See flush.

What the constructor refuses ​

A Flare that cannot work throws a FlareError with the code INVALID_CONFIGURATION from its constructor, so you find the mistake at startup. The message names the option.

  • A count that is not a whole number of 0 or more: buffer.capacity, rateLimits.perMinute and every entry of privacy.limits.
  • A duration outside 0 to 2147483647 ms, the longest delay a timer can hold: buffer.maxAge, timeout and dedupe.window.
  • A defaults.to list that names a destination you never configured.
  • A redact or scrub that is not a function.
  • defaults that fail the schema, or that redact or scrub fails on.

An option set to undefined keeps its default. flush never throws: it clamps its timeout into the same range.

Released under the MIT License.