@adjudicate/observability 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecosystem-telemetry.js","sourceRoot":"","sources":["../src/ecosystem-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAgKH,MAAM,QAAQ,GAAwC;IACpD,WAAW,EAAE,GAAG;IAChB,kBAAkB,EAAE,EAAE;IACtB,eAAe,EAAE,GAAG;IACpB,gBAAgB,EAAE,GAAG;IACrB,kBAAkB,EAAE,GAAG;IACvB,cAAc,EAAE,EAAE;CACnB,CAAC;AAEF,MAAM,QAAQ,GAAG,cAAuB,CAAC;AAEzC;;;;GAIG;AACH,MAAM,cAAc;IAEW;IADZ,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACjD,YAA6B,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAE5C,GAAG,CAAC,GAAW,EAAE,KAAK,GAAG,CAAC;QACxB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;YACpD,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAA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CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC7D,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/E,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAChC,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Exporter — the single seam through which `@adjudicate/observability` emits
3
+ * events. Consumers wire this to an OpenTelemetry-backed exporter (OTLP/proto,
4
+ * OTLP/http, the gRPC SDK) at boot. Tests inject `createInMemoryExporter()`.
5
+ *
6
+ * Why a custom interface rather than `@opentelemetry/sdk-trace-base`'s
7
+ * `SpanExporter` directly:
8
+ *
9
+ * - Metrics, learning events, and audit spans share a single funnel. A
10
+ * single `export(event)` keeps the three sinks behind a uniform contract
11
+ * and lets adopters install one transport for the whole subsystem.
12
+ *
13
+ * - The OpenTelemetry packages are not pinned by this package — we declare
14
+ * `@opentelemetry/api ^1.9.0` as a runtime dep so consumers control the
15
+ * trace/metric SDK choice. Pinning the full SDK here would force every
16
+ * adopter onto our version.
17
+ *
18
+ * - Kernel determinism is sacred. By funneling through this interface,
19
+ * observability never reaches into the kernel — it only receives copies
20
+ * of events the kernel already emitted via its existing sinks.
21
+ */
22
+ import type { SEMCONV } from "./semconv.js";
23
+ /**
24
+ * Event categories emitted by the three sinks. Carried as a discriminant so a
25
+ * single exporter can route per-kind (e.g. metrics → meter, spans → tracer).
26
+ */
27
+ export type ExportedEventKind = "metrics.decision" | "metrics.refusal" | "metrics.ledger" | "metrics.sink_failure" | "metrics.shadow_divergence" | "metrics.resource_limit" | "learning.outcome" | "audit.span";
28
+ /**
29
+ * One observability emission. Attributes carry the wire-shape an OTLP
30
+ * exporter would use; the `name` field is the metric name or span name.
31
+ * `body` is reserved for events with structured payloads (e.g., the full
32
+ * AuditRecord — exporters may strip or sample it).
33
+ */
34
+ export interface ExportedEvent {
35
+ readonly kind: ExportedEventKind;
36
+ readonly name: string;
37
+ readonly at: string;
38
+ readonly attributes: Readonly<Record<(typeof SEMCONV)[keyof typeof SEMCONV] | string, string | number | boolean | undefined>>;
39
+ /** Optional structured body — present only on `audit.span` and `learning.outcome`. */
40
+ readonly body?: unknown;
41
+ }
42
+ /**
43
+ * The single seam. Implementations MUST NOT throw — observability is best-
44
+ * effort, never a customer outage. Synchronous so the kernel-adjacent sinks
45
+ * stay non-async; real OTLP transports buffer internally and flush off the
46
+ * hot path.
47
+ */
48
+ export interface Exporter {
49
+ export(event: ExportedEvent): void;
50
+ }
51
+ /**
52
+ * In-memory test exporter. Captures every event into a mutable array so
53
+ * tests can assert "the right events were emitted with the right semconv
54
+ * attributes." Returned alongside its event buffer so the test doesn't
55
+ * have to read out of an opaque handle.
56
+ */
57
+ export interface InMemoryExporter {
58
+ readonly exporter: Exporter;
59
+ readonly events: ExportedEvent[];
60
+ }
61
+ export declare function createInMemoryExporter(): InMemoryExporter;
62
+ /**
63
+ * No-op exporter. Useful when an adopter wants to wire up the sinks early
64
+ * (e.g., during boot, before the OTLP transport is configured) without
65
+ * paying for any allocation. Production deployments should NOT install
66
+ * this — emission would be silent.
67
+ */
68
+ export declare function noopExporter(): Exporter;
69
+ //# sourceMappingURL=exporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,sBAAsB,GACtB,2BAA2B,GAC3B,wBAAwB,GACxB,kBAAkB,GAClB,YAAY,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAC3B,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAC/F,CAAC;IACF,sFAAsF;IACtF,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;CACpC;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAQzD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAMvC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Exporter — the single seam through which `@adjudicate/observability` emits
3
+ * events. Consumers wire this to an OpenTelemetry-backed exporter (OTLP/proto,
4
+ * OTLP/http, the gRPC SDK) at boot. Tests inject `createInMemoryExporter()`.
5
+ *
6
+ * Why a custom interface rather than `@opentelemetry/sdk-trace-base`'s
7
+ * `SpanExporter` directly:
8
+ *
9
+ * - Metrics, learning events, and audit spans share a single funnel. A
10
+ * single `export(event)` keeps the three sinks behind a uniform contract
11
+ * and lets adopters install one transport for the whole subsystem.
12
+ *
13
+ * - The OpenTelemetry packages are not pinned by this package — we declare
14
+ * `@opentelemetry/api ^1.9.0` as a runtime dep so consumers control the
15
+ * trace/metric SDK choice. Pinning the full SDK here would force every
16
+ * adopter onto our version.
17
+ *
18
+ * - Kernel determinism is sacred. By funneling through this interface,
19
+ * observability never reaches into the kernel — it only receives copies
20
+ * of events the kernel already emitted via its existing sinks.
21
+ */
22
+ export function createInMemoryExporter() {
23
+ const events = [];
24
+ const exporter = {
25
+ export(event) {
26
+ events.push(event);
27
+ },
28
+ };
29
+ return { exporter, events };
30
+ }
31
+ /**
32
+ * No-op exporter. Useful when an adopter wants to wire up the sinks early
33
+ * (e.g., during boot, before the OTLP transport is configured) without
34
+ * paying for any allocation. Production deployments should NOT install
35
+ * this — emission would be silent.
36
+ */
37
+ export function noopExporter() {
38
+ return {
39
+ export() {
40
+ /* intentional no-op */
41
+ },
42
+ };
43
+ }
44
+ //# sourceMappingURL=exporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.js","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAwDH,MAAM,UAAU,sBAAsB;IACpC,MAAM,MAAM,GAAoB,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAa;QACzB,MAAM,CAAC,KAAK;YACV,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,MAAM;YACJ,uBAAuB;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @adjudicate/observability — OTLP-native sinks for the kernel's three
3
+ * telemetry surfaces (metrics, learning, audit).
4
+ *
5
+ * The package adapts the kernel's existing sink contracts (`MetricsSink`,
6
+ * `LearningSink`, `AuditSink`) onto a single `Exporter` interface that the
7
+ * adopter wires to an OpenTelemetry transport. The kernel itself is
8
+ * untouched — observability is OPTIONAL plumbing and MUST NEVER affect a
9
+ * Decision outcome. If the exporter throws, the sink swallows the error;
10
+ * if the exporter is misconfigured, telemetry is silent but adjudication
11
+ * still runs.
12
+ *
13
+ * # Why a custom Exporter and not OTLP SDKs directly
14
+ *
15
+ * The OTLP exporters in `@opentelemetry/exporter-trace-otlp-proto` are
16
+ * span-oriented and pull in a transport stack. By funneling all three
17
+ * adjudicate sinks through one in-process `Exporter`, adopters can:
18
+ *
19
+ * - Wire one OTLP/proto transport for the whole subsystem
20
+ * - Or stay on a no-op transport in environments without an OTel collector
21
+ * - Or capture events into an in-memory buffer for tests
22
+ *
23
+ * The `@opentelemetry/api` package is the only OTel dependency we pull in;
24
+ * it is metadata-only (interfaces) and adds no runtime weight.
25
+ *
26
+ * # Layout
27
+ *
28
+ * - `exporter.ts` Exporter interface + InMemoryExporter for tests
29
+ * - `semconv.ts` Stable attribute names (`adjudicate.*`)
30
+ * - `metrics.ts` createOtlpMetricsSink → MetricsSink
31
+ * - `learning.ts` createOtlpLearningSink → LearningSink
32
+ * - `audit-spans.ts` createOtlpAuditSpanExporter → AuditSink wrapper
33
+ */
34
+ export { type Exporter, type ExportedEvent, type ExportedEventKind, type InMemoryExporter, createInMemoryExporter, noopExporter, } from "./exporter.js";
35
+ export { SEMCONV, type SemconvAttribute, type SemconvKey } from "./semconv.js";
36
+ export { createOtlpMetricsSink, type OtlpMetricsSinkOptions, } from "./metrics.js";
37
+ export { createOtlpLearningSink, type OtlpLearningSinkOptions, } from "./learning.js";
38
+ export { createOtlpAuditSpanExporter, type OtlpAuditSpanExporterOptions, } from "./audit-spans.js";
39
+ export { createEcosystemTelemetry, classifyReplayFailure, serializeEcosystemSnapshot, type EcosystemTelemetry, type EcosystemTelemetryOptions, type EcosystemTelemetrySnapshot, type PackEcosystemSnapshot, type DecisionDistributionSnapshot, type ReplayFailureSnapshot, type ReplayFailureClass, type AnalyzerTriageSnapshot, type AnalyzerTriageOutcome, type SemconvAdoptionSnapshot, type MigrationPainSnapshot, type IncidentSnapshot, type OperationalIncidentClass, } from "./ecosystem-telemetry.js";
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,2BAA2B,EAC3B,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,GAC9B,MAAM,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @adjudicate/observability — OTLP-native sinks for the kernel's three
3
+ * telemetry surfaces (metrics, learning, audit).
4
+ *
5
+ * The package adapts the kernel's existing sink contracts (`MetricsSink`,
6
+ * `LearningSink`, `AuditSink`) onto a single `Exporter` interface that the
7
+ * adopter wires to an OpenTelemetry transport. The kernel itself is
8
+ * untouched — observability is OPTIONAL plumbing and MUST NEVER affect a
9
+ * Decision outcome. If the exporter throws, the sink swallows the error;
10
+ * if the exporter is misconfigured, telemetry is silent but adjudication
11
+ * still runs.
12
+ *
13
+ * # Why a custom Exporter and not OTLP SDKs directly
14
+ *
15
+ * The OTLP exporters in `@opentelemetry/exporter-trace-otlp-proto` are
16
+ * span-oriented and pull in a transport stack. By funneling all three
17
+ * adjudicate sinks through one in-process `Exporter`, adopters can:
18
+ *
19
+ * - Wire one OTLP/proto transport for the whole subsystem
20
+ * - Or stay on a no-op transport in environments without an OTel collector
21
+ * - Or capture events into an in-memory buffer for tests
22
+ *
23
+ * The `@opentelemetry/api` package is the only OTel dependency we pull in;
24
+ * it is metadata-only (interfaces) and adds no runtime weight.
25
+ *
26
+ * # Layout
27
+ *
28
+ * - `exporter.ts` Exporter interface + InMemoryExporter for tests
29
+ * - `semconv.ts` Stable attribute names (`adjudicate.*`)
30
+ * - `metrics.ts` createOtlpMetricsSink → MetricsSink
31
+ * - `learning.ts` createOtlpLearningSink → LearningSink
32
+ * - `audit-spans.ts` createOtlpAuditSpanExporter → AuditSink wrapper
33
+ */
34
+ export { createInMemoryExporter, noopExporter, } from "./exporter.js";
35
+ export { SEMCONV } from "./semconv.js";
36
+ export { createOtlpMetricsSink, } from "./metrics.js";
37
+ export { createOtlpLearningSink, } from "./learning.js";
38
+ export { createOtlpAuditSpanExporter, } from "./audit-spans.js";
39
+ // Post-v1 ecosystem-telemetry primitive — opt-in, local-first, deterministic.
40
+ // Adopters compose this aggregator alongside their sinks to produce
41
+ // JSON-stable evidence snapshots. The framework never instantiates it.
42
+ export { createEcosystemTelemetry, classifyReplayFailure, serializeEcosystemSnapshot, } from "./ecosystem-telemetry.js";
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAKL,sBAAsB,EACtB,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,OAAO,EAA0C,MAAM,cAAc,CAAC;AAE/E,OAAO,EACL,qBAAqB,GAEtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,GAEvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,2BAA2B,GAE5B,MAAM,kBAAkB,CAAC;AAE1B,8EAA8E;AAC9E,oEAAoE;AACpE,uEAAuE;AACvE,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,0BAA0B,GAc3B,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * OTLP-shaped LearningSink.
3
+ *
4
+ * Adopters install this when they want adjudication outcomes routed to a
5
+ * downstream analytics warehouse via the OTLP pipeline (e.g., a collector
6
+ * that fans out to BigQuery / Snowflake / Honeycomb). The sink emits a
7
+ * structured `learning.outcome` event per Decision; the exporter is
8
+ * responsible for shaping it onto the destination's wire format.
9
+ *
10
+ * Learning events are richer than metrics — they carry `basisCodes`,
11
+ * `planFingerprint`, and guard identity — so the `body` field carries the
12
+ * full LearningEvent. Attributes mirror the headline fields for partition
13
+ * keys.
14
+ *
15
+ * Wiring:
16
+ *
17
+ * import { setLearningSink } from "@adjudicate/core/kernel";
18
+ * import { createOtlpLearningSink } from "@adjudicate/observability";
19
+ *
20
+ * setLearningSink(createOtlpLearningSink({ exporter }));
21
+ */
22
+ import type { LearningSink } from "@adjudicate/core/kernel";
23
+ import type { Exporter } from "./exporter.js";
24
+ export interface OtlpLearningSinkOptions {
25
+ readonly exporter: Exporter;
26
+ /** Optional Pack identifier stamped on every event. */
27
+ readonly packId?: string;
28
+ /** Optional Pack policy version stamped on every event. */
29
+ readonly policyVersion?: string;
30
+ }
31
+ export declare function createOtlpLearningSink(opts: OtlpLearningSinkOptions): LearningSink;
32
+ //# sourceMappingURL=learning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning.d.ts","sourceRoot":"","sources":["../src/learning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAG7D,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,uBAAuB,GAC5B,YAAY,CAqCd"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * OTLP-shaped LearningSink.
3
+ *
4
+ * Adopters install this when they want adjudication outcomes routed to a
5
+ * downstream analytics warehouse via the OTLP pipeline (e.g., a collector
6
+ * that fans out to BigQuery / Snowflake / Honeycomb). The sink emits a
7
+ * structured `learning.outcome` event per Decision; the exporter is
8
+ * responsible for shaping it onto the destination's wire format.
9
+ *
10
+ * Learning events are richer than metrics — they carry `basisCodes`,
11
+ * `planFingerprint`, and guard identity — so the `body` field carries the
12
+ * full LearningEvent. Attributes mirror the headline fields for partition
13
+ * keys.
14
+ *
15
+ * Wiring:
16
+ *
17
+ * import { setLearningSink } from "@adjudicate/core/kernel";
18
+ * import { createOtlpLearningSink } from "@adjudicate/observability";
19
+ *
20
+ * setLearningSink(createOtlpLearningSink({ exporter }));
21
+ */
22
+ import { SEMCONV } from "./semconv.js";
23
+ export function createOtlpLearningSink(opts) {
24
+ return {
25
+ recordOutcome(event) {
26
+ const exported = {
27
+ kind: "learning.outcome",
28
+ name: "adjudicate.learning.outcome",
29
+ at: event.at,
30
+ attributes: {
31
+ [SEMCONV.INTENT_KIND]: event.intentKind,
32
+ [SEMCONV.DECISION_KIND]: event.decisionKind,
33
+ [SEMCONV.TAINT]: event.taint,
34
+ [SEMCONV.LATENCY_MS]: event.durationMs,
35
+ [SEMCONV.INTENT_HASH]: event.intentHash,
36
+ ...(event.guardId !== undefined
37
+ ? { [SEMCONV.GUARD_ID]: event.guardId }
38
+ : {}),
39
+ ...(event.guardPhase !== undefined
40
+ ? { "adjudicate.guard.phase": event.guardPhase }
41
+ : {}),
42
+ ...(event.planFingerprint !== undefined
43
+ ? { "adjudicate.plan.fingerprint": event.planFingerprint }
44
+ : {}),
45
+ ...(opts.packId !== undefined ? { [SEMCONV.PACK_ID]: opts.packId } : {}),
46
+ ...(opts.policyVersion !== undefined
47
+ ? { [SEMCONV.POLICY_VERSION]: opts.policyVersion }
48
+ : {}),
49
+ },
50
+ // Full LearningEvent for warehouses that ingest event bodies.
51
+ body: event,
52
+ };
53
+ try {
54
+ opts.exporter.export(exported);
55
+ }
56
+ catch {
57
+ /* swallow — sink failures must not affect Decisions. */
58
+ }
59
+ },
60
+ };
61
+ }
62
+ //# sourceMappingURL=learning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning.js","sourceRoot":"","sources":["../src/learning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAUvC,MAAM,UAAU,sBAAsB,CACpC,IAA6B;IAE7B,OAAO;QACL,aAAa,CAAC,KAAK;YACjB,MAAM,QAAQ,GAAkB;gBAC9B,IAAI,EAAE,kBAAkB;gBACxB,IAAI,EAAE,6BAA6B;gBACnC,EAAE,EAAE,KAAK,CAAC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CAAC,QAAQ,CAAC,CAAC;YACjC,CAAC;YAAC,MAAM,CAAC;gBACP,wDAAwD;YAC1D,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * OTLP-shaped MetricsSink.
3
+ *
4
+ * Wraps `@adjudicate/core/kernel`'s `MetricsSink` contract and emits one
5
+ * `ExportedEvent` per call. The events carry the semantic conventions defined
6
+ * in `semconv.ts`, so an OTLP exporter can map them onto OpenTelemetry meters
7
+ * without losing the kernel's shape.
8
+ *
9
+ * Adopter wiring:
10
+ *
11
+ * import { setMetricsSink } from "@adjudicate/core/kernel";
12
+ * import { createOtlpMetricsSink } from "@adjudicate/observability";
13
+ *
14
+ * setMetricsSink(createOtlpMetricsSink({ exporter: yourOtlpExporter }));
15
+ *
16
+ * The sink itself does no transport — it pushes events into the injected
17
+ * `Exporter`. Real OTLP traffic happens in the adopter-owned exporter.
18
+ */
19
+ import type { MetricsSink } from "@adjudicate/core/kernel";
20
+ import type { Exporter } from "./exporter.js";
21
+ export interface OtlpMetricsSinkOptions {
22
+ readonly exporter: Exporter;
23
+ /** Optional clock — tests inject a fake. */
24
+ readonly clockIso?: () => string;
25
+ /** Optional Pack identifier stamped on every event. */
26
+ readonly packId?: string;
27
+ /** Optional Pack policy version stamped on every event. */
28
+ readonly policyVersion?: string;
29
+ }
30
+ export declare function createOtlpMetricsSink(opts: OtlpMetricsSinkOptions): MetricsSink;
31
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAG7D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAC;IACjC,uDAAuD;IACvD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,WAAW,CA2F/E"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * OTLP-shaped MetricsSink.
3
+ *
4
+ * Wraps `@adjudicate/core/kernel`'s `MetricsSink` contract and emits one
5
+ * `ExportedEvent` per call. The events carry the semantic conventions defined
6
+ * in `semconv.ts`, so an OTLP exporter can map them onto OpenTelemetry meters
7
+ * without losing the kernel's shape.
8
+ *
9
+ * Adopter wiring:
10
+ *
11
+ * import { setMetricsSink } from "@adjudicate/core/kernel";
12
+ * import { createOtlpMetricsSink } from "@adjudicate/observability";
13
+ *
14
+ * setMetricsSink(createOtlpMetricsSink({ exporter: yourOtlpExporter }));
15
+ *
16
+ * The sink itself does no transport — it pushes events into the injected
17
+ * `Exporter`. Real OTLP traffic happens in the adopter-owned exporter.
18
+ */
19
+ import { SEMCONV } from "./semconv.js";
20
+ export function createOtlpMetricsSink(opts) {
21
+ const clockIso = opts.clockIso ?? (() => new Date().toISOString());
22
+ const stamp = stampFactory(opts);
23
+ return {
24
+ recordLedgerOp(event) {
25
+ const exported = {
26
+ kind: "metrics.ledger",
27
+ name: `adjudicate.ledger.${event.op}`,
28
+ at: clockIso(),
29
+ attributes: stamp({
30
+ "adjudicate.ledger.op": event.op,
31
+ "adjudicate.ledger.outcome": event.outcome,
32
+ [SEMCONV.INTENT_KIND]: event.intentKind,
33
+ [SEMCONV.LATENCY_MS]: event.latencyMs,
34
+ }),
35
+ };
36
+ safeExport(opts.exporter, exported);
37
+ },
38
+ recordDecision(event) {
39
+ const exported = {
40
+ kind: "metrics.decision",
41
+ name: "adjudicate.decision",
42
+ at: clockIso(),
43
+ attributes: stamp({
44
+ [SEMCONV.INTENT_KIND]: event.intentKind,
45
+ [SEMCONV.DECISION_KIND]: event.decision,
46
+ [SEMCONV.LATENCY_MS]: event.latencyMs,
47
+ "adjudicate.basis.count": event.basisCount,
48
+ [SEMCONV.INTENT_HASH]: event.intentHash,
49
+ }),
50
+ };
51
+ safeExport(opts.exporter, exported);
52
+ },
53
+ recordRefusal(event) {
54
+ const exported = {
55
+ kind: "metrics.refusal",
56
+ name: "adjudicate.refusal",
57
+ at: clockIso(),
58
+ attributes: stamp({
59
+ [SEMCONV.INTENT_KIND]: event.intentKind,
60
+ "adjudicate.refusal.kind": event.refusal.kind,
61
+ "adjudicate.refusal.code": event.refusal.code,
62
+ [SEMCONV.INTENT_HASH]: event.intentHash,
63
+ }),
64
+ };
65
+ safeExport(opts.exporter, exported);
66
+ },
67
+ recordSinkFailure(event) {
68
+ const exported = {
69
+ kind: "metrics.sink_failure",
70
+ name: "adjudicate.sink_failure",
71
+ at: clockIso(),
72
+ attributes: stamp({
73
+ "adjudicate.sink": event.sink,
74
+ "adjudicate.sink.subject": event.subject,
75
+ "adjudicate.sink.error_class": event.errorClass,
76
+ "adjudicate.sink.consecutive_failures": event.consecutiveFailures,
77
+ }),
78
+ };
79
+ safeExport(opts.exporter, exported);
80
+ },
81
+ recordShadowDivergence(event) {
82
+ const exported = {
83
+ kind: "metrics.shadow_divergence",
84
+ name: "adjudicate.shadow_divergence",
85
+ at: clockIso(),
86
+ attributes: stamp({
87
+ [SEMCONV.INTENT_KIND]: event.intentKind,
88
+ "adjudicate.shadow.divergence": event.divergence,
89
+ "adjudicate.shadow.legacy": event.legacy.kind,
90
+ [SEMCONV.DECISION_KIND]: event.adjudicate.kind,
91
+ }),
92
+ };
93
+ safeExport(opts.exporter, exported);
94
+ },
95
+ recordResourceLimit(event) {
96
+ const exported = {
97
+ kind: "metrics.resource_limit",
98
+ name: "adjudicate.resource_limit",
99
+ at: clockIso(),
100
+ attributes: stamp({
101
+ "adjudicate.resource": event.resource,
102
+ "adjudicate.resource.subject": event.subject,
103
+ "adjudicate.resource.limit": event.limit,
104
+ "adjudicate.resource.observed": event.observed,
105
+ }),
106
+ };
107
+ safeExport(opts.exporter, exported);
108
+ },
109
+ };
110
+ }
111
+ function stampFactory(opts) {
112
+ return (attrs) => ({
113
+ ...attrs,
114
+ ...(opts.packId !== undefined ? { [SEMCONV.PACK_ID]: opts.packId } : {}),
115
+ ...(opts.policyVersion !== undefined
116
+ ? { [SEMCONV.POLICY_VERSION]: opts.policyVersion }
117
+ : {}),
118
+ });
119
+ }
120
+ /**
121
+ * Observability is best-effort. An exporter that throws (misconfigured
122
+ * transport, network blip) must never propagate into the kernel hot path.
123
+ */
124
+ function safeExport(exporter, event) {
125
+ try {
126
+ exporter.export(event);
127
+ }
128
+ catch {
129
+ /* swallow — exporter failures must not affect Decision outcomes. */
130
+ }
131
+ }
132
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAYvC,MAAM,UAAU,qBAAqB,CAAC,IAA4B;IAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO;QACL,cAAc,CAAC,KAAK;YAClB,MAAM,QAAQ,GAAkB;gBAC9B,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,qBAAqB,KAAK,CAAC,EAAE,EAAE;gBACrC,EAAE,EAAE,QAAQ,EAAE;gBACd,UAAU,EAAE,KAAK,CAAC;oBAChB,sBAAsB,EAAE,KAAK,CAAC,EAAE;o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BAA6B,EAAE,KAAK,CAAC,OAAO;oBAC5C,2BAA2B,EAAE,KAAK,CAAC,KAAK;oBACxC,8BAA8B,EAAE,KAAK,CAAC,QAAQ;iBAC/C,CAAC;aACH,CAAC;YACF,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,IAA4B;IAGhD,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACjB,GAAG,KAAK;QACR,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS;YAClC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE;YAClD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAC,QAAkB,EAAE,KAAoB;IAC1D,IAAI,CAAC;QACH,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;IACtE,CAAC;AACH,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Semantic conventions for adjudicate's OTLP attribute names.
3
+ *
4
+ * The names are namespaced under `adjudicate.*` so they don't collide with
5
+ * upstream OpenTelemetry semconv (`http.*`, `db.*`, …) or with adopter-defined
6
+ * attributes. We commit to keeping these names stable across minor versions —
7
+ * dashboards, alerts, and SIEM rules built on top of them MUST NOT break when
8
+ * `@adjudicate/observability` bumps its minor.
9
+ *
10
+ * If a new attribute is needed, ADD a new key here; do NOT rename existing
11
+ * ones. Removal is a breaking change and goes through the deprecation
12
+ * calendar (see `docs/release/deprecations.md`).
13
+ */
14
+ export declare const SEMCONV: {
15
+ /** Envelope kind — e.g. "vacation.request", "pix.charge.refund". */
16
+ readonly INTENT_KIND: "adjudicate.intent.kind";
17
+ /** Decision.kind — one of EXECUTE/REFUSE/ESCALATE/REQUEST_CONFIRMATION/REWRITE/DEFER. */
18
+ readonly DECISION_KIND: "adjudicate.decision.kind";
19
+ /** Taint level on the originating envelope — UNTRUSTED | TRUSTED | SYSTEM. */
20
+ readonly TAINT: "adjudicate.taint";
21
+ /** Adopter-supplied policy bundle version (e.g. semver of the Pack). */
22
+ readonly POLICY_VERSION: "adjudicate.policy.version";
23
+ /** Adopter-supplied Pack identifier, when known. */
24
+ readonly PACK_ID: "adjudicate.pack.id";
25
+ /** Wall-clock duration of the adjudication itself, in milliseconds. */
26
+ readonly LATENCY_MS: "adjudicate.latency.ms";
27
+ /** Audit-stable intent hash — useful for cross-correlating spans with audit rows. */
28
+ readonly INTENT_HASH: "adjudicate.intent.hash";
29
+ /** Matched-guard identifier (see ADR-105). Omitted for non-guard phases. */
30
+ readonly GUARD_ID: "adjudicate.guard.id";
31
+ /**
32
+ * Source of a propagated transition (kill-switch, deferred resume, …).
33
+ * Low cardinality: `pubsub | poll | boot | external`. Lets dashboards
34
+ * separate "operator initiated trip" from "boot-time resync".
35
+ */
36
+ readonly TRANSITION_SOURCE: "adjudicate.transition.source";
37
+ /**
38
+ * Lifecycle phase for the adapter loop. Low cardinality:
39
+ * `started | iteration | tool_use | decision | completed | paused`.
40
+ */
41
+ readonly ADAPTER_PHASE: "adjudicate.adapter.phase";
42
+ /**
43
+ * Adapter iteration counter within a single `.send()` call. Bounded
44
+ * by `maxIterations` (default 8) — safe for low-cardinality histograms.
45
+ */
46
+ readonly ADAPTER_ITERATION: "adjudicate.adapter.iteration";
47
+ /**
48
+ * Adapter outcome kind. Low cardinality: matches `AgentOutcome.kind`
49
+ * (`completed | deferred | awaiting_confirmation | escalated | max_iterations_exceeded`).
50
+ */
51
+ readonly ADAPTER_OUTCOME: "adjudicate.adapter.outcome";
52
+ /**
53
+ * Provider identifier supplied by the bridge. Adopter-controlled
54
+ * vocabulary (e.g., `anthropic | openai | vercel-ai | bedrock`). Kept
55
+ * low-cardinality by adopter discipline; the framework does not enforce
56
+ * a fixed enum here because adopters add their own providers.
57
+ */
58
+ readonly PROVIDER_ID: "adjudicate.provider.id";
59
+ /**
60
+ * Defer/confirm lifecycle phase: `parked | resumed | confirmed | declined | expired`.
61
+ */
62
+ readonly PAUSE_PHASE: "adjudicate.pause.phase";
63
+ /**
64
+ * Defer signal vocabulary entry. Controlled by the Pack's declared
65
+ * `signals` list — Packs are expected to keep this list small.
66
+ */
67
+ readonly DEFER_SIGNAL: "adjudicate.defer.signal";
68
+ /**
69
+ * Kill-switch state. Low cardinality: `active | normal`.
70
+ * Use {@link TRANSITION_SOURCE} alongside for the trigger.
71
+ */
72
+ readonly KILL_SWITCH_STATE: "adjudicate.kill_switch.state";
73
+ };
74
+ export type SemconvKey = keyof typeof SEMCONV;
75
+ export type SemconvAttribute = (typeof SEMCONV)[SemconvKey];
76
+ //# sourceMappingURL=semconv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.d.ts","sourceRoot":"","sources":["../src/semconv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO;IAClB,oEAAoE;;IAEpE,yFAAyF;;IAEzF,8EAA8E;;IAE9E,wEAAwE;;IAExE,oDAAoD;;IAEpD,uEAAuE;;IAEvE,qFAAqF;;IAErF,4EAA4E;;IAE5E;;;;OAIG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;IAEH;;;OAGG;;IAEH;;;OAGG;;CAEK,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,OAAO,CAAC;AAC9C,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC"}