@nxgt/telemetry 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ import type { Exporter } from '../export/exporter';
2
+ import type { Resource, Severity, Signal } from '../model/signal';
3
+ import { type Sampler } from '../trace/sampler';
4
+ export interface TelemetryOptions {
5
+ readonly version?: string;
6
+ readonly environment?: string;
7
+ /** Stamped on the resource, so every signal carries them. */
8
+ readonly attributes?: Readonly<Record<string, unknown>>;
9
+ /** Asked once, for a root span. Default: `alwaysSample`. */
10
+ readonly sampler?: Sampler;
11
+ /** Logs below this are never built. Spans are unaffected. Default `info`. */
12
+ readonly minimum?: Severity;
13
+ /** Whether a recorded failure carries its stack. Default true. */
14
+ readonly stackTraces?: boolean;
15
+ /** Flush once this many signals are waiting. Default 512. */
16
+ readonly batch?: number;
17
+ /** Flush this long after the first signal of a batch, in ms. Default 1000. */
18
+ readonly linger?: number;
19
+ /** How long `close` waits for the backlog, in ms. Default 10000. */
20
+ readonly drainTimeout?: number;
21
+ /** Default: `console.error`. It must not throw; if it does, it is ignored. */
22
+ readonly onExportError?: (failure: unknown) => void;
23
+ /** In order. A batch reaches them one after the other. */
24
+ readonly exporters?: readonly Exporter[];
25
+ }
26
+ export declare const TELEMETRY_DEFAULTS: Readonly<{
27
+ minimum: Severity;
28
+ stackTraces: true;
29
+ batch: 512;
30
+ linger: 1000;
31
+ drainTimeout: 10000;
32
+ }>;
33
+ /**
34
+ * A service's telemetry: its resource, its sampler, and the pipeline its
35
+ * signals go through.
36
+ *
37
+ * Build it with {@link createTelemetry}. `install()` makes it the one a logger
38
+ * or a span finds when there is none in scope.
39
+ */
40
+ export declare class Telemetry {
41
+ readonly resource: Resource;
42
+ readonly sampler: Sampler;
43
+ readonly minimum: Severity;
44
+ readonly stackTraces: boolean;
45
+ private readonly pipeline;
46
+ constructor(options: TelemetryOptions & {
47
+ readonly service: string;
48
+ });
49
+ /** Never blocks, never throws. False once closed. */
50
+ emit(signal: Signal): boolean;
51
+ /** The one a logger or a span finds with nothing in scope. Returns itself. */
52
+ install(): this;
53
+ /**
54
+ * Ships the backlog and closes the exporters. **It has to be awaited**:
55
+ * JavaScript cannot block, so a process that exits without waiting loses
56
+ * its last batch — which is the batch that explains the shutdown.
57
+ *
58
+ * Idempotent, and it stands down as the installed default.
59
+ */
60
+ close(): Promise<void>;
61
+ [Symbol.asyncDispose](): Promise<void>;
62
+ }
63
+ /**
64
+ * ```ts
65
+ * const telemetry = createTelemetry('checkout', {
66
+ * environment: 'production',
67
+ * sampler: ratioSampler(0.1),
68
+ * exporters: [consoleExporter()],
69
+ * }).install();
70
+ * ```
71
+ *
72
+ * `service` has no default on purpose: it is the key everything groups by, and
73
+ * a service called `unknown` is a dashboard nobody can read.
74
+ */
75
+ export declare function createTelemetry(service: string, options?: TelemetryOptions): Telemetry;
76
+ /** The installed default, if `install()` has been called. */
77
+ export declare function installedTelemetry(): Telemetry | undefined;
78
+ /**
79
+ * Only for a test that needs the process back the way it found it. Production
80
+ * code stands an instance down by closing it.
81
+ */
82
+ export declare function uninstallTelemetry(telemetry?: Telemetry): void;
83
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../src/telemetry/telemetry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,CAAC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YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,gBAAqB,GAC5B,SAAS,CAEX;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,IAAI,SAAS,GAAG,SAAS,CAE1D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAE9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/telemetry",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Logs and traces for a TypeScript service, with no OpenTelemetry SDK: spans over AsyncLocalStorage, W3C traceparent propagation, declared events, and a pipeline that never blocks the caller",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,7 +50,7 @@
50
50
  ]
51
51
  },
52
52
  "devDependencies": {
53
- "@types/bun": "^1.4.0"
53
+ "@types/bun": "^1.4.2"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "typescript": "^6.0.3"