@nodii/telemetry 0.0.2 → 0.3.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/README.md +223 -1
- package/dist/active-span.d.ts +12 -0
- package/dist/active-span.d.ts.map +1 -0
- package/dist/active-span.js +20 -0
- package/dist/active-span.js.map +1 -0
- package/dist/agent-invocable.d.ts +24 -0
- package/dist/agent-invocable.d.ts.map +1 -0
- package/dist/agent-invocable.js +64 -0
- package/dist/agent-invocable.js.map +1 -0
- package/dist/audit-types.d.ts +15 -0
- package/dist/audit-types.d.ts.map +1 -0
- package/dist/audit-types.js +39 -0
- package/dist/audit-types.js.map +1 -0
- package/dist/audit.d.ts +226 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +255 -0
- package/dist/audit.js.map +1 -0
- package/dist/configure.d.ts +34 -0
- package/dist/configure.d.ts.map +1 -0
- package/dist/configure.js +23 -0
- package/dist/configure.js.map +1 -0
- package/dist/context.d.ts +40 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +70 -0
- package/dist/context.js.map +1 -0
- package/dist/drizzle/audit-schema.d.ts +884 -0
- package/dist/drizzle/audit-schema.d.ts.map +1 -0
- package/dist/drizzle/audit-schema.js +268 -0
- package/dist/drizzle/audit-schema.js.map +1 -0
- package/dist/drizzle/index.d.ts +3 -0
- package/dist/drizzle/index.d.ts.map +1 -0
- package/dist/drizzle/index.js +5 -0
- package/dist/drizzle/index.js.map +1 -0
- package/dist/index.d.ts +21 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +39 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +114 -0
- package/dist/init.js.map +1 -0
- package/dist/intent.d.ts +21 -0
- package/dist/intent.d.ts.map +1 -0
- package/dist/intent.js +123 -0
- package/dist/intent.js.map +1 -0
- package/dist/logger.d.ts +19 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +99 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics.d.ts +53 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +152 -0
- package/dist/metrics.js.map +1 -0
- package/dist/otlp-adapter.d.ts +44 -0
- package/dist/otlp-adapter.d.ts.map +1 -0
- package/dist/otlp-adapter.js +351 -0
- package/dist/otlp-adapter.js.map +1 -0
- package/dist/outbox-emit.d.ts +34 -0
- package/dist/outbox-emit.d.ts.map +1 -0
- package/dist/outbox-emit.js +58 -0
- package/dist/outbox-emit.js.map +1 -0
- package/dist/redaction.d.ts +51 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +173 -0
- package/dist/redaction.js.map +1 -0
- package/dist/sdk-counters.d.ts +14 -0
- package/dist/sdk-counters.d.ts.map +1 -0
- package/dist/sdk-counters.js +42 -0
- package/dist/sdk-counters.js.map +1 -0
- package/dist/tracer.d.ts +63 -0
- package/dist/tracer.d.ts.map +1 -0
- package/dist/tracer.js +214 -0
- package/dist/tracer.js.map +1 -0
- package/dist/types.d.ts +230 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +66 -0
- package/dist/types.js.map +1 -0
- package/dist/uuid.d.ts +5 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +34 -0
- package/dist/uuid.js.map +1 -0
- package/package.json +44 -7
package/dist/intent.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Intent lifecycle per D46 + D155.
|
|
2
|
+
//
|
|
3
|
+
// API: `intent.begin/progress/complete/abandon/current`.
|
|
4
|
+
// begin sync UUIDv7 mint + async outbox `core.intent.begun.v1`;
|
|
5
|
+
// HARD validates against intent_types registry (D155).
|
|
6
|
+
// Activates ALS context: sets `intent_id` on the current
|
|
7
|
+
// NodiiContext via `_setIntentIdInCurrentScope`.
|
|
8
|
+
// progress no-op stub at v0.1.0 per M02 carry-forward (D155). Kept
|
|
9
|
+
// on the surface so callers don't break when the real
|
|
10
|
+
// behavior lands.
|
|
11
|
+
// complete emits outbox `core.intent.completed.v1`; deactivates
|
|
12
|
+
// context (intent_id back to null OR to the parent in the
|
|
13
|
+
// nested-begin stack, see below).
|
|
14
|
+
// abandon emits outbox `core.intent.abandoned.v1`; deactivates
|
|
15
|
+
// context same as complete.
|
|
16
|
+
// current sync ALS read; returns the active intent_id or null.
|
|
17
|
+
//
|
|
18
|
+
// Nested begins stack by ID match (D155). The library tracks an
|
|
19
|
+
// in-process stack keyed by trailing intent_id; complete/abandon pop
|
|
20
|
+
// the matching entry. If a complete/abandon arrives for an id not at
|
|
21
|
+
// the top of the stack, we still emit the event but log a warning —
|
|
22
|
+
// nested-begin discipline is a caller-side rule.
|
|
23
|
+
import { _setIntentIdInCurrentScope, getContext } from "./context";
|
|
24
|
+
import { requireTelemetry } from "./init";
|
|
25
|
+
import { emitOutbox } from "./outbox-emit";
|
|
26
|
+
import { uuidv7 } from "./uuid";
|
|
27
|
+
/** Per-typeName runtime registry; populated by `initTelemetry`. */
|
|
28
|
+
function intentTypeDef(typeName) {
|
|
29
|
+
const cfg = requireTelemetry();
|
|
30
|
+
return cfg.intentTypes[typeName] ?? null;
|
|
31
|
+
}
|
|
32
|
+
const stack = [];
|
|
33
|
+
async function begin(typeName, payload) {
|
|
34
|
+
const def = intentTypeDef(typeName);
|
|
35
|
+
if (!def) {
|
|
36
|
+
throw new IntentTypeNotRegistered(typeName);
|
|
37
|
+
}
|
|
38
|
+
// D45/D46 (E5 reframe): per-flow server/client mintable enforcement
|
|
39
|
+
// is a runtime concern that the gateway / SDK middleware should set
|
|
40
|
+
// via context; for v0.1.0 we accept all begins from server-side code
|
|
41
|
+
// and rely on the gateway to mint for HTTP-initiated. The flag is
|
|
42
|
+
// surfaced on the def so consumers can branch if they need to.
|
|
43
|
+
const id = uuidv7();
|
|
44
|
+
stack.push(id);
|
|
45
|
+
_setIntentIdInCurrentScope(id);
|
|
46
|
+
await emitOutbox({
|
|
47
|
+
topic: "core.intent.begun.v1",
|
|
48
|
+
event_id: id,
|
|
49
|
+
schema_version: 1,
|
|
50
|
+
payload: {
|
|
51
|
+
intent_type: typeName,
|
|
52
|
+
timeout_seconds: def.timeout_seconds,
|
|
53
|
+
payload: payload ?? null,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
async function complete(id, result) {
|
|
59
|
+
requireTelemetry();
|
|
60
|
+
popStack(id, "complete");
|
|
61
|
+
_setIntentIdInCurrentScope(currentStackTop());
|
|
62
|
+
await emitOutbox({
|
|
63
|
+
topic: "core.intent.completed.v1",
|
|
64
|
+
event_id: id,
|
|
65
|
+
schema_version: 1,
|
|
66
|
+
payload: { intent_id: id, result: result ?? null },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function abandon(id, reason) {
|
|
70
|
+
requireTelemetry();
|
|
71
|
+
popStack(id, "abandon");
|
|
72
|
+
_setIntentIdInCurrentScope(currentStackTop());
|
|
73
|
+
await emitOutbox({
|
|
74
|
+
topic: "core.intent.abandoned.v1",
|
|
75
|
+
event_id: id,
|
|
76
|
+
schema_version: 1,
|
|
77
|
+
payload: { intent_id: id, reason },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function progress(_id, _payload) {
|
|
81
|
+
// No-op at v0.1.0 per D155 § M02 carry-forward. Surface kept stable
|
|
82
|
+
// so callers don't break when behavior lands at a later version.
|
|
83
|
+
}
|
|
84
|
+
function current() {
|
|
85
|
+
return getContext()?.intent_id ?? null;
|
|
86
|
+
}
|
|
87
|
+
function popStack(id, op) {
|
|
88
|
+
const idx = stack.lastIndexOf(id);
|
|
89
|
+
if (idx === -1) {
|
|
90
|
+
// Not in stack — likely a misuse, but per D155 we still emit the
|
|
91
|
+
// event so the outbox stays a faithful chronology. Log a warning.
|
|
92
|
+
// eslint-disable-next-line no-console
|
|
93
|
+
console.warn(`[@nodii/telemetry] intent.${op}(${id}) called but id is not on the active stack; emitting event anyway.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Pop entries above this one too (treats out-of-order as orphaned
|
|
97
|
+
// begins — they get implicitly abandoned for the in-process stack).
|
|
98
|
+
stack.length = idx;
|
|
99
|
+
}
|
|
100
|
+
function currentStackTop() {
|
|
101
|
+
return stack.length > 0 ? (stack[stack.length - 1] ?? null) : null;
|
|
102
|
+
}
|
|
103
|
+
/** Thrown by `intent.begin` when the type isn't in the registry (D155 HARD). */
|
|
104
|
+
export class IntentTypeNotRegistered extends Error {
|
|
105
|
+
typeName;
|
|
106
|
+
constructor(typeName) {
|
|
107
|
+
super(`intent type "${typeName}" is not registered. Add it to the intent_types registry passed to initTelemetry().`);
|
|
108
|
+
this.typeName = typeName;
|
|
109
|
+
this.name = "IntentTypeNotRegistered";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Test-only stack reset. */
|
|
113
|
+
export function _resetIntentStackForTests() {
|
|
114
|
+
stack.length = 0;
|
|
115
|
+
}
|
|
116
|
+
export const intent = {
|
|
117
|
+
begin,
|
|
118
|
+
progress,
|
|
119
|
+
complete,
|
|
120
|
+
abandon,
|
|
121
|
+
current,
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=intent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent.js","sourceRoot":"","sources":["../src/intent.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,EAAE;AACF,yDAAyD;AACzD,sEAAsE;AACtE,mEAAmE;AACnE,qEAAqE;AACrE,6DAA6D;AAC7D,sEAAsE;AACtE,kEAAkE;AAClE,8BAA8B;AAC9B,mEAAmE;AACnE,sEAAsE;AACtE,8CAA8C;AAC9C,mEAAmE;AACnE,wCAAwC;AACxC,mEAAmE;AACnE,EAAE;AACF,gEAAgE;AAChE,qEAAqE;AACrE,qEAAqE;AACrE,oEAAoE;AACpE,iDAAiD;AAEjD,OAAO,EAAE,0BAA0B,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;A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IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrE,CAAC;AAED,gFAAgF;AAChF,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACpB;IAA5B,YAA4B,QAAgB;QAC1C,KAAK,CACH,gBAAgB,QAAQ,qFAAqF,CAC9G,CAAC;QAHwB,aAAQ,GAAR,QAAQ,CAAQ;QAI1C,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,6BAA6B;AAC7B,MAAM,UAAU,yBAAyB;IACvC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,OAAO;CACC,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { LogEnvelope } from "./types";
|
|
2
|
+
/** A sink that consumes formed log envelopes. Default = JSON to stdio. */
|
|
3
|
+
export type LogSink = (envelope: LogEnvelope, fields: Record<string, unknown>) => void;
|
|
4
|
+
/**
|
|
5
|
+
* SDK-internal: the OTel adapter installs an OTLP-log sink in TS-12.
|
|
6
|
+
* Public callers MUST NOT call this; the override is for internal
|
|
7
|
+
* substitution only (and tests).
|
|
8
|
+
*/
|
|
9
|
+
export declare function _setLogSink(s: LogSink): void;
|
|
10
|
+
/** Test-only restore. */
|
|
11
|
+
export declare function _resetLogSinkForTests(): void;
|
|
12
|
+
/** D13/D14 logger. Envelope fields are SDK-injected; do not supply them. */
|
|
13
|
+
export declare const logger: {
|
|
14
|
+
readonly debug: (msg: string, fields?: Record<string, unknown>) => void;
|
|
15
|
+
readonly info: (msg: string, fields?: Record<string, unknown>) => void;
|
|
16
|
+
readonly warn: (msg: string, fields?: Record<string, unknown>) => void;
|
|
17
|
+
readonly error: (msg: string, fields?: Record<string, unknown>) => void;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,SAAS,CAAC;AAErD,0EAA0E;AAC1E,MAAM,MAAM,OAAO,GAAG,CACpB,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,IAAI,CAAC;AAIV;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,CAE5C;AAED,yBAAyB;AACzB,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AA+DD,4EAA4E;AAC5E,eAAO,MAAM,MAAM;0BACN,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,IAAI;yBAGhD,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,IAAI;yBAG/C,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,IAAI;0BAG9C,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,IAAI;CAGlD,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Logger per D13/D14/D15.
|
|
2
|
+
//
|
|
3
|
+
// API:
|
|
4
|
+
// logger.debug | info | warn | error (msg, fields?)
|
|
5
|
+
//
|
|
6
|
+
// The 11-field envelope is auto-attached from initTelemetry config +
|
|
7
|
+
// active NodiiContext + active OTel span. Caller passes only `msg` +
|
|
8
|
+
// optional `fields`. Fields go through the D15 redaction passes
|
|
9
|
+
// (structured key + regex on string values) before emission. Failure
|
|
10
|
+
// in either pass = drop the line + bump
|
|
11
|
+
// `telemetry.sdk.redaction_failure_total{reason}` (D15 fail-closed).
|
|
12
|
+
//
|
|
13
|
+
// Sink: the default sink writes JSON to stdout/stderr. Real OTel-LP
|
|
14
|
+
// export wiring is deferred to TS-12; the sink is a single injection
|
|
15
|
+
// point that the OTel adapter replaces.
|
|
16
|
+
import { getActiveSpan } from "./active-span";
|
|
17
|
+
import { getContext } from "./context";
|
|
18
|
+
import { requireTelemetry } from "./init";
|
|
19
|
+
import { attemptRedactFields, attemptRedactString } from "./redaction";
|
|
20
|
+
import { incSdkCounter } from "./sdk-counters";
|
|
21
|
+
let sink = defaultJsonSink;
|
|
22
|
+
/**
|
|
23
|
+
* SDK-internal: the OTel adapter installs an OTLP-log sink in TS-12.
|
|
24
|
+
* Public callers MUST NOT call this; the override is for internal
|
|
25
|
+
* substitution only (and tests).
|
|
26
|
+
*/
|
|
27
|
+
export function _setLogSink(s) {
|
|
28
|
+
sink = s;
|
|
29
|
+
}
|
|
30
|
+
/** Test-only restore. */
|
|
31
|
+
export function _resetLogSinkForTests() {
|
|
32
|
+
sink = defaultJsonSink;
|
|
33
|
+
}
|
|
34
|
+
function defaultJsonSink(envelope, fields) {
|
|
35
|
+
const line = JSON.stringify({ ...envelope, ...fields });
|
|
36
|
+
if (envelope.level === "error" || envelope.level === "warn") {
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
process.stderr.write(`${line}\n`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
process.stdout.write(`${line}\n`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function emit(level, msg, fields) {
|
|
46
|
+
const cfg = requireTelemetry();
|
|
47
|
+
const ctx = getContext();
|
|
48
|
+
// D15 redaction (fail-closed). Run BOTH passes before forming the
|
|
49
|
+
// envelope; if either throws, drop the line + bump the counter.
|
|
50
|
+
const msgResult = attemptRedactString(msg);
|
|
51
|
+
if (!msgResult.ok) {
|
|
52
|
+
incSdkCounter("telemetry.sdk.redaction_failure_total", {
|
|
53
|
+
reason: msgResult.reason,
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const fieldsResult = fields
|
|
58
|
+
? attemptRedactFields(fields)
|
|
59
|
+
: { ok: true, redacted: {} };
|
|
60
|
+
if (!fieldsResult.ok) {
|
|
61
|
+
incSdkCounter("telemetry.sdk.redaction_failure_total", {
|
|
62
|
+
reason: fieldsResult.reason,
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const span = getActiveSpan();
|
|
67
|
+
const envelope = {
|
|
68
|
+
level,
|
|
69
|
+
ts: new Date().toISOString(),
|
|
70
|
+
msg: msgResult.redacted,
|
|
71
|
+
service: cfg.serviceName,
|
|
72
|
+
env: cfg.env,
|
|
73
|
+
tenant_id: ctx?.tenant_id ?? "",
|
|
74
|
+
user_id: ctx?.user_id ?? null,
|
|
75
|
+
on_behalf_of: ctx?.on_behalf_of ?? null,
|
|
76
|
+
actor_type: ctx?.actor_type,
|
|
77
|
+
request_id: ctx?.request_id ?? "",
|
|
78
|
+
trace_id: span?.trace_id ?? null,
|
|
79
|
+
span_id: span?.span_id ?? null,
|
|
80
|
+
intent_id: ctx?.intent_id ?? null,
|
|
81
|
+
};
|
|
82
|
+
sink(envelope, fieldsResult.redacted);
|
|
83
|
+
}
|
|
84
|
+
/** D13/D14 logger. Envelope fields are SDK-injected; do not supply them. */
|
|
85
|
+
export const logger = {
|
|
86
|
+
debug(msg, fields) {
|
|
87
|
+
emit("debug", msg, fields);
|
|
88
|
+
},
|
|
89
|
+
info(msg, fields) {
|
|
90
|
+
emit("info", msg, fields);
|
|
91
|
+
},
|
|
92
|
+
warn(msg, fields) {
|
|
93
|
+
emit("warn", msg, fields);
|
|
94
|
+
},
|
|
95
|
+
error(msg, fields) {
|
|
96
|
+
emit("error", msg, fields);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,0BAA0B;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F,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,CAAC,GAAW,EAAE,MAAgC;QACjD,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,GAAW,EAAE,MAAgC;QAChD,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,CAAC,GAAW,EAAE,MAAgC;QAChD,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IACD,KAAK,CAAC,GAAW,EAAE,MAAgC;QACjD,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;CACO,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type MetricFamily } from "./types";
|
|
2
|
+
/** Thrown by `metrics.counter/histogram` when registration is rejected. */
|
|
3
|
+
export declare class MetricVocabularyError extends Error {
|
|
4
|
+
readonly metric: string;
|
|
5
|
+
readonly reason: string;
|
|
6
|
+
constructor(metric: string, reason: string);
|
|
7
|
+
}
|
|
8
|
+
export interface CounterHandle {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly family: MetricFamily;
|
|
11
|
+
readonly description: string;
|
|
12
|
+
inc(labels?: Record<string, string | number>): void;
|
|
13
|
+
inc(by: number, labels?: Record<string, string | number>): void;
|
|
14
|
+
}
|
|
15
|
+
export interface HistogramHandle {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly family: MetricFamily;
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly maxBuckets: number;
|
|
20
|
+
record(value: number, labels?: Record<string, string | number>): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Backend that records the actual data points. The default backend
|
|
24
|
+
* stores points in-process for tests + the SDK counters; the real OTel
|
|
25
|
+
* meter wires in via TS-12 by replacing this through `_setBackend`.
|
|
26
|
+
*/
|
|
27
|
+
export interface MetricsBackend {
|
|
28
|
+
recordCounter(name: string, by: number, labels: Record<string, string | number>): void;
|
|
29
|
+
recordHistogram(name: string, value: number, labels: Record<string, string | number>): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function _setMetricsBackend(b: MetricsBackend): void;
|
|
32
|
+
export declare function _resetMetricsBackendForTests(): void;
|
|
33
|
+
export interface MetricRegistration {
|
|
34
|
+
family: MetricFamily;
|
|
35
|
+
description: string;
|
|
36
|
+
labelKeys?: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
declare function counter(name: string, reg: MetricRegistration): CounterHandle;
|
|
39
|
+
declare function histogram(name: string, reg: MetricRegistration & {
|
|
40
|
+
maxBuckets?: number;
|
|
41
|
+
}): HistogramHandle;
|
|
42
|
+
/**
|
|
43
|
+
* The `metrics.*` namespace (D149 verbatim name). Use:
|
|
44
|
+
*
|
|
45
|
+
* const c = metrics.counter('billing_payments_total', { family: 'async_worker', description: '...' });
|
|
46
|
+
* c.inc({ tenant_id, pgw, status });
|
|
47
|
+
*/
|
|
48
|
+
export declare const metrics: {
|
|
49
|
+
readonly counter: typeof counter;
|
|
50
|
+
readonly histogram: typeof histogram;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,SAAS,CAAC;AAEjB,2EAA2E;AAC3E,qBAAa,qBAAsB,SAAQ,KAAK;aAE5B,MAAM,EAAE,MAAM;aACd,MAAM,EAAE,MAAM;gBADd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM;CAKjC;AAsED,MAAM,WAAW,aAAa;IAC5B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EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED,iBAAS,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,kBAAkB,GAAG,aAAa,CAwBrE;AAED,iBAAS,SAAS,CAChB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,kBAAkB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAChD,eAAe,CAoBjB;AAED;;;;;GAKG;AACH,eAAO,MAAM,OAAO;;;CAGV,CAAC"}
|
package/dist/metrics.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Metrics per D18 / D19 / D20 / D21 / D22 / D23 / D24.
|
|
2
|
+
//
|
|
3
|
+
// Discipline at v0.1.0:
|
|
4
|
+
// - `metrics.counter()` and `metrics.histogram()` accept a name +
|
|
5
|
+
// family + description. The name MUST exist in the vocabulary
|
|
6
|
+
// registry loaded by `initTelemetry({ vocabularyRegistry })` per
|
|
7
|
+
// D24. Names not in the registry are rejected with
|
|
8
|
+
// `telemetry.sdk.cardinality_rejected_total{family, reason='not_in_vocabulary'}`
|
|
9
|
+
// and a thrown `MetricVocabularyError`.
|
|
10
|
+
// - `family` is one of the six locked families (D18). Mismatches with
|
|
11
|
+
// the registry-declared family are rejected the same way.
|
|
12
|
+
// - `tenant_id` is a bare label (D20) — the registration helper
|
|
13
|
+
// validates label keys against a deny-list that excludes `tenant.id`
|
|
14
|
+
// and `tenantId` variants.
|
|
15
|
+
// - Histograms are exponential (D19); the wrapper exposes
|
|
16
|
+
// `histogram.record(value, labels)` and stores the configuration
|
|
17
|
+
// for the OTel adapter to consume in TS-12. Max 160 buckets (D19).
|
|
18
|
+
// - Delta temporality (D21) is declared on the wrapper; the OTel
|
|
19
|
+
// adapter sets the OTLP export accordingly.
|
|
20
|
+
import { requireTelemetry } from "./init";
|
|
21
|
+
import { incSdkCounter } from "./sdk-counters";
|
|
22
|
+
import { METRIC_FAMILIES, } from "./types";
|
|
23
|
+
/** Thrown by `metrics.counter/histogram` when registration is rejected. */
|
|
24
|
+
export class MetricVocabularyError extends Error {
|
|
25
|
+
metric;
|
|
26
|
+
reason;
|
|
27
|
+
constructor(metric, reason) {
|
|
28
|
+
super(`metric "${metric}" rejected: ${reason}`);
|
|
29
|
+
this.metric = metric;
|
|
30
|
+
this.reason = reason;
|
|
31
|
+
this.name = "MetricVocabularyError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* D20: bare-label discipline. Reject `tenant.id` and `tenantId`
|
|
36
|
+
* variants at registration. Also reject any underscored Postgres-y
|
|
37
|
+
* variants like `tenantid`. The locked correct key is `tenant_id`.
|
|
38
|
+
*/
|
|
39
|
+
const FORBIDDEN_LABEL_KEYS = new Set([
|
|
40
|
+
"tenant.id",
|
|
41
|
+
"tenantId",
|
|
42
|
+
"tenantid",
|
|
43
|
+
"TENANT_ID",
|
|
44
|
+
]);
|
|
45
|
+
function validateLabelKeys(metric, family, labelKeys) {
|
|
46
|
+
for (const k of labelKeys) {
|
|
47
|
+
if (FORBIDDEN_LABEL_KEYS.has(k)) {
|
|
48
|
+
const reason = "label_key_forbidden";
|
|
49
|
+
incSdkCounter("telemetry.sdk.cardinality_rejected_total", {
|
|
50
|
+
family,
|
|
51
|
+
reason,
|
|
52
|
+
});
|
|
53
|
+
throw new MetricVocabularyError(metric, `label key '${k}' forbidden — use bare 'tenant_id' per D20`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function validateRegistration(metric, family) {
|
|
58
|
+
if (!METRIC_FAMILIES.includes(family)) {
|
|
59
|
+
const reason = "family_unknown";
|
|
60
|
+
incSdkCounter("telemetry.sdk.cardinality_rejected_total", {
|
|
61
|
+
family,
|
|
62
|
+
reason,
|
|
63
|
+
});
|
|
64
|
+
throw new MetricVocabularyError(metric, reason);
|
|
65
|
+
}
|
|
66
|
+
const cfg = requireTelemetry();
|
|
67
|
+
const entry = cfg.vocabularyRegistry[metric];
|
|
68
|
+
if (!entry) {
|
|
69
|
+
const reason = "not_in_vocabulary";
|
|
70
|
+
incSdkCounter("telemetry.sdk.cardinality_rejected_total", {
|
|
71
|
+
family,
|
|
72
|
+
reason,
|
|
73
|
+
});
|
|
74
|
+
throw new MetricVocabularyError(metric, reason);
|
|
75
|
+
}
|
|
76
|
+
if (entry.family !== family) {
|
|
77
|
+
const reason = "family_mismatch";
|
|
78
|
+
incSdkCounter("telemetry.sdk.cardinality_rejected_total", {
|
|
79
|
+
family,
|
|
80
|
+
reason,
|
|
81
|
+
});
|
|
82
|
+
throw new MetricVocabularyError(metric, `family mismatch — registry says '${entry.family}', caller said '${family}'`);
|
|
83
|
+
}
|
|
84
|
+
return entry;
|
|
85
|
+
}
|
|
86
|
+
const inProcessBackend = {
|
|
87
|
+
recordCounter(_name, _by, _labels) {
|
|
88
|
+
/* no-op; TS-12 replaces */
|
|
89
|
+
},
|
|
90
|
+
recordHistogram(_name, _value, _labels) {
|
|
91
|
+
/* no-op; TS-12 replaces */
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
let backend = inProcessBackend;
|
|
95
|
+
export function _setMetricsBackend(b) {
|
|
96
|
+
backend = b;
|
|
97
|
+
}
|
|
98
|
+
export function _resetMetricsBackendForTests() {
|
|
99
|
+
backend = inProcessBackend;
|
|
100
|
+
}
|
|
101
|
+
function counter(name, reg) {
|
|
102
|
+
const entry = validateRegistration(name, reg.family);
|
|
103
|
+
validateLabelKeys(name, reg.family, reg.labelKeys ?? []);
|
|
104
|
+
const description = reg.description || entry.description;
|
|
105
|
+
return {
|
|
106
|
+
name,
|
|
107
|
+
family: reg.family,
|
|
108
|
+
description,
|
|
109
|
+
inc(byOrLabels, maybeLabels) {
|
|
110
|
+
let by;
|
|
111
|
+
let labels;
|
|
112
|
+
if (typeof byOrLabels === "number") {
|
|
113
|
+
by = byOrLabels;
|
|
114
|
+
labels = maybeLabels ?? {};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
by = 1;
|
|
118
|
+
labels = byOrLabels ?? {};
|
|
119
|
+
}
|
|
120
|
+
backend.recordCounter(name, by, labels);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function histogram(name, reg) {
|
|
125
|
+
const entry = validateRegistration(name, reg.family);
|
|
126
|
+
validateLabelKeys(name, reg.family, reg.labelKeys ?? []);
|
|
127
|
+
const description = reg.description || entry.description;
|
|
128
|
+
const maxBuckets = reg.maxBuckets ?? 160;
|
|
129
|
+
if (maxBuckets > 160) {
|
|
130
|
+
throw new MetricVocabularyError(name, `maxBuckets ${maxBuckets} exceeds D19 cap (160)`);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
name,
|
|
134
|
+
family: reg.family,
|
|
135
|
+
description,
|
|
136
|
+
maxBuckets,
|
|
137
|
+
record(value, labels = {}) {
|
|
138
|
+
backend.recordHistogram(name, value, labels);
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The `metrics.*` namespace (D149 verbatim name). Use:
|
|
144
|
+
*
|
|
145
|
+
* const c = metrics.counter('billing_payments_total', { family: 'async_worker', description: '...' });
|
|
146
|
+
* c.inc({ tenant_id, pgw, status });
|
|
147
|
+
*/
|
|
148
|
+
export const metrics = {
|
|
149
|
+
counter,
|
|
150
|
+
histogram,
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,wBAAwB;AACxB,oEAAoE;AACpE,kEAAkE;AAClE,qEAAqE;AACrE,uDAAuD;AACvD,qFAAqF;AACrF,4CAA4C;AAC5C,wEAAwE;AACxE,8DAA8D;AAC9D,kEAAkE;AAClE,yEAAyE;AACzE,+BAA+B;AAC/B,4DAA4D;AAC5D,qEAAqE;AACrE,u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AC,KAAK,EAAE,MAAM,GAAG,EAAE;YACvB,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO;IACP,SAAS;CACD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
2
|
+
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
|
3
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
4
|
+
import { type CounterHandle, type HistogramHandle } from "./metrics";
|
|
5
|
+
import type { ErrorHandlingConfig, ResourceAttributes } from "./types";
|
|
6
|
+
/** Config for the OTLP adapter — the subset of init config it needs. */
|
|
7
|
+
export interface OtlpAdapterConfig {
|
|
8
|
+
serviceName: string;
|
|
9
|
+
env: string;
|
|
10
|
+
serviceVersion?: string;
|
|
11
|
+
deploymentRegion?: string;
|
|
12
|
+
otlpEndpoint: string;
|
|
13
|
+
errorHandling: ErrorHandlingConfig;
|
|
14
|
+
resourceAttributes: Record<string, string | number | boolean>;
|
|
15
|
+
}
|
|
16
|
+
/** Handle returned by `installOtlpAdapter` so callers can shut down. */
|
|
17
|
+
export interface OtlpAdapterHandle {
|
|
18
|
+
/** Force-flushes all signal pipelines (spans + logs + metrics). */
|
|
19
|
+
forceFlush(): Promise<void>;
|
|
20
|
+
/** Shuts everything down. Calls flush first. */
|
|
21
|
+
shutdown(): Promise<void>;
|
|
22
|
+
/** Direct accessor — used by Lambda lifecycle wrappers. */
|
|
23
|
+
tracerProvider: NodeTracerProvider;
|
|
24
|
+
loggerProvider: LoggerProvider;
|
|
25
|
+
meterProvider: MeterProvider;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Installs the real OTLP exporters by replacing the no-op emitter,
|
|
29
|
+
* sink, and backend with adapters that flush to OTel SDK providers
|
|
30
|
+
* wired to OTLP gRPC.
|
|
31
|
+
*
|
|
32
|
+
* Idempotent — second call returns the same handle.
|
|
33
|
+
*/
|
|
34
|
+
export declare function installOtlpAdapter(cfg: OtlpAdapterConfig): OtlpAdapterHandle;
|
|
35
|
+
/** Force-flushes the active OTLP pipelines. No-op when not installed. */
|
|
36
|
+
export declare function forceFlush(): Promise<void>;
|
|
37
|
+
/** Shuts down the OTLP pipelines. No-op when not installed. */
|
|
38
|
+
export declare function shutdownOtlpAdapter(): Promise<void>;
|
|
39
|
+
/** For tests + introspection. */
|
|
40
|
+
export declare function getOtlpAdapterHandle(): OtlpAdapterHandle | null;
|
|
41
|
+
/** Test-only reset; does NOT shutdown providers. */
|
|
42
|
+
export declare function _resetOtlpAdapterForTests(): void;
|
|
43
|
+
export type { CounterHandle, HistogramHandle, ResourceAttributes };
|
|
44
|
+
//# sourceMappingURL=otlp-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlp-adapter.d.ts","sourceRoot":"","sources":["../src/otlp-adapter.ts"],"names":[],"mappings":"AAkCA,OAAO,EAEL,cAAc,EACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,aAAa,EAEd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AAQvC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EAGrB,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EACV,mBAAmB,EAEnB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,wEAAwE;AACxE,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,mBAAmB,CAAC;I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