@telorun/kernel 0.49.0 → 0.51.0
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/dist/controller-loader.d.ts +6 -1
- package/dist/controller-loader.d.ts.map +1 -1
- package/dist/controller-loader.js +2 -0
- package/dist/controller-loader.js.map +1 -1
- package/dist/controller-loaders/bundle-builder.d.ts +2 -1
- package/dist/controller-loaders/bundle-builder.d.ts.map +1 -1
- package/dist/controller-loaders/bundle-builder.js +14 -9
- package/dist/controller-loaders/bundle-builder.js.map +1 -1
- package/dist/controller-loaders/npm-loader.d.ts +8 -2
- package/dist/controller-loaders/npm-loader.d.ts.map +1 -1
- package/dist/controller-loaders/npm-loader.js +19 -10
- package/dist/controller-loaders/npm-loader.js.map +1 -1
- package/dist/controllers/logging/console-sink-controller.d.ts +15 -0
- package/dist/controllers/logging/console-sink-controller.d.ts.map +1 -0
- package/dist/controllers/logging/console-sink-controller.js +40 -0
- package/dist/controllers/logging/console-sink-controller.js.map +1 -0
- package/dist/controllers/logging/file-sink-controller.d.ts +11 -0
- package/dist/controllers/logging/file-sink-controller.d.ts.map +1 -0
- package/dist/controllers/logging/file-sink-controller.js +33 -0
- package/dist/controllers/logging/file-sink-controller.js.map +1 -0
- package/dist/controllers/logging/sink-identity.d.ts +37 -0
- package/dist/controllers/logging/sink-identity.d.ts.map +1 -0
- package/dist/controllers/logging/sink-identity.js +40 -0
- package/dist/controllers/logging/sink-identity.js.map +1 -0
- package/dist/controllers/module/import-controller.d.ts.map +1 -1
- package/dist/controllers/module/import-controller.js +25 -0
- package/dist/controllers/module/import-controller.js.map +1 -1
- package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -1
- package/dist/controllers/resource-definition/resource-definition-controller.js +1 -0
- package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -1
- package/dist/evaluation-context.d.ts +27 -1
- package/dist/evaluation-context.d.ts.map +1 -1
- package/dist/evaluation-context.js +84 -16
- package/dist/evaluation-context.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/internal-context.d.ts +4 -0
- package/dist/internal-context.d.ts.map +1 -1
- package/dist/kernel.d.ts +26 -0
- package/dist/kernel.d.ts.map +1 -1
- package/dist/kernel.js +78 -5
- package/dist/kernel.js.map +1 -1
- package/dist/logging/bootstrap-writer.d.ts +23 -0
- package/dist/logging/bootstrap-writer.d.ts.map +1 -0
- package/dist/logging/bootstrap-writer.js +31 -0
- package/dist/logging/bootstrap-writer.js.map +1 -0
- package/dist/logging/color-precedence.d.ts +27 -0
- package/dist/logging/color-precedence.d.ts.map +1 -0
- package/dist/logging/color-precedence.js +47 -0
- package/dist/logging/color-precedence.js.map +1 -0
- package/dist/logging/console-sink.d.ts +45 -0
- package/dist/logging/console-sink.d.ts.map +1 -0
- package/dist/logging/console-sink.js +56 -0
- package/dist/logging/console-sink.js.map +1 -0
- package/dist/logging/debug-wire-sink.d.ts +38 -0
- package/dist/logging/debug-wire-sink.d.ts.map +1 -0
- package/dist/logging/debug-wire-sink.js +85 -0
- package/dist/logging/debug-wire-sink.js.map +1 -0
- package/dist/logging/drop-accounting.d.ts +34 -0
- package/dist/logging/drop-accounting.d.ts.map +1 -0
- package/dist/logging/drop-accounting.js +98 -0
- package/dist/logging/drop-accounting.js.map +1 -0
- package/dist/logging/encode-json.d.ts +28 -0
- package/dist/logging/encode-json.d.ts.map +1 -0
- package/dist/logging/encode-json.js +86 -0
- package/dist/logging/encode-json.js.map +1 -0
- package/dist/logging/encode-pretty.d.ts +7 -0
- package/dist/logging/encode-pretty.d.ts.map +1 -0
- package/dist/logging/encode-pretty.js +104 -0
- package/dist/logging/encode-pretty.js.map +1 -0
- package/dist/logging/file-sink.d.ts +33 -0
- package/dist/logging/file-sink.d.ts.map +1 -0
- package/dist/logging/file-sink.js +72 -0
- package/dist/logging/file-sink.js.map +1 -0
- package/dist/logging/index.d.ts +39 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +27 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/kernel-logging.d.ts +110 -0
- package/dist/logging/kernel-logging.d.ts.map +1 -0
- package/dist/logging/kernel-logging.js +199 -0
- package/dist/logging/kernel-logging.js.map +1 -0
- package/dist/logging/log-sink.d.ts +9 -0
- package/dist/logging/log-sink.d.ts.map +1 -0
- package/dist/logging/log-sink.js +8 -0
- package/dist/logging/log-sink.js.map +1 -0
- package/dist/logging/logging-host.d.ts +14 -0
- package/dist/logging/logging-host.d.ts.map +1 -0
- package/dist/logging/logging-host.js +27 -0
- package/dist/logging/logging-host.js.map +1 -0
- package/dist/logging/logging-pipeline.d.ts +89 -0
- package/dist/logging/logging-pipeline.d.ts.map +1 -0
- package/dist/logging/logging-pipeline.js +349 -0
- package/dist/logging/logging-pipeline.js.map +1 -0
- package/dist/logging/normalize-attributes.d.ts +48 -0
- package/dist/logging/normalize-attributes.d.ts.map +1 -0
- package/dist/logging/normalize-attributes.js +140 -0
- package/dist/logging/normalize-attributes.js.map +1 -0
- package/dist/logging/record-buffer.d.ts +24 -0
- package/dist/logging/record-buffer.d.ts.map +1 -0
- package/dist/logging/record-buffer.js +78 -0
- package/dist/logging/record-buffer.js.map +1 -0
- package/dist/logging/redact-attributes.d.ts +45 -0
- package/dist/logging/redact-attributes.d.ts.map +1 -0
- package/dist/logging/redact-attributes.js +152 -0
- package/dist/logging/redact-attributes.js.map +1 -0
- package/dist/logging/sampler.d.ts +34 -0
- package/dist/logging/sampler.d.ts.map +1 -0
- package/dist/logging/sampler.js +52 -0
- package/dist/logging/sampler.js.map +1 -0
- package/dist/logging/scope-config.d.ts +32 -0
- package/dist/logging/scope-config.d.ts.map +1 -0
- package/dist/logging/scope-config.js +2 -0
- package/dist/logging/scope-config.js.map +1 -0
- package/dist/logging/span-id.d.ts +24 -0
- package/dist/logging/span-id.d.ts.map +1 -0
- package/dist/logging/span-id.js +85 -0
- package/dist/logging/span-id.js.map +1 -0
- package/dist/logging/to-error-value.d.ts +3 -0
- package/dist/logging/to-error-value.d.ts.map +1 -0
- package/dist/logging/to-error-value.js +79 -0
- package/dist/logging/to-error-value.js.map +1 -0
- package/dist/logging/trace-parent.d.ts +54 -0
- package/dist/logging/trace-parent.d.ts.map +1 -0
- package/dist/logging/trace-parent.js +92 -0
- package/dist/logging/trace-parent.js.map +1 -0
- package/dist/manifest-schemas.d.ts +1 -1
- package/dist/manifest-schemas.d.ts.map +1 -1
- package/dist/manifest-schemas.js +12 -0
- package/dist/manifest-schemas.js.map +1 -1
- package/dist/module-context.d.ts +16 -0
- package/dist/module-context.d.ts.map +1 -1
- package/dist/module-context.js +6 -0
- package/dist/module-context.js.map +1 -1
- package/dist/resource-context.d.ts +15 -1
- package/dist/resource-context.d.ts.map +1 -1
- package/dist/resource-context.js +45 -0
- package/dist/resource-context.js.map +1 -1
- package/dist/schema-compiled-values.d.ts.map +1 -1
- package/dist/schema-compiled-values.js +7 -0
- package/dist/schema-compiled-values.js.map +1 -1
- package/dist/schema-validator.d.ts +8 -1
- package/dist/schema-validator.d.ts.map +1 -1
- package/dist/schema-validator.js +13 -3
- package/dist/schema-validator.js.map +1 -1
- package/dist/transports/oci/oci-transport.d.ts +2 -0
- package/dist/transports/oci/oci-transport.d.ts.map +1 -1
- package/dist/transports/oci/oci-transport.js +15 -1
- package/dist/transports/oci/oci-transport.js.map +1 -1
- package/dist/transports/registry-transport.d.ts +2 -0
- package/dist/transports/registry-transport.d.ts.map +1 -1
- package/dist/transports/registry-transport.js +13 -0
- package/dist/transports/registry-transport.js.map +1 -1
- package/dist/transports/transport.d.ts +15 -0
- package/dist/transports/transport.d.ts.map +1 -1
- package/package.json +17 -3
- package/src/controller-loader.ts +7 -1
- package/src/controller-loaders/bundle-builder.ts +18 -10
- package/src/controller-loaders/npm-loader.ts +32 -11
- package/src/controllers/logging/console-sink-controller.ts +46 -0
- package/src/controllers/logging/file-sink-controller.ts +40 -0
- package/src/controllers/logging/sink-identity.ts +53 -0
- package/src/controllers/module/import-controller.ts +27 -0
- package/src/controllers/resource-definition/resource-definition-controller.ts +1 -0
- package/src/evaluation-context.ts +93 -15
- package/src/index.ts +54 -0
- package/src/internal-context.ts +4 -0
- package/src/kernel.ts +98 -8
- package/src/logging/bootstrap-writer.ts +38 -0
- package/src/logging/color-precedence.ts +62 -0
- package/src/logging/console-sink.ts +86 -0
- package/src/logging/debug-wire-sink.ts +85 -0
- package/src/logging/drop-accounting.ts +108 -0
- package/src/logging/encode-json.ts +98 -0
- package/src/logging/encode-pretty.ts +117 -0
- package/src/logging/file-sink.ts +87 -0
- package/src/logging/index.ts +65 -0
- package/src/logging/kernel-logging.ts +266 -0
- package/src/logging/log-sink.ts +18 -0
- package/src/logging/logging-host.ts +33 -0
- package/src/logging/logging-pipeline.ts +465 -0
- package/src/logging/normalize-attributes.ts +228 -0
- package/src/logging/record-buffer.ts +72 -0
- package/src/logging/redact-attributes.ts +168 -0
- package/src/logging/sampler.ts +76 -0
- package/src/logging/scope-config.ts +32 -0
- package/src/logging/span-id.ts +84 -0
- package/src/logging/to-error-value.ts +89 -0
- package/src/logging/trace-parent.ts +110 -0
- package/src/manifest-schemas.ts +12 -0
- package/src/module-context.ts +23 -0
- package/src/resource-context.ts +48 -0
- package/src/schema-compiled-values.ts +6 -0
- package/src/schema-validator.ts +20 -5
- package/src/transports/oci/oci-transport.ts +16 -0
- package/src/transports/registry-transport.ts +14 -0
- package/src/transports/transport.ts +17 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _ConsoleSink_stream, _ConsoleSink_pretty, _ConsoleSink_color, _ConsoleSink_encodeBytes;
|
|
13
|
+
import { decideColor } from "./color-precedence.js";
|
|
14
|
+
import { encodeJsonLine } from "./encode-json.js";
|
|
15
|
+
import { encodePrettyLine } from "./encode-pretty.js";
|
|
16
|
+
export class ConsoleSink {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
/** A file-descriptor write blocks until the bytes are handed to the OS, so a
|
|
19
|
+
* `fatal` record is durable by the time `log()` returns (§10.5). */
|
|
20
|
+
this.syncFlushable = true;
|
|
21
|
+
_ConsoleSink_stream.set(this, void 0);
|
|
22
|
+
_ConsoleSink_pretty.set(this, void 0);
|
|
23
|
+
_ConsoleSink_color.set(this, void 0);
|
|
24
|
+
_ConsoleSink_encodeBytes.set(this, void 0);
|
|
25
|
+
this.sinkId = options.sinkId;
|
|
26
|
+
this.level = options.level;
|
|
27
|
+
const destination = options.destination ?? "stderr";
|
|
28
|
+
__classPrivateFieldSet(this, _ConsoleSink_stream, destination === "stdout" ? options.stdout : options.stderr, "f");
|
|
29
|
+
// `auto` is evaluated against *this sink's* destination descriptor, not the
|
|
30
|
+
// process's: a console sink on stdout and another on stderr can resolve
|
|
31
|
+
// differently, and that is correct.
|
|
32
|
+
const isTTY = Boolean(__classPrivateFieldGet(this, _ConsoleSink_stream, "f").isTTY);
|
|
33
|
+
const encoding = options.encoding ?? "auto";
|
|
34
|
+
__classPrivateFieldSet(this, _ConsoleSink_pretty, encoding === "pretty" || (encoding === "auto" && isTTY), "f");
|
|
35
|
+
__classPrivateFieldSet(this, _ConsoleSink_color, __classPrivateFieldGet(this, _ConsoleSink_pretty, "f")
|
|
36
|
+
? decideColor({ setting: options.color ?? "auto", env: options.env, isTTY })
|
|
37
|
+
: false, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _ConsoleSink_encodeBytes, options.encodeBytes, "f");
|
|
39
|
+
}
|
|
40
|
+
write(record) {
|
|
41
|
+
__classPrivateFieldGet(this, _ConsoleSink_stream, "f").write(__classPrivateFieldGet(this, _ConsoleSink_pretty, "f")
|
|
42
|
+
? encodePrettyLine(record, { color: __classPrivateFieldGet(this, _ConsoleSink_color, "f") })
|
|
43
|
+
: encodeJsonLine(record, { encodeBytes: __classPrivateFieldGet(this, _ConsoleSink_encodeBytes, "f") }));
|
|
44
|
+
}
|
|
45
|
+
async flush() {
|
|
46
|
+
// Nothing is held: every record is handed to the descriptor on write.
|
|
47
|
+
}
|
|
48
|
+
flushSync() {
|
|
49
|
+
// Same — the write already reached the OS.
|
|
50
|
+
}
|
|
51
|
+
async close() {
|
|
52
|
+
// The process owns stdout/stderr; a sink never closes them.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
_ConsoleSink_stream = new WeakMap(), _ConsoleSink_pretty = new WeakMap(), _ConsoleSink_color = new WeakMap(), _ConsoleSink_encodeBytes = new WeakMap();
|
|
56
|
+
//# sourceMappingURL=console-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-sink.js","sourceRoot":"","sources":["../../src/logging/console-sink.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAqB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAqB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAiCtD,MAAM,OAAO,WAA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,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,uBAAA,IAAI,gCAAa,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,sEAAsE;IACxE,CAAC;IAED,SAAS;QACP,2CAA2C;IAC7C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,4DAA4D;IAC9D,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { LogRecord } from "@telorun/sdk";
|
|
2
|
+
import { type BytesEncoder } from "./encode-json.js";
|
|
3
|
+
import type { LogSinkInstance } from "./log-sink.js";
|
|
4
|
+
/**
|
|
5
|
+
* The `debug-wire` sink — `kernel/specs/logging.md` §10.2 and §11.4.
|
|
6
|
+
*
|
|
7
|
+
* **Not declarable.** It is host-attached when a debug consumer connects
|
|
8
|
+
* (`--debug` / `--inspect`) and detached on disconnect, which makes it tooling
|
|
9
|
+
* attachment rather than application configuration — the same category as TTY
|
|
10
|
+
* detection, not a violation of D6.
|
|
11
|
+
*
|
|
12
|
+
* Not sync-flushable: delivery crosses an SSE/stream boundary owned by the host,
|
|
13
|
+
* so a `fatal` record's flush here is initiated but never awaited (§10.5).
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEBUG_WIRE_SINK_ID = "<debug-wire>";
|
|
16
|
+
export declare class DebugWireSink implements LogSinkInstance {
|
|
17
|
+
#private;
|
|
18
|
+
readonly sinkId = "<debug-wire>";
|
|
19
|
+
readonly level: number;
|
|
20
|
+
readonly syncFlushable = false;
|
|
21
|
+
constructor(options: {
|
|
22
|
+
level: number;
|
|
23
|
+
/** Hands a §11.4 `record` frame to the host's wire writer. */
|
|
24
|
+
emit: (frame: {
|
|
25
|
+
kind: "record";
|
|
26
|
+
timestamp: string;
|
|
27
|
+
record: Record<string, unknown>;
|
|
28
|
+
}) => void;
|
|
29
|
+
/** Offloads `bytes` attributes to the host's blob store when it has one —
|
|
30
|
+
* the debug wire does. Raw bytes are never inlined (§6.1). */
|
|
31
|
+
encodeBytes?: BytesEncoder;
|
|
32
|
+
});
|
|
33
|
+
write(record: LogRecord): void;
|
|
34
|
+
flush(): Promise<void>;
|
|
35
|
+
flushSync(): void;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=debug-wire-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-wire-sink.d.ts","sourceRoot":"","sources":["../../src/logging/debug-wire-sink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,qBAAa,aAAc,YAAW,eAAe;;IACnD,QAAQ,CAAC,MAAM,kBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,SAAS;gBAKnB,OAAO,EAAE;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,8DAA8D;QAC9D,IAAI,EAAE,CAAC,KAAK,EAAE;YAAE,IAAI,EAAE,QAAQ,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,KAAK,IAAI,CAAC;QAC9F;uEAC+D;QAC/D,WAAW,CAAC,EAAE,YAAY,CAAC;KAC5B;IAMD,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAUxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,SAAS,IAAI,IAAI;IAIX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAC7B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DebugWireSink_emit, _DebugWireSink_encodeBytes;
|
|
13
|
+
import { toJsonProfile } from "./encode-json.js";
|
|
14
|
+
/**
|
|
15
|
+
* The `debug-wire` sink — `kernel/specs/logging.md` §10.2 and §11.4.
|
|
16
|
+
*
|
|
17
|
+
* **Not declarable.** It is host-attached when a debug consumer connects
|
|
18
|
+
* (`--debug` / `--inspect`) and detached on disconnect, which makes it tooling
|
|
19
|
+
* attachment rather than application configuration — the same category as TTY
|
|
20
|
+
* detection, not a violation of D6.
|
|
21
|
+
*
|
|
22
|
+
* Not sync-flushable: delivery crosses an SSE/stream boundary owned by the host,
|
|
23
|
+
* so a `fatal` record's flush here is initiated but never awaited (§10.5).
|
|
24
|
+
*/
|
|
25
|
+
export const DEBUG_WIRE_SINK_ID = "<debug-wire>";
|
|
26
|
+
export class DebugWireSink {
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.sinkId = DEBUG_WIRE_SINK_ID;
|
|
29
|
+
this.syncFlushable = false;
|
|
30
|
+
_DebugWireSink_emit.set(this, void 0);
|
|
31
|
+
_DebugWireSink_encodeBytes.set(this, void 0);
|
|
32
|
+
this.level = options.level;
|
|
33
|
+
__classPrivateFieldSet(this, _DebugWireSink_emit, options.emit, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _DebugWireSink_encodeBytes, options.encodeBytes, "f");
|
|
35
|
+
}
|
|
36
|
+
write(record) {
|
|
37
|
+
const profile = toJsonProfile(record);
|
|
38
|
+
if (__classPrivateFieldGet(this, _DebugWireSink_encodeBytes, "f"))
|
|
39
|
+
offloadBytes(profile, __classPrivateFieldGet(this, _DebugWireSink_encodeBytes, "f"));
|
|
40
|
+
__classPrivateFieldGet(this, _DebugWireSink_emit, "f").call(this, {
|
|
41
|
+
kind: "record",
|
|
42
|
+
timestamp: new Date(Number(record.timestamp / 1000000n)).toISOString(),
|
|
43
|
+
record: profile,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async flush() {
|
|
47
|
+
// Frames are handed to the host synchronously; the host owns delivery.
|
|
48
|
+
}
|
|
49
|
+
flushSync() {
|
|
50
|
+
// Never synchronously drainable — see the class doc.
|
|
51
|
+
}
|
|
52
|
+
async close() { }
|
|
53
|
+
}
|
|
54
|
+
_DebugWireSink_emit = new WeakMap(), _DebugWireSink_encodeBytes = new WeakMap();
|
|
55
|
+
/** Replace `Uint8Array` leaves with the host's pointer form, bounded by the
|
|
56
|
+
* attribute limits already applied upstream. */
|
|
57
|
+
function offloadBytes(value, encodeBytes) {
|
|
58
|
+
const stack = [value];
|
|
59
|
+
let guard = 0;
|
|
60
|
+
while (stack.length > 0 && guard < 10000) {
|
|
61
|
+
guard += 1;
|
|
62
|
+
const current = stack.pop();
|
|
63
|
+
if (!current || typeof current !== "object")
|
|
64
|
+
continue;
|
|
65
|
+
if (Array.isArray(current)) {
|
|
66
|
+
for (let i = 0; i < current.length; i += 1) {
|
|
67
|
+
const item = current[i];
|
|
68
|
+
if (item instanceof Uint8Array)
|
|
69
|
+
current[i] = encodeBytes(item);
|
|
70
|
+
else
|
|
71
|
+
stack.push(item);
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const record = current;
|
|
76
|
+
for (const key of Object.keys(record)) {
|
|
77
|
+
const item = record[key];
|
|
78
|
+
if (item instanceof Uint8Array)
|
|
79
|
+
record[key] = encodeBytes(item);
|
|
80
|
+
else
|
|
81
|
+
stack.push(item);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=debug-wire-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-wire-sink.js","sourceRoot":"","sources":["../../src/logging/debug-wire-sink.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AAGpE;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEjD,MAAM,OAAO,aAAa;IAQxB,YAAY,OAOX;QAdQ,WAAM,GAAG,kBAAkB,CAAC;QAE5B,kBAAa,GAAG,KAAK,CAAC;QAEtB,sCAA+F;QAC/F,6CAAuC;QAU9C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,uBAAA,IAAI,uBAAS,OAAO,CAAC,IAAI,MAAA,CAAC;QAC1B,uBAAA,IAAI,8BAAgB,OAAO,CAAC,WAAW,MAAA,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,MAAiB;QACrB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,uBAAA,IAAI,kCAAa;YAAE,YAAY,CAAC,OAAO,EAAE,uBAAA,IAAI,kCAAa,CAAC,CAAC;QAChE,uBAAA,IAAI,2BAAM,MAAV,IAAI,EAAO;YACT,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,QAAU,CAAC,CAA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AI,CAAC,CAAC;;gBAC3D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DropCause } from "./log-sink.js";
|
|
2
|
+
/**
|
|
3
|
+
* Drop accounting — `kernel/specs/logging.md` §10.4.
|
|
4
|
+
*
|
|
5
|
+
* A runtime maintains a monotonic counter of records dropped per sink, per
|
|
6
|
+
* cause. When drops occur and then cease, it emits exactly one `warn` record
|
|
7
|
+
* reporting the count and the cause. **Dropping without accounting is
|
|
8
|
+
* non-conformant** — "nothing is silently lost" is a design principle, not a
|
|
9
|
+
* nice-to-have, so every drop, truncation, and sink failure is counted and
|
|
10
|
+
* surfaced.
|
|
11
|
+
*/
|
|
12
|
+
/** Sampling drops happen before fan-out, so they are not attributable to any one
|
|
13
|
+
* sink and are counted against the pipeline itself. */
|
|
14
|
+
export declare const PIPELINE_SINK_ID = "<pipeline>";
|
|
15
|
+
export interface DropReport {
|
|
16
|
+
sinkId: string;
|
|
17
|
+
cause: DropCause;
|
|
18
|
+
/** Records dropped since the previous report. */
|
|
19
|
+
count: number;
|
|
20
|
+
/** Monotonic lifetime total for this (sink, cause) pair. */
|
|
21
|
+
total: number;
|
|
22
|
+
}
|
|
23
|
+
export declare class DropRegistry {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(onRecovered: (report: DropReport) => void);
|
|
26
|
+
record(sinkId: string, cause: DropCause, count?: number): void;
|
|
27
|
+
/** Lifetime total for a (sink, cause) pair. */
|
|
28
|
+
total(sinkId: string, cause: DropCause): number;
|
|
29
|
+
/** Emit any outstanding reports immediately — used at shutdown so a run that
|
|
30
|
+
* ends while still dropping does not lose its final accounting. */
|
|
31
|
+
reportPending(): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=drop-accounting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-accounting.d.ts","sourceRoot":"","sources":["../../src/logging/drop-accounting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;GASG;AAEH;wDACwD;AACxD,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAa7C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,YAAY;;gBAOX,WAAW,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI;IAIrD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,SAAI,GAAG,IAAI;IAyBzD,+CAA+C;IAC/C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM;IAI/C;wEACoE;IACpE,aAAa,IAAI,IAAI;IAQrB,OAAO,IAAI,IAAI;CAmBhB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DropRegistry_instances, _DropRegistry_counters, _DropRegistry_onRecovered, _DropRegistry_reporting, _DropRegistry_report;
|
|
13
|
+
/**
|
|
14
|
+
* Drop accounting — `kernel/specs/logging.md` §10.4.
|
|
15
|
+
*
|
|
16
|
+
* A runtime maintains a monotonic counter of records dropped per sink, per
|
|
17
|
+
* cause. When drops occur and then cease, it emits exactly one `warn` record
|
|
18
|
+
* reporting the count and the cause. **Dropping without accounting is
|
|
19
|
+
* non-conformant** — "nothing is silently lost" is a design principle, not a
|
|
20
|
+
* nice-to-have, so every drop, truncation, and sink failure is counted and
|
|
21
|
+
* surfaced.
|
|
22
|
+
*/
|
|
23
|
+
/** Sampling drops happen before fan-out, so they are not attributable to any one
|
|
24
|
+
* sink and are counted against the pipeline itself. */
|
|
25
|
+
export const PIPELINE_SINK_ID = "<pipeline>";
|
|
26
|
+
/** How long a cause must go quiet before its recovery warning is emitted. */
|
|
27
|
+
const QUIESCE_MS = 1000;
|
|
28
|
+
export class DropRegistry {
|
|
29
|
+
constructor(onRecovered) {
|
|
30
|
+
_DropRegistry_instances.add(this);
|
|
31
|
+
_DropRegistry_counters.set(this, new Map());
|
|
32
|
+
_DropRegistry_onRecovered.set(this, void 0);
|
|
33
|
+
/** Guards against a recovery warning that itself drops, which would otherwise
|
|
34
|
+
* re-arm the timer forever. */
|
|
35
|
+
_DropRegistry_reporting.set(this, false);
|
|
36
|
+
__classPrivateFieldSet(this, _DropRegistry_onRecovered, onRecovered, "f");
|
|
37
|
+
}
|
|
38
|
+
record(sinkId, cause, count = 1) {
|
|
39
|
+
const key = `${sinkId}\x00${cause}`;
|
|
40
|
+
let counter = __classPrivateFieldGet(this, _DropRegistry_counters, "f").get(key);
|
|
41
|
+
if (!counter) {
|
|
42
|
+
counter = { total: 0, reported: 0, timer: undefined };
|
|
43
|
+
__classPrivateFieldGet(this, _DropRegistry_counters, "f").set(key, counter);
|
|
44
|
+
}
|
|
45
|
+
// Always count — a drop caused by emitting the recovery warning itself is
|
|
46
|
+
// still a drop, and undercounting it is exactly the silent loss this class
|
|
47
|
+
// exists to prevent.
|
|
48
|
+
counter.total += count;
|
|
49
|
+
// The only thing suppressed while a recovery warning is in flight is the
|
|
50
|
+
// timer re-arm: re-arming here would loop forever (the warning's own drop
|
|
51
|
+
// re-arms the timer, which fires and drops again). The increment above keeps
|
|
52
|
+
// the total honest; the next ordinary drop — or `reportPending` at
|
|
53
|
+
// shutdown — surfaces it, since `total !== reported`.
|
|
54
|
+
if (__classPrivateFieldGet(this, _DropRegistry_reporting, "f"))
|
|
55
|
+
return;
|
|
56
|
+
if (counter.timer)
|
|
57
|
+
clearTimeout(counter.timer);
|
|
58
|
+
counter.timer = setTimeout(() => __classPrivateFieldGet(this, _DropRegistry_instances, "m", _DropRegistry_report).call(this, sinkId, cause, counter), QUIESCE_MS);
|
|
59
|
+
// A pending drop report must never be the reason a process stays alive.
|
|
60
|
+
counter.timer.unref?.();
|
|
61
|
+
}
|
|
62
|
+
/** Lifetime total for a (sink, cause) pair. */
|
|
63
|
+
total(sinkId, cause) {
|
|
64
|
+
return __classPrivateFieldGet(this, _DropRegistry_counters, "f").get(`${sinkId}\x00${cause}`)?.total ?? 0;
|
|
65
|
+
}
|
|
66
|
+
/** Emit any outstanding reports immediately — used at shutdown so a run that
|
|
67
|
+
* ends while still dropping does not lose its final accounting. */
|
|
68
|
+
reportPending() {
|
|
69
|
+
for (const [key, counter] of __classPrivateFieldGet(this, _DropRegistry_counters, "f")) {
|
|
70
|
+
if (counter.total === counter.reported)
|
|
71
|
+
continue;
|
|
72
|
+
const [sinkId, cause] = key.split("\x00");
|
|
73
|
+
__classPrivateFieldGet(this, _DropRegistry_instances, "m", _DropRegistry_report).call(this, sinkId, cause, counter);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
dispose() {
|
|
77
|
+
for (const counter of __classPrivateFieldGet(this, _DropRegistry_counters, "f").values()) {
|
|
78
|
+
if (counter.timer)
|
|
79
|
+
clearTimeout(counter.timer);
|
|
80
|
+
counter.timer = undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_DropRegistry_counters = new WeakMap(), _DropRegistry_onRecovered = new WeakMap(), _DropRegistry_reporting = new WeakMap(), _DropRegistry_instances = new WeakSet(), _DropRegistry_report = function _DropRegistry_report(sinkId, cause, counter) {
|
|
85
|
+
counter.timer = undefined;
|
|
86
|
+
const count = counter.total - counter.reported;
|
|
87
|
+
if (count <= 0)
|
|
88
|
+
return;
|
|
89
|
+
counter.reported = counter.total;
|
|
90
|
+
__classPrivateFieldSet(this, _DropRegistry_reporting, true, "f");
|
|
91
|
+
try {
|
|
92
|
+
__classPrivateFieldGet(this, _DropRegistry_onRecovered, "f").call(this, { sinkId, cause, count, total: counter.total });
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
__classPrivateFieldSet(this, _DropRegistry_reporting, false, "f");
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=drop-accounting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-accounting.js","sourceRoot":"","sources":["../../src/logging/drop-accounting.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA;;;;;;;;;GASG;AAEH;wDACwD;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C,6EAA6E;AAC7E,MAAM,UAAU,GAAG,IAAI,CAAC;AAmBxB,MAAM,OAAO,YAAY;IAOvB,YAAY,WAAyC;;QAN5C,iCAAY,IAAI,GAAG,EAAmB,EAAC;QACvC,4CAA2C;QACpD;wCACgC;QAChC,kCAAa,KAAK,EAAC;QAGjB,uBAAA,IAAI,6BAAgB,WAAW,MAAA,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,MAAc,EA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AI,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,QAAQ;gBAAE,SAAS;YACjD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAwB,CAAC;YACjE,uBAAA,IAAI,qDAAQ,MAAZ,IAAI,EAAS,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,MAAM,OAAO,IAAI,uBAAA,IAAI,8BAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YAC9C,IAAI,OAAO,CAAC,KAAK;gBAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC/C,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;QAC5B,CAAC;IACH,CAAC;CAcF;0NAZS,MAAc,EAAE,KAAgB,EAAE,OAAgB;IACxD,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC/C,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO;IACvB,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IACjC,uBAAA,IAAI,2BAAc,IAAI,MAAA,CAAC;IACvB,IAAI,CAAC;QACH,uBAAA,IAAI,iCAAa,MAAjB,IAAI,EAAc,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACpE,CAAC;YAAS,CAAC;QACT,uBAAA,IAAI,2BAAc,KAAK,MAAA,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AnyValue, type LogRecord } from "@telorun/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The `json` encoding — `kernel/specs/logging.md` §11.1. One JSON object per
|
|
4
|
+
* line, UTF-8, newline-terminated.
|
|
5
|
+
*
|
|
6
|
+
* No de-facto cross-ecosystem standard exists for key names, so Telo defines its
|
|
7
|
+
* own profile and keeps OTLP as a separate one. Keys are emitted in the §11.1
|
|
8
|
+
* order for diffability, and extension data belongs in `attributes` — unknown
|
|
9
|
+
* top-level keys are never emitted.
|
|
10
|
+
*/
|
|
11
|
+
/** How a `bytes` attribute is rendered. Raw bytes are never inlined into a text
|
|
12
|
+
* encoding: a sink with a blob store offloads them to a pointer, and every
|
|
13
|
+
* other sink base64-encodes (§6.1). */
|
|
14
|
+
export type BytesEncoder = (bytes: Uint8Array) => AnyValue;
|
|
15
|
+
export declare const base64Bytes: BytesEncoder;
|
|
16
|
+
export interface JsonEncodeOptions {
|
|
17
|
+
encodeBytes?: BytesEncoder;
|
|
18
|
+
}
|
|
19
|
+
/** Encode one record as a newline-terminated JSON line. */
|
|
20
|
+
export declare function encodeJsonLine(record: LogRecord, options?: JsonEncodeOptions): string;
|
|
21
|
+
/** Encode one record as a JSON object, without the trailing newline — the shape
|
|
22
|
+
* the debug wire nests inside its `record` frame (§11.4). */
|
|
23
|
+
export declare function encodeJson(record: LogRecord, options?: JsonEncodeOptions): string;
|
|
24
|
+
/** The §11.1 key profile as a plain object, in the recommended order. Exposed
|
|
25
|
+
* separately because the debug wire embeds the same profile rather than
|
|
26
|
+
* re-deriving it. */
|
|
27
|
+
export declare function toJsonProfile(record: LogRecord): Record<string, unknown>;
|
|
28
|
+
//# sourceMappingURL=encode-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-json.d.ts","sourceRoot":"","sources":["../../src/logging/encode-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAmB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9F;;;;;;;;GAQG;AAEH;;wCAEwC;AACxC,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,QAAQ,CAAC;AAE3D,eAAO,MAAM,WAAW,EAAE,YAA+D,CAAC;AAE1F,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAEzF;AAED;8DAC8D;AAC9D,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAErF;AAED;;sBAEsB;AACtB,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA+BxE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { formatUnixNano } from "@telorun/sdk";
|
|
2
|
+
export const base64Bytes = (bytes) => Buffer.from(bytes).toString("base64");
|
|
3
|
+
/** Encode one record as a newline-terminated JSON line. */
|
|
4
|
+
export function encodeJsonLine(record, options = {}) {
|
|
5
|
+
return `${encodeJson(record, options)}\n`;
|
|
6
|
+
}
|
|
7
|
+
/** Encode one record as a JSON object, without the trailing newline — the shape
|
|
8
|
+
* the debug wire nests inside its `record` frame (§11.4). */
|
|
9
|
+
export function encodeJson(record, options = {}) {
|
|
10
|
+
return JSON.stringify(toJsonProfile(record), makeReplacer(options.encodeBytes ?? base64Bytes));
|
|
11
|
+
}
|
|
12
|
+
/** The §11.1 key profile as a plain object, in the recommended order. Exposed
|
|
13
|
+
* separately because the debug wire embeds the same profile rather than
|
|
14
|
+
* re-deriving it. */
|
|
15
|
+
export function toJsonProfile(record) {
|
|
16
|
+
const out = {
|
|
17
|
+
time: formatUnixNano(record.timestamp),
|
|
18
|
+
level: record.severityText.toUpperCase(),
|
|
19
|
+
severity: record.severityNumber,
|
|
20
|
+
msg: record.message,
|
|
21
|
+
};
|
|
22
|
+
// `observed_timestamp` is deliberately NOT emitted: §11.1 defines a closed key
|
|
23
|
+
// set and forbids extra top-level keys, and §17's schema is
|
|
24
|
+
// `additionalProperties: false`. The field survives on the record model and in
|
|
25
|
+
// the `otlp` profile, which has a real `observedTimeUnixNano` slot for it.
|
|
26
|
+
if (record.traceId !== undefined)
|
|
27
|
+
out["trace_id"] = record.traceId;
|
|
28
|
+
if (record.spanId !== undefined)
|
|
29
|
+
out["span_id"] = record.spanId;
|
|
30
|
+
if (record.traceFlags !== undefined)
|
|
31
|
+
out["trace_flags"] = record.traceFlags;
|
|
32
|
+
if (record.resource !== undefined)
|
|
33
|
+
out["resource"] = record.resource;
|
|
34
|
+
if (record.module !== undefined)
|
|
35
|
+
out["module"] = record.module;
|
|
36
|
+
if (record.scope !== undefined)
|
|
37
|
+
out["scope"] = record.scope;
|
|
38
|
+
// Nested, never flattened — flattening risks collision with reserved keys.
|
|
39
|
+
// Emitted with keys in sorted (code-point) order so the `json` encoding is
|
|
40
|
+
// byte-identical across runtimes (§16 vector 18): attribute keys are arbitrary
|
|
41
|
+
// user data with no natural order, and sorted is the only order both this
|
|
42
|
+
// runtime and a Rust `BTreeMap`-backed one produce without extra config.
|
|
43
|
+
if (record.attributes !== undefined)
|
|
44
|
+
out["attributes"] = sortKeysDeep(record.attributes);
|
|
45
|
+
if (record.error !== undefined)
|
|
46
|
+
out["err"] = record.error;
|
|
47
|
+
if (record.eventName !== undefined)
|
|
48
|
+
out["event_name"] = record.eventName;
|
|
49
|
+
if (record.droppedAttributesCount) {
|
|
50
|
+
out["dropped_attributes_count"] = record.droppedAttributesCount;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/** Rebuild an attribute value with every nested object's keys in sorted order.
|
|
55
|
+
* `JSON.stringify` emits string keys in insertion order, so reconstructing the
|
|
56
|
+
* object with sorted insertion is what pins the byte order. Arrays keep their
|
|
57
|
+
* index order; `Uint8Array` is a leaf. The attributes are already normalized
|
|
58
|
+
* (§6.3), so depth and breadth are bounded and this cannot diverge. */
|
|
59
|
+
function sortKeysDeep(value) {
|
|
60
|
+
if (value === null || typeof value !== "object")
|
|
61
|
+
return value;
|
|
62
|
+
if (value instanceof Uint8Array)
|
|
63
|
+
return value;
|
|
64
|
+
if (Array.isArray(value))
|
|
65
|
+
return value.map(sortKeysDeep);
|
|
66
|
+
const sorted = {};
|
|
67
|
+
for (const key of Object.keys(value).sort())
|
|
68
|
+
sorted[key] = sortKeysDeep(value[key]);
|
|
69
|
+
return sorted;
|
|
70
|
+
}
|
|
71
|
+
function makeReplacer(encodeBytes) {
|
|
72
|
+
return function replacer(_key, value) {
|
|
73
|
+
if (typeof value === "bigint") {
|
|
74
|
+
// Values beyond 2^53 lose precision in a JS receiver, so they degrade to a
|
|
75
|
+
// decimal string rather than to a wrong number — the same reasoning OTLP
|
|
76
|
+
// gives for quoting its 64-bit fields.
|
|
77
|
+
return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER)
|
|
78
|
+
? Number(value)
|
|
79
|
+
: value.toString();
|
|
80
|
+
}
|
|
81
|
+
if (value instanceof Uint8Array)
|
|
82
|
+
return encodeBytes(value);
|
|
83
|
+
return value;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=encode-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-json.js","sourceRoot":"","sources":["../../src/logging/encode-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAkD,MAAM,cAAc,CAAC;AAiB9F,MAAM,CAAC,MAAM,WAAW,GAAiB,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAM1F,2DAA2D;AAC3D,MAAM,UAAU,cAAc,CAAC,MAAiB,EAAE,UAA6B,EAAE;IAC/E,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED;8DAC8D;AAC9D,MAAM,UAAU,UAAU,C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I,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;gBACzF,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBACf,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACvB,CAAC;QACD,IAAI,KAAK,YAAY,UAAU;YAAE,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type LogRecord } from "@telorun/sdk";
|
|
2
|
+
export interface PrettyEncodeOptions {
|
|
3
|
+
color: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function encodePrettyLine(record: LogRecord, options: PrettyEncodeOptions): string;
|
|
6
|
+
export declare function encodePretty(record: LogRecord, options: PrettyEncodeOptions): string;
|
|
7
|
+
//# sourceMappingURL=encode-pretty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-pretty.d.ts","sourceRoot":"","sources":["../../src/logging/encode-pretty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AA2B7F,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAExF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA+BpF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { severityFloor } from "@telorun/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* The `pretty` encoding — `kernel/specs/logging.md` §11.2. For humans on a
|
|
4
|
+
* terminal:
|
|
5
|
+
*
|
|
6
|
+
* 12:34:56.789 INFO Http.Server.api listening net.host.port=8080
|
|
7
|
+
*
|
|
8
|
+
* The color table is a modal synthesis across pino-pretty, zap, tint,
|
|
9
|
+
* tracing-subscriber, consola, and winston, which do not fully agree — zap alone
|
|
10
|
+
* uses magenta for DEBUG and blue for INFO, and TRACE has no consensus. It is a
|
|
11
|
+
* deliberate choice, not a standard.
|
|
12
|
+
*/
|
|
13
|
+
const RESET = "\u001b[0m";
|
|
14
|
+
const LEVEL_COLOR = {
|
|
15
|
+
1: "\u001b[2m", // TRACE — dim
|
|
16
|
+
5: "\u001b[34m", // DEBUG — blue
|
|
17
|
+
9: "\u001b[32m", // INFO — green
|
|
18
|
+
13: "\u001b[33m", // WARN — yellow
|
|
19
|
+
17: "\u001b[31m", // ERROR — red
|
|
20
|
+
21: "\u001b[1;41m", // FATAL — bold, red background
|
|
21
|
+
};
|
|
22
|
+
const DIM = "\u001b[2m";
|
|
23
|
+
export function encodePrettyLine(record, options) {
|
|
24
|
+
return `${encodePretty(record, options)}\n`;
|
|
25
|
+
}
|
|
26
|
+
export function encodePretty(record, options) {
|
|
27
|
+
const paint = options.color
|
|
28
|
+
? (code, text) => `${code}${text}${RESET}`
|
|
29
|
+
: (_code, text) => text;
|
|
30
|
+
const parts = [
|
|
31
|
+
formatLocalTime(record.timestamp),
|
|
32
|
+
paint(LEVEL_COLOR[severityFloor(record.severityNumber)], record.severityText.padEnd(5)),
|
|
33
|
+
];
|
|
34
|
+
if (record.resource)
|
|
35
|
+
parts.push(`${record.resource.kind}.${record.resource.name}`);
|
|
36
|
+
// The message itself is never colored by level — only the level token is.
|
|
37
|
+
parts.push(record.message);
|
|
38
|
+
const attributes = record.attributes;
|
|
39
|
+
if (attributes) {
|
|
40
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
41
|
+
parts.push(`${paint(DIM, key)}=${formatAttributeValue(value)}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (record.droppedAttributesCount) {
|
|
45
|
+
parts.push(`${paint(DIM, "dropped_attributes_count")}=${record.droppedAttributesCount}`);
|
|
46
|
+
}
|
|
47
|
+
let line = parts.join(" ");
|
|
48
|
+
if (record.error)
|
|
49
|
+
line += `\n${formatError(record.error, paint)}`;
|
|
50
|
+
return line;
|
|
51
|
+
}
|
|
52
|
+
/** `HH:MM:ss.SSS`, local timezone. Millisecond resolution: the sub-millisecond
|
|
53
|
+
* digits of the record's nanosecond timestamp are noise on a console line. */
|
|
54
|
+
function formatLocalTime(timestamp) {
|
|
55
|
+
const date = new Date(Number(timestamp / 1000000n));
|
|
56
|
+
const hh = String(date.getHours()).padStart(2, "0");
|
|
57
|
+
const mm = String(date.getMinutes()).padStart(2, "0");
|
|
58
|
+
const ss = String(date.getSeconds()).padStart(2, "0");
|
|
59
|
+
const ms = String(date.getMilliseconds()).padStart(3, "0");
|
|
60
|
+
return `${hh}:${mm}:${ss}.${ms}`;
|
|
61
|
+
}
|
|
62
|
+
function formatAttributeValue(value) {
|
|
63
|
+
if (value === null)
|
|
64
|
+
return "null";
|
|
65
|
+
if (value instanceof Uint8Array)
|
|
66
|
+
return `<${value.byteLength} bytes>`;
|
|
67
|
+
if (typeof value === "object")
|
|
68
|
+
return quoteIfNeeded(JSON.stringify(value, jsonSafe));
|
|
69
|
+
return quoteIfNeeded(String(value));
|
|
70
|
+
}
|
|
71
|
+
/** Values containing whitespace, `"`, or `=` must be quoted so the `key=value`
|
|
72
|
+
* stream stays unambiguously parseable by eye. */
|
|
73
|
+
function quoteIfNeeded(text) {
|
|
74
|
+
return /[\s"=]/.test(text) ? JSON.stringify(text) : text;
|
|
75
|
+
}
|
|
76
|
+
function jsonSafe(_key, value) {
|
|
77
|
+
if (typeof value === "bigint")
|
|
78
|
+
return value.toString();
|
|
79
|
+
if (value instanceof Uint8Array)
|
|
80
|
+
return `<${value.byteLength} bytes>`;
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
/** Errors render after the message; the stack goes on following lines,
|
|
84
|
+
* indented, unmodified. The `cause` chain follows, already bounded by §6.3. */
|
|
85
|
+
function formatError(error, paint) {
|
|
86
|
+
const lines = [` ${paint(LEVEL_COLOR[17], error.type)}: ${error.message}`];
|
|
87
|
+
if (error.stack) {
|
|
88
|
+
for (const line of error.stack.split("\n"))
|
|
89
|
+
lines.push(` ${line}`);
|
|
90
|
+
}
|
|
91
|
+
let cause = error.cause;
|
|
92
|
+
let guard = 0;
|
|
93
|
+
while (cause && guard < 16) {
|
|
94
|
+
lines.push(` ${paint(DIM, "caused by")} ${cause.type}: ${cause.message}`);
|
|
95
|
+
if (cause.stack) {
|
|
96
|
+
for (const line of cause.stack.split("\n"))
|
|
97
|
+
lines.push(` ${line}`);
|
|
98
|
+
}
|
|
99
|
+
cause = cause.cause;
|
|
100
|
+
guard += 1;
|
|
101
|
+
}
|
|
102
|
+
return lines.join("\n");
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=encode-pretty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-pretty.js","sourceRoot":"","sources":["../../src/logging/encode-pretty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkD,MAAM,cAAc,CAAC;AAE7F;;;;;;;;;;GAUG;AAEH,MAAM,KAAK,GAAG,WAAW,CAAC;AAE1B,MAAM,WAAW,GAAqC;IACpD,CAAC,EAAE,WAAW,EAAE,cAAc;IAC9B,CAAC,EAAE,YAAY,EAAE,eAAe;IAChC,CAAC,EAAE,YAAY,EAAE,eAAe;IAChC,EAAE,EAAE,YAAY,EAAE,gBAAgB;IAClC,EAAE,EAAE,YAAY,EAAE,cAAc;IAChC,EAAE,EAAE,cAAc,EAAE,+BAA+B;CACpD,CAAC;AAEF,MAAM,GAAG,GAAG,WAAW,CAAC;AAMxB,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,OAA4B;IAC9E,OAAO,GAAG,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAiB,EAAE,OAA4B;IAC1E,MAAM,KAAK,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D,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LogRecord } from "@telorun/sdk";
|
|
2
|
+
import { type BytesEncoder } from "./encode-json.js";
|
|
3
|
+
import { type LogSinkInstance, type SinkBufferPolicy } from "./log-sink.js";
|
|
4
|
+
/**
|
|
5
|
+
* `Telo.FileSink` — a kernel built-in (§10.2). Asynchronous, `json` by default.
|
|
6
|
+
*
|
|
7
|
+
* Sync-flushable: a positional write is available on every target platform, so a
|
|
8
|
+
* `fatal` record is durable by the time `log()` returns. That is what makes the
|
|
9
|
+
* file sink a legitimate audit destination while an OTLP sink is not — delivery
|
|
10
|
+
* there is a network round-trip that cannot complete without yielding.
|
|
11
|
+
*/
|
|
12
|
+
export type FileEncoding = "json" | "pretty";
|
|
13
|
+
export interface FileSinkOptions {
|
|
14
|
+
sinkId: string;
|
|
15
|
+
level: number;
|
|
16
|
+
destination: string;
|
|
17
|
+
encoding?: FileEncoding;
|
|
18
|
+
policy?: SinkBufferPolicy;
|
|
19
|
+
onDrop: () => void;
|
|
20
|
+
encodeBytes?: BytesEncoder;
|
|
21
|
+
}
|
|
22
|
+
export declare class FileSink implements LogSinkInstance {
|
|
23
|
+
#private;
|
|
24
|
+
readonly sinkId: string;
|
|
25
|
+
readonly level: number;
|
|
26
|
+
readonly syncFlushable = true;
|
|
27
|
+
constructor(options: FileSinkOptions);
|
|
28
|
+
write(record: LogRecord): void;
|
|
29
|
+
flush(): Promise<void>;
|
|
30
|
+
flushSync(): void;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=file-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-sink.d.ts","sourceRoot":"","sources":["../../src/logging/file-sink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAyB,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGnG;;;;;;;GAOG;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7C,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B;AAED,qBAAa,QAAS,YAAW,eAAe;;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,QAAQ;gBAQlB,OAAO,EAAE,eAAe;IAmBpC,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAKxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,SAAS,IAAI,IAAI;IASX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
|