@athenox/talos
Version:
Talos: a backend you describe instead of write. Declare a schema, write the rules in plain language, map URLs to sentences; a small built-in model turns them into query plans.
87 lines (86 loc) • 3.7 kB
TypeScript
/**
* What a Talos instance reports, so that someone who comes with its id can be
* helped: how it is configured, what it was asked, what it did, how fast, and
* what broke right after it answered.
*
* On by default, every part can be turned off on its own:
*
* defineApp({ ..., telemetry: { prompts: false } }) // all but the prompts
* defineApp({ ..., telemetry: false }) // nothing at all
*
* TALOS_TELEMETRY=0 (or DO_NOT_TRACK=1) turns it off for the whole process,
* whatever the code says. Nothing the app's users typed leaves the process as
* is: words outside the model's vocabulary and the app's own words become
* `<w>`, numbers `#`, and values in plans `<v>` — see `anonymise`.
*/
export type TelemetryOptions = {
/** Runtime errors and exceptions in the seconds after Talos answered. */
errors?: boolean;
/** The plans Talos made and ran (op, table, columns, status — no values). */
operations?: boolean;
/** The app's prompt and the sentences it was asked, anonymised. */
prompts?: boolean;
/** Latency of each call, and the load of Talos and of the whole process. */
performance?: boolean;
/** Talos and model versions, runtime settings, Node and platform. */
config?: boolean;
/** The data schema: tables, columns, declared values, relations, functions. */
schema?: boolean;
/** How long after an answer an error still counts as following it. Default 5000 ms. */
errorWindowMs?: number;
/** How often the load is sampled. Default 60000 ms. */
loadEveryMs?: number;
};
/**
* Where every instance reports (`POST { events: [...] }`, see collector/server.ts).
* Fixed: an app decides what is sent, never where — that is what makes an
* instance id something the Talos team can look up.
*/
export declare const ENDPOINT = "https://stats.talos.korollr.com/v1/events";
declare const PARTS: readonly ['errors', 'operations', 'prompts', 'performance', 'config', 'schema'];
type Part = typeof PARTS[number];
type Event = Record<string, unknown> & {
type: string;
};
export declare class Telemetry {
readonly instanceId: string;
readonly endpoint = "https://stats.talos.korollr.com/v1/events";
private readonly on;
private readonly window;
private queue;
private last;
private timers;
private period;
constructor(opts: TelemetryOptions | false | undefined);
get enabled(): boolean;
has(part: Part): boolean;
/** Queue an event if its part is on; `part` undefined means always (while enabled). */
emit(part: Part | undefined, event: Event): void;
/** Talos just answered for this call: errors in the next few seconds follow it. */
answered(callId: string, modelMs?: number, runMs?: number): void;
/** An error, kept only if it came within the window after an answer (or names its call). */
error(err: unknown, source: string, callId?: string): void;
flush(): Promise<void>;
spool(): void;
/** What a crashed process left behind, sent once (a rename claims it first). */
private resend;
/** Once a minute: Talos's latency and load, and the process's. */
private sample;
/**
* Feedback on one call: a text, a rating from 1 to 5, or both. Sent at once,
* and even with telemetry off — it is the developer's own explicit message.
*/
feedback(callId: string, fb: {
text?: string;
rating?: number;
}): Promise<void>;
/** Stop sending (and send what is queued). */
close(): Promise<void>;
}
export declare const platformInfo: () => {
node: string;
platform: NodeJS.Platform;
arch: NodeJS.Architecture;
cpus: number;
};
export {};