@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.
- package/README.md +742 -0
- package/dist/attributes/attributes.d.ts +7 -0
- package/dist/attributes/attributes.d.ts.map +1 -1
- package/dist/context/current.d.ts +43 -0
- package/dist/context/current.d.ts.map +1 -0
- package/dist/export/console.d.ts +20 -0
- package/dist/export/console.d.ts.map +1 -0
- package/dist/export/exporter.d.ts +39 -0
- package/dist/export/exporter.d.ts.map +1 -0
- package/dist/export/file.d.ts +43 -0
- package/dist/export/file.d.ts.map +1 -0
- package/dist/export/json-lines.d.ts +17 -0
- package/dist/export/json-lines.d.ts.map +1 -0
- package/dist/export/pipeline.d.ts +64 -0
- package/dist/export/pipeline.d.ts.map +1 -0
- package/dist/export/rotation.d.ts +46 -0
- package/dist/export/rotation.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +845 -33
- package/dist/index.js.map +18 -6
- package/dist/logger/event.d.ts +15 -0
- package/dist/logger/event.d.ts.map +1 -0
- package/dist/logger/logger.d.ts +46 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/standard-schema.d.ts +32 -0
- package/dist/logger/standard-schema.d.ts.map +1 -0
- package/dist/model/error.d.ts +21 -0
- package/dist/model/error.d.ts.map +1 -0
- package/dist/span/scope.d.ts +71 -0
- package/dist/span/scope.d.ts.map +1 -0
- package/dist/span/span.d.ts +13 -0
- package/dist/span/span.d.ts.map +1 -0
- package/dist/telemetry/telemetry.d.ts +83 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -11,6 +11,13 @@ export type AttributeValue = AttributeScalar | readonly AttributeScalar[];
|
|
|
11
11
|
export type Attributes = Readonly<Record<string, AttributeValue>>;
|
|
12
12
|
/** Shared, frozen, and the one to return when there is nothing to say. */
|
|
13
13
|
export declare const EMPTY_ATTRIBUTES: Attributes;
|
|
14
|
+
/**
|
|
15
|
+
* What a value reads as when reading it threw. A getter that throws, a revoked
|
|
16
|
+
* Proxy and a `toString` that raises all arrive here — from application code,
|
|
17
|
+
* in a `catch`, which is exactly where a log must not become the second
|
|
18
|
+
* failure.
|
|
19
|
+
*/
|
|
20
|
+
export declare const UNREADABLE = "[unreadable]";
|
|
14
21
|
/**
|
|
15
22
|
* Whatever a caller passed, as something that can be indexed.
|
|
16
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/attributes/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,SAAS,eAAe,EAAE,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;AAElE,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,EAAE,UAA8B,CAAC;AAE9D;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/attributes/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,SAAS,eAAe,EAAE,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;AAElE,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,EAAE,UAA8B,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAQ9D;AA4BD;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GAClD,UAAU,CA+BZ;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAC9B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,UAAU,GACf,UAAU,CAKZ;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAEjE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Attributes } from '../attributes/attributes';
|
|
2
|
+
import { type Telemetry } from '../telemetry/telemetry';
|
|
3
|
+
import { type SpanContext } from '../trace/ids';
|
|
4
|
+
/**
|
|
5
|
+
* What travels with the work: which telemetry is writing, which span is open,
|
|
6
|
+
* and the attributes everything inside inherits.
|
|
7
|
+
*/
|
|
8
|
+
export interface TelemetryContext {
|
|
9
|
+
readonly telemetry: Telemetry;
|
|
10
|
+
/** Absent between `withTelemetry` and the first `span`. */
|
|
11
|
+
readonly span?: SpanContext;
|
|
12
|
+
readonly attributes: Attributes;
|
|
13
|
+
}
|
|
14
|
+
export declare function currentContext(): TelemetryContext | undefined;
|
|
15
|
+
/** Runs `fn` with `context` current, and restores whatever was there after. */
|
|
16
|
+
export declare function runWithContext<T>(context: TelemetryContext, fn: () => T): T;
|
|
17
|
+
/**
|
|
18
|
+
* The telemetry a logger or a span should write to: the one **in scope** first,
|
|
19
|
+
* the **installed** one second.
|
|
20
|
+
*
|
|
21
|
+
* That order is what lets two suites in one process each collect their own
|
|
22
|
+
* signals, and it is why `withTelemetry` exists.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveTelemetry(): Telemetry | undefined;
|
|
25
|
+
/** Runs `fn` with `telemetry` in scope, in place of the installed one. */
|
|
26
|
+
export declare function withTelemetry<T>(telemetry: Telemetry, fn: () => T): T;
|
|
27
|
+
/**
|
|
28
|
+
* Runs `fn` with these attributes inherited by every log and span inside it.
|
|
29
|
+
*
|
|
30
|
+
* With no context open but a telemetry installed — the top level of an
|
|
31
|
+
* application, before any span — it opens one, so the attributes reach the logs
|
|
32
|
+
* written there. With nothing installed either it runs `fn` unchanged:
|
|
33
|
+
* attaching attributes to nothing is not an error, and a library that does it
|
|
34
|
+
* must work in an application that has never heard of this one.
|
|
35
|
+
*/
|
|
36
|
+
export declare function withAttributes<T>(attributes: Readonly<Record<string, unknown>>, fn: () => T): T;
|
|
37
|
+
/** The span open right here, if there is one. */
|
|
38
|
+
export declare function currentSpan(): SpanContext | undefined;
|
|
39
|
+
/** The header to send with an outgoing call, so the trace continues. */
|
|
40
|
+
export declare function currentTraceparent(): string | undefined;
|
|
41
|
+
/** The attributes everything written here inherits. */
|
|
42
|
+
export declare function currentAttributes(): Attributes;
|
|
43
|
+
//# sourceMappingURL=current.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current.d.ts","sourceRoot":"","sources":["../../src/context/current.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,UAAU,EAIf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CAChC;AAoBD,wBAAgB,cAAc,IAAI,gBAAgB,GAAG,SAAS,CAE7D;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE3E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,SAAS,GAAG,SAAS,CAExD;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAUrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC/B,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC7C,EAAE,EAAE,MAAM,CAAC,GACT,CAAC,CAcH;AAED,iDAAiD;AACjD,wBAAgB,WAAW,IAAI,WAAW,GAAG,SAAS,CAErD;AAED,wEAAwE;AACxE,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,SAAS,CAGvD;AAED,uDAAuD;AACvD,wBAAgB,iBAAiB,IAAI,UAAU,CAE9C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Exporter } from './exporter';
|
|
2
|
+
export interface ConsoleExporterOptions {
|
|
3
|
+
/** Where a line goes. Default: `console.log`. */
|
|
4
|
+
readonly write?: (line: string) => void;
|
|
5
|
+
/** Whether a recorded stack is printed under the line. Default true. */
|
|
6
|
+
readonly stackTraces?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* One line per signal, for a terminal.
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* 10:04:22.318 INFO CheckoutService checkout.charged orderId=o-1 amount=4200 [4bf92f35/00f067aa]
|
|
13
|
+
* 10:04:22.402 SPAN charge 84ms [4bf92f35/00f067aa]
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Errors go to the same stream as everything else: a log split across two
|
|
17
|
+
* streams is a log read in the wrong order.
|
|
18
|
+
*/
|
|
19
|
+
export declare function consoleExporter(options?: ConsoleExporterOptions): Exporter;
|
|
20
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/export/console.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,sBAAsB;IACtC,iDAAiD;IACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,wEAAwE;IACxE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC9B,OAAO,GAAE,sBAA2B,GAClC,QAAQ,CAcV"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Resource, Signal } from '../model/signal';
|
|
2
|
+
/**
|
|
3
|
+
* Where a batch of signals goes.
|
|
4
|
+
*
|
|
5
|
+
* The contract, which the pipeline guarantees and an implementation may rely
|
|
6
|
+
* on:
|
|
7
|
+
*
|
|
8
|
+
* - **`export` is called from one consumer, never concurrently.** There is
|
|
9
|
+
* nothing to synchronise, and a batch's order is the order things happened
|
|
10
|
+
* in.
|
|
11
|
+
* - **It may take as long as it wants.** Nothing that writes a signal is
|
|
12
|
+
* waiting on it.
|
|
13
|
+
* - **It should not throw.** If it does, the failure is reported to
|
|
14
|
+
* `onExportError` and the next exporter still receives the batch: a
|
|
15
|
+
* collector being down is not a reason for a request to fail.
|
|
16
|
+
*
|
|
17
|
+
* The `resource` comes with every call rather than through a start hook, rather
|
|
18
|
+
* than being fixed when the exporter is built — which is what lets one exporter
|
|
19
|
+
* serve two telemetries. Most exporters here hold nothing; `fileExporter` is
|
|
20
|
+
* the exception and says so.
|
|
21
|
+
*/
|
|
22
|
+
export interface Exporter {
|
|
23
|
+
/**
|
|
24
|
+
* Declared as a property rather than a method so TypeScript checks its
|
|
25
|
+
* parameters contravariantly: an implementation that asks for a mutable
|
|
26
|
+
* `Signal[]` is rejected, and a batch stays what arrived.
|
|
27
|
+
*/
|
|
28
|
+
export: (resource: Resource, batch: readonly Signal[]) => void | Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Called once, after the last batch has drained. Optional.
|
|
31
|
+
*
|
|
32
|
+
* The one exception is a drain that ran out of time: `close` is then called
|
|
33
|
+
* while an `export` may still be in flight, because the alternative is a
|
|
34
|
+
* process that will not exit. The timeout is reported to `onExportError`
|
|
35
|
+
* first, so it is never silent.
|
|
36
|
+
*/
|
|
37
|
+
close?: () => void | Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../../src/export/exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,QAAQ;IACxB;;;;OAIG;IACH,MAAM,EAAE,CACP,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,SAAS,MAAM,EAAE,KACpB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Exporter } from './exporter';
|
|
2
|
+
/** 64 MiB. */
|
|
3
|
+
export declare const DEFAULT_MAX_SIZE: number;
|
|
4
|
+
/** 24 hours, in milliseconds. Epoch-aligned, so it rolls at UTC midnight. */
|
|
5
|
+
export declare const DEFAULT_ROTATION_PERIOD: number;
|
|
6
|
+
export interface FileExporterOptions {
|
|
7
|
+
/** The file to append to. Its directory is created if it is missing. */
|
|
8
|
+
readonly path: string;
|
|
9
|
+
/** Roll at this many bytes. `0` disables it. Default 64 MiB. */
|
|
10
|
+
readonly maxSize?: number;
|
|
11
|
+
/** Roll when this period changes, in ms. `0` disables it. Default 24h. */
|
|
12
|
+
readonly every?: number;
|
|
13
|
+
/** How many rolled files to keep. Default 7. */
|
|
14
|
+
readonly keep?: number;
|
|
15
|
+
/** Gzip a rolled file. Default false. */
|
|
16
|
+
readonly compress?: boolean;
|
|
17
|
+
/** For specs. Default `Date.now`. */
|
|
18
|
+
readonly now?: () => number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One JSON object per signal, appended to a file, with rotation.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* fileExporter({ path: 'logs/telemetry.jsonl', every: 0, maxSize: 8 * 1024 * 1024 })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* The same line format as `jsonLinesExporter`, so a shipper reads either. It
|
|
28
|
+
* **appends**: a restart continues the current file, and the period is read
|
|
29
|
+
* from that file's modification time rather than from when this process
|
|
30
|
+
* started, so a service that restarts hourly still rolls once a day.
|
|
31
|
+
*
|
|
32
|
+
* `close()` rolls nothing. A rolled file is a finished period, and a shutdown is
|
|
33
|
+
* not one.
|
|
34
|
+
*
|
|
35
|
+
* **This exporter owns its path.** It is the one stateful exporter here — it
|
|
36
|
+
* remembers the file's size and age rather than asking the filesystem on every
|
|
37
|
+
* batch — so give each path exactly one exporter. Calls are serialised
|
|
38
|
+
* internally, and any failure throws away what it remembered, so an external
|
|
39
|
+
* `logrotate` or a full disk costs the batch it happened on and nothing after
|
|
40
|
+
* it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function fileExporter(options: FileExporterOptions): Exporter;
|
|
43
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/export/file.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAU3C,cAAc;AACd,eAAO,MAAM,gBAAgB,QAAmB,CAAC;AACjD,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,QAAsB,CAAC;AAI3D,MAAM,WAAW,mBAAmB;IACnC,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,QAAQ,CAgDnE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Exporter } from './exporter';
|
|
2
|
+
export interface JsonLinesExporterOptions {
|
|
3
|
+
/** Where a line goes. Default: `console.log`. */
|
|
4
|
+
readonly write?: (line: string) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* One JSON object per signal, one per line — the format `jq`, a log shipper and
|
|
8
|
+
* a collector's file receiver all read.
|
|
9
|
+
*
|
|
10
|
+
* The line is the signal as it is: `type` discriminates `"log"` from `"span"`,
|
|
11
|
+
* instants are epoch milliseconds, and absent fields are absent rather than
|
|
12
|
+
* null. **It does not carry the resource.** A file belongs to one service, so
|
|
13
|
+
* repeating its name on every line would be noise; an exporter that writes
|
|
14
|
+
* somewhere shared — `@nxgt/telemetry-mongo` — stamps it instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function jsonLinesExporter(options?: JsonLinesExporterOptions): Exporter;
|
|
17
|
+
//# sourceMappingURL=json-lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-lines.d.ts","sourceRoot":"","sources":["../../src/export/json-lines.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,wBAAwB;IACxC,iDAAiD;IACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,GAAE,wBAA6B,GACpC,QAAQ,CAWV"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Resource, Signal } from '../model/signal';
|
|
2
|
+
import type { Exporter } from './exporter';
|
|
3
|
+
export interface PipelineOptions {
|
|
4
|
+
readonly resource: Resource;
|
|
5
|
+
readonly exporters: readonly Exporter[];
|
|
6
|
+
/** Flush once this many signals are waiting. */
|
|
7
|
+
readonly batch: number;
|
|
8
|
+
/** Flush this many milliseconds after the first signal of a batch. */
|
|
9
|
+
readonly linger: number;
|
|
10
|
+
/** How long `close` waits for the backlog before giving up. */
|
|
11
|
+
readonly drainTimeout: number;
|
|
12
|
+
readonly onExportError: (failure: unknown) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The queue between everything that writes a signal and everything that ships
|
|
16
|
+
* one.
|
|
17
|
+
*
|
|
18
|
+
* `post` is synchronous, total, and unbounded. A bounded queue would answer the
|
|
19
|
+
* back-pressure question by dropping signals or by blocking the application,
|
|
20
|
+
* and neither is an answer; an application that outruns its collector grows
|
|
21
|
+
* this array, which is visible in a heap profile, rather than losing the
|
|
22
|
+
* evidence of what it was doing.
|
|
23
|
+
*
|
|
24
|
+
* One consumer drains it, which is what lets the buffer be a plain array with
|
|
25
|
+
* no locking and what makes a batch's order the order things happened in.
|
|
26
|
+
*/
|
|
27
|
+
export declare class Pipeline {
|
|
28
|
+
private readonly options;
|
|
29
|
+
private buffer;
|
|
30
|
+
private timer;
|
|
31
|
+
/** The single consumer: every flush is chained onto the previous one. */
|
|
32
|
+
private draining;
|
|
33
|
+
private closed;
|
|
34
|
+
private closing;
|
|
35
|
+
constructor(options: PipelineOptions);
|
|
36
|
+
/**
|
|
37
|
+
* Never blocks, never throws, and answers whether the signal was taken.
|
|
38
|
+
* `false` means the pipeline is closed — the signal is dropped in silence,
|
|
39
|
+
* because a log must not become the reason a shutdown fails.
|
|
40
|
+
*/
|
|
41
|
+
post(signal: Signal): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Stops accepting signals, ships what is waiting, and closes every
|
|
44
|
+
* exporter. Idempotent.
|
|
45
|
+
*
|
|
46
|
+
* It has to be awaited, and it is the one thing here that a caller waits
|
|
47
|
+
* for: a close that returned before the backlog shipped would lose exactly
|
|
48
|
+
* the signals a shutdown most needs to explain itself.
|
|
49
|
+
*
|
|
50
|
+
* **`drainTimeout` bounds the whole of it** — the drain and the exporters'
|
|
51
|
+
* own `close` together — so neither a collector that stopped answering nor
|
|
52
|
+
* an exporter that will not let go of its socket becomes the reason a
|
|
53
|
+
* process will not exit. A drain that runs out of time is reported to
|
|
54
|
+
* `onExportError`; see {@link Exporter} for what that suspends.
|
|
55
|
+
*/
|
|
56
|
+
close(): Promise<void>;
|
|
57
|
+
private flush;
|
|
58
|
+
private clearTimer;
|
|
59
|
+
private ship;
|
|
60
|
+
private drainAndClose;
|
|
61
|
+
private closeExporters;
|
|
62
|
+
private report;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/export/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACnD;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,KAAK,CAA4C;IACzD,yEAAyE;IACzE,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA4B;gBAE/B,OAAO,EAAE,eAAe;IAIpC;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAoB7B;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,UAAU;YAMJ,IAAI;YAUJ,aAAa;YA2Bb,cAAc;IAU5B,OAAO,CAAC,MAAM;CASd"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface RotationPolicy {
|
|
2
|
+
/** Roll once the file is at least this many bytes. 0 disables it. */
|
|
3
|
+
readonly maxSize: number;
|
|
4
|
+
/** Roll when this many milliseconds' period changes. 0 disables it. */
|
|
5
|
+
readonly every: number;
|
|
6
|
+
/** How many rolled files to keep. 0 keeps none. */
|
|
7
|
+
readonly keep: number;
|
|
8
|
+
readonly compress: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether the file open since `openedAt` should be rolled before the next
|
|
12
|
+
* write.
|
|
13
|
+
*
|
|
14
|
+
* **An empty file is never rolled**, whatever the clock says: rolling one
|
|
15
|
+
* produces an empty archive and resets the period, so an idle service would
|
|
16
|
+
* accumulate a directory of nothing.
|
|
17
|
+
*
|
|
18
|
+
* The period is **epoch-aligned** rather than measured from when the file was
|
|
19
|
+
* opened: `every: 24h` then rolls at UTC midnight, which is what somebody
|
|
20
|
+
* reading yesterday's file expects, instead of 24 hours after a restart.
|
|
21
|
+
*/
|
|
22
|
+
export declare function rotationDue(size: number, openedAt: number, now: number, policy: RotationPolicy): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* `telemetry.jsonl` rolled at that instant becomes
|
|
25
|
+
* `telemetry-20260915-100422.jsonl`, and `-1`, `-2`… if that name is taken.
|
|
26
|
+
* UTC, and no colons: the name has to survive every filesystem.
|
|
27
|
+
*/
|
|
28
|
+
export declare function rolledName(path: string, at: number, taken?: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* The rolled files of `path`, **newest first**. Anything else — the live file,
|
|
31
|
+
* another service's archives — is left alone.
|
|
32
|
+
*
|
|
33
|
+
* The order is taken from the parsed stamp and collision number, not from the
|
|
34
|
+
* name as text. Sorting the names would be wrong twice over within one second:
|
|
35
|
+
* the suffix is not fixed-width, so `-9` sorts after `-12`, and the unsuffixed
|
|
36
|
+
* name — which is the *oldest* of that second — sorts after every suffixed one,
|
|
37
|
+
* because `.` is above `-`.
|
|
38
|
+
*
|
|
39
|
+
* A gzipped archive and its plain twin are one period, and only the archive is
|
|
40
|
+
* listed: a `compress` whose cleanup failed must not make `keep` prune a period
|
|
41
|
+
* early.
|
|
42
|
+
*/
|
|
43
|
+
export declare function rolledOf(path: string, names: readonly string[]): string[];
|
|
44
|
+
/** Which rolled files to delete, given how many to keep. */
|
|
45
|
+
export declare function prunable(path: string, names: readonly string[], keep: number): string[];
|
|
46
|
+
//# sourceMappingURL=rotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotation.d.ts","sourceRoot":"","sources":["../../src/export/rotation.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,GACpB,OAAO,CAIT;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAUtE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAoBzE;AAED,4DAA4D;AAC5D,wBAAgB,QAAQ,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,MAAM,GACV,MAAM,EAAE,CAOV"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
export * from './attributes/attributes';
|
|
2
|
+
export * from './context/current';
|
|
3
|
+
export * from './export/console';
|
|
4
|
+
export * from './export/exporter';
|
|
5
|
+
export * from './export/file';
|
|
6
|
+
export * from './export/json-lines';
|
|
7
|
+
export type { PipelineOptions } from './export/pipeline';
|
|
8
|
+
export * from './export/rotation';
|
|
9
|
+
export * from './logger/event';
|
|
10
|
+
export * from './logger/logger';
|
|
11
|
+
export type { StandardSchemaV1 } from './logger/standard-schema';
|
|
12
|
+
export * from './model/error';
|
|
2
13
|
export * from './model/signal';
|
|
14
|
+
export * from './span/scope';
|
|
15
|
+
export * from './span/span';
|
|
16
|
+
export * from './telemetry/telemetry';
|
|
3
17
|
export * from './trace/ids';
|
|
4
18
|
export * from './trace/sampler';
|
|
5
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|