autotel-schema 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.
Files changed (61) hide show
  1. package/README.md +131 -0
  2. package/dist/cli.cjs +111 -0
  3. package/dist/cli.cjs.map +1 -0
  4. package/dist/cli.d.cts +14 -0
  5. package/dist/cli.d.cts.map +1 -0
  6. package/dist/cli.d.ts +14 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +82 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/contract-DGjxR9nb.d.cts +123 -0
  11. package/dist/contract-DGjxR9nb.d.cts.map +1 -0
  12. package/dist/contract-DGjxR9nb.d.ts +123 -0
  13. package/dist/contract-DGjxR9nb.d.ts.map +1 -0
  14. package/dist/diff-BQPh72vY.d.cts +89 -0
  15. package/dist/diff-BQPh72vY.d.cts.map +1 -0
  16. package/dist/diff-D7qkNn0-.d.ts +89 -0
  17. package/dist/diff-D7qkNn0-.d.ts.map +1 -0
  18. package/dist/diff.cjs +185 -0
  19. package/dist/diff.cjs.map +1 -0
  20. package/dist/diff.d.cts +2 -0
  21. package/dist/diff.d.ts +2 -0
  22. package/dist/diff.js +181 -0
  23. package/dist/diff.js.map +1 -0
  24. package/dist/index.cjs +63 -0
  25. package/dist/index.cjs.map +1 -0
  26. package/dist/index.d.cts +33 -0
  27. package/dist/index.d.cts.map +1 -0
  28. package/dist/index.d.ts +33 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +43 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/processor-CK7LAdaa.d.ts +100 -0
  33. package/dist/processor-CK7LAdaa.d.ts.map +1 -0
  34. package/dist/processor-CkBkzK6y.d.cts +100 -0
  35. package/dist/processor-CkBkzK6y.d.cts.map +1 -0
  36. package/dist/processor-D93TAXvZ.cjs +366 -0
  37. package/dist/processor-D93TAXvZ.cjs.map +1 -0
  38. package/dist/processor-FmvKYllX.js +306 -0
  39. package/dist/processor-FmvKYllX.js.map +1 -0
  40. package/dist/processor.cjs +5 -0
  41. package/dist/processor.d.cts +2 -0
  42. package/dist/processor.d.ts +2 -0
  43. package/dist/processor.js +3 -0
  44. package/dist/snapshot-CyWGJaJT.cjs +119 -0
  45. package/dist/snapshot-CyWGJaJT.cjs.map +1 -0
  46. package/dist/snapshot-h8pb_Up_.js +89 -0
  47. package/dist/snapshot-h8pb_Up_.js.map +1 -0
  48. package/package.json +80 -0
  49. package/src/attrs.ts +23 -0
  50. package/src/cli.ts +117 -0
  51. package/src/contract.test.ts +67 -0
  52. package/src/contract.ts +231 -0
  53. package/src/diff.ts +282 -0
  54. package/src/index.ts +88 -0
  55. package/src/processor.test.ts +74 -0
  56. package/src/processor.ts +152 -0
  57. package/src/redaction.ts +64 -0
  58. package/src/snapshot.test.ts +88 -0
  59. package/src/snapshot.ts +119 -0
  60. package/src/validate.test.ts +100 -0
  61. package/src/validate.ts +237 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,63 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_snapshot = require('./snapshot-CyWGJaJT.cjs');
3
+ const require_processor = require('./processor-D93TAXvZ.cjs');
4
+ const require_diff = require('./diff.cjs');
5
+
6
+ //#region src/redaction.ts
7
+ /**
8
+ * Every attribute key in the contract flagged `highCardinality: true`, across
9
+ * both common and per-span attributes. Feed this into a redaction/normalization
10
+ * allow-list so the fields most useful to an agent reader survive.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { init } from 'autotel';
15
+ * import { highCardinalityKeys } from 'autotel-schema';
16
+ * import { contract } from './telemetry.contract';
17
+ *
18
+ * init({
19
+ * service: 'checkout',
20
+ * // keep user.id / request.id intact even under the strict redactor
21
+ * attributeRedactor: { allowKeys: highCardinalityKeys(contract), preset: 'strict' },
22
+ * });
23
+ * ```
24
+ */
25
+ function highCardinalityKeys(contract) {
26
+ const keys = /* @__PURE__ */ new Set();
27
+ for (const [key, spec] of Object.entries(contract.commonAttributes ?? {})) if (spec.highCardinality) keys.add(key);
28
+ for (const spanSpec of Object.values(contract.spans)) for (const [key, spec] of Object.entries(spanSpec.attributes ?? {})) if (spec.highCardinality) keys.add(key);
29
+ return [...keys].toSorted();
30
+ }
31
+ /**
32
+ * Predicate form of {@link highCardinalityKeys} — `true` when `key` is declared
33
+ * high-cardinality anywhere in the contract. Useful inside a custom
34
+ * `spanNameNormalizer` or redactor callback.
35
+ */
36
+ function isHighCardinalityKey(contract, key) {
37
+ if (contract.commonAttributes?.[key]?.highCardinality) return true;
38
+ for (const spanSpec of Object.values(contract.spans)) if (spanSpec.attributes?.[key]?.highCardinality) return true;
39
+ return false;
40
+ }
41
+
42
+ //#endregion
43
+ exports.ATTRIBUTE_TYPES = require_processor.ATTRIBUTE_TYPES;
44
+ exports.SCHEMA_ATTRS = require_snapshot.SCHEMA_ATTRS;
45
+ exports.SNAPSHOT_SPEC = require_snapshot.SNAPSHOT_SPEC;
46
+ exports.STABILITIES = require_processor.STABILITIES;
47
+ exports.SchemaValidationSpanProcessor = require_processor.SchemaValidationSpanProcessor;
48
+ exports.allowsAdditionalAttributes = require_processor.allowsAdditionalAttributes;
49
+ exports.contractToSnapshot = require_snapshot.contractToSnapshot;
50
+ exports.createSchemaValidationProcessor = require_processor.createSchemaValidationProcessor;
51
+ exports.defineContract = require_processor.defineContract;
52
+ exports.diffSnapshots = require_diff.diffSnapshots;
53
+ exports.formatDiff = require_diff.formatDiff;
54
+ exports.formatViolation = require_processor.formatViolation;
55
+ exports.hasBreakingChanges = require_diff.hasBreakingChanges;
56
+ exports.hasErrors = require_processor.hasErrors;
57
+ exports.highCardinalityKeys = highCardinalityKeys;
58
+ exports.isHighCardinalityKey = isHighCardinalityKey;
59
+ exports.parseSnapshot = require_snapshot.parseSnapshot;
60
+ exports.resolveAttributeSpec = require_processor.resolveAttributeSpec;
61
+ exports.serializeSnapshot = require_snapshot.serializeSnapshot;
62
+ exports.validateSpan = require_processor.validateSpan;
63
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/redaction.ts"],"sourcesContent":["/**\n * Cardinality posture helpers.\n *\n * The old cardinality rule — \"keep unique-value counts down\" — was a constraint\n * invented because dashboards have pixels and a graph with 10k series is\n * unreadable to a human. An agent does not look at the graph; it reads the\n * spans. A high-cardinality field (the user id, the sender domain, the request\n * id) is then the single most useful attribute on a trace when the agent is\n * chasing one specific failure.\n *\n * So the contract lets you mark attributes `highCardinality: true` as a\n * deliberate signal, and this module turns that into a *protect list*: the keys\n * a redactor or span-name normalizer must NOT strip, even when an aggressive\n * default would otherwise drop them.\n */\n\nimport type { TelemetryContract } from './contract.js';\n\n/**\n * Every attribute key in the contract flagged `highCardinality: true`, across\n * both common and per-span attributes. Feed this into a redaction/normalization\n * allow-list so the fields most useful to an agent reader survive.\n *\n * @example\n * ```ts\n * import { init } from 'autotel';\n * import { highCardinalityKeys } from 'autotel-schema';\n * import { contract } from './telemetry.contract';\n *\n * init({\n * service: 'checkout',\n * // keep user.id / request.id intact even under the strict redactor\n * attributeRedactor: { allowKeys: highCardinalityKeys(contract), preset: 'strict' },\n * });\n * ```\n */\nexport function highCardinalityKeys(contract: TelemetryContract): string[] {\n const keys = new Set<string>();\n for (const [key, spec] of Object.entries(contract.commonAttributes ?? {})) {\n if (spec.highCardinality) keys.add(key);\n }\n for (const spanSpec of Object.values(contract.spans)) {\n for (const [key, spec] of Object.entries(spanSpec.attributes ?? {})) {\n if (spec.highCardinality) keys.add(key);\n }\n }\n return [...keys].toSorted();\n}\n\n/**\n * Predicate form of {@link highCardinalityKeys} — `true` when `key` is declared\n * high-cardinality anywhere in the contract. Useful inside a custom\n * `spanNameNormalizer` or redactor callback.\n */\nexport function isHighCardinalityKey(\n contract: TelemetryContract,\n key: string,\n): boolean {\n if (contract.commonAttributes?.[key]?.highCardinality) return true;\n for (const spanSpec of Object.values(contract.spans)) {\n if (spanSpec.attributes?.[key]?.highCardinality) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,oBAAoB,UAAuC;CACzE,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,SAAS,oBAAoB,CAAC,CAAC,GACtE,IAAI,KAAK,iBAAiB,KAAK,IAAI,GAAG;CAExC,KAAK,MAAM,YAAY,OAAO,OAAO,SAAS,KAAK,GACjD,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,SAAS,cAAc,CAAC,CAAC,GAChE,IAAI,KAAK,iBAAiB,KAAK,IAAI,GAAG;CAG1C,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,SAAS;AAC5B;;;;;;AAOA,SAAgB,qBACd,UACA,KACS;CACT,IAAI,SAAS,mBAAmB,IAAI,EAAE,iBAAiB,OAAO;CAC9D,KAAK,MAAM,YAAY,OAAO,OAAO,SAAS,KAAK,GACjD,IAAI,SAAS,aAAa,IAAI,EAAE,iBAAiB,OAAO;CAE1D,OAAO;AACT"}
@@ -0,0 +1,33 @@
1
+ import { a as diffSnapshots, c as ContractSnapshot, d as contractToSnapshot, f as parseSnapshot, g as SchemaAttributeKey, h as SNAPSHOT_SPEC, i as SnapshotDiff, l as SnapshotAttribute, m as SCHEMA_ATTRS, n as ChangeType, o as formatDiff, p as serializeSnapshot, r as SnapshotChange, s as hasBreakingChanges, t as ChangeKind, u as SnapshotSpan } from "./diff-BQPh72vY.cjs";
2
+ import { a as SpanSpec, c as allowsAdditionalAttributes, i as STABILITIES, l as defineContract, n as AttributeSpec, o as Stability, r as AttributeType, s as TelemetryContract, t as ATTRIBUTE_TYPES, u as resolveAttributeSpec } from "./contract-DGjxR9nb.cjs";
3
+ import { a as SchemaValidationSpanProcessor, c as createSchemaValidationProcessor, d as ValidateOptions, f as ViolationCode, g as validateSpan, h as hasErrors, i as SchemaValidationProcessorOptions, l as SchemaViolation, m as formatViolation, n as ReadableSpanLike, o as SpanLike, p as ViolationSeverity, r as SchemaProcessorMode, s as SpanProcessorLike, t as OtelContext, u as SpanShape } from "./processor-CkBkzK6y.cjs";
4
+
5
+ //#region src/redaction.d.ts
6
+ /**
7
+ * Every attribute key in the contract flagged `highCardinality: true`, across
8
+ * both common and per-span attributes. Feed this into a redaction/normalization
9
+ * allow-list so the fields most useful to an agent reader survive.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { init } from 'autotel';
14
+ * import { highCardinalityKeys } from 'autotel-schema';
15
+ * import { contract } from './telemetry.contract';
16
+ *
17
+ * init({
18
+ * service: 'checkout',
19
+ * // keep user.id / request.id intact even under the strict redactor
20
+ * attributeRedactor: { allowKeys: highCardinalityKeys(contract), preset: 'strict' },
21
+ * });
22
+ * ```
23
+ */
24
+ declare function highCardinalityKeys(contract: TelemetryContract): string[];
25
+ /**
26
+ * Predicate form of {@link highCardinalityKeys} — `true` when `key` is declared
27
+ * high-cardinality anywhere in the contract. Useful inside a custom
28
+ * `spanNameNormalizer` or redactor callback.
29
+ */
30
+ declare function isHighCardinalityKey(contract: TelemetryContract, key: string): boolean;
31
+ //#endregion
32
+ export { ATTRIBUTE_TYPES, type AttributeSpec, type AttributeType, type ChangeKind, type ChangeType, type ContractSnapshot, type OtelContext, type ReadableSpanLike, SCHEMA_ATTRS, SNAPSHOT_SPEC, STABILITIES, type SchemaAttributeKey, type SchemaProcessorMode, type SchemaValidationProcessorOptions, SchemaValidationSpanProcessor, type SchemaViolation, type SnapshotAttribute, type SnapshotChange, type SnapshotDiff, type SnapshotSpan, type SpanLike, type SpanProcessorLike, type SpanShape, type SpanSpec, type Stability, type TelemetryContract, type ValidateOptions, type ViolationCode, type ViolationSeverity, allowsAdditionalAttributes, contractToSnapshot, createSchemaValidationProcessor, defineContract, diffSnapshots, formatDiff, formatViolation, hasBreakingChanges, hasErrors, highCardinalityKeys, isHighCardinalityKey, parseSnapshot, resolveAttributeSpec, serializeSnapshot, validateSpan };
33
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/redaction.ts"],"mappings":";;;;;;;AAwDa;;;;;;;;;;;;;;;;iBApBG,mBAAA,CAAoB,QAA2B,EAAjB,iBAAiB;;;;;;iBAkB/C,oBAAA,CACd,QAAA,EAAU,iBAAiB,EAC3B,GAAA"}
@@ -0,0 +1,33 @@
1
+ import { a as diffSnapshots, c as ContractSnapshot, d as contractToSnapshot, f as parseSnapshot, g as SchemaAttributeKey, h as SNAPSHOT_SPEC, i as SnapshotDiff, l as SnapshotAttribute, m as SCHEMA_ATTRS, n as ChangeType, o as formatDiff, p as serializeSnapshot, r as SnapshotChange, s as hasBreakingChanges, t as ChangeKind, u as SnapshotSpan } from "./diff-D7qkNn0-.js";
2
+ import { a as SpanSpec, c as allowsAdditionalAttributes, i as STABILITIES, l as defineContract, n as AttributeSpec, o as Stability, r as AttributeType, s as TelemetryContract, t as ATTRIBUTE_TYPES, u as resolveAttributeSpec } from "./contract-DGjxR9nb.js";
3
+ import { a as SchemaValidationSpanProcessor, c as createSchemaValidationProcessor, d as ValidateOptions, f as ViolationCode, g as validateSpan, h as hasErrors, i as SchemaValidationProcessorOptions, l as SchemaViolation, m as formatViolation, n as ReadableSpanLike, o as SpanLike, p as ViolationSeverity, r as SchemaProcessorMode, s as SpanProcessorLike, t as OtelContext, u as SpanShape } from "./processor-CK7LAdaa.js";
4
+
5
+ //#region src/redaction.d.ts
6
+ /**
7
+ * Every attribute key in the contract flagged `highCardinality: true`, across
8
+ * both common and per-span attributes. Feed this into a redaction/normalization
9
+ * allow-list so the fields most useful to an agent reader survive.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { init } from 'autotel';
14
+ * import { highCardinalityKeys } from 'autotel-schema';
15
+ * import { contract } from './telemetry.contract';
16
+ *
17
+ * init({
18
+ * service: 'checkout',
19
+ * // keep user.id / request.id intact even under the strict redactor
20
+ * attributeRedactor: { allowKeys: highCardinalityKeys(contract), preset: 'strict' },
21
+ * });
22
+ * ```
23
+ */
24
+ declare function highCardinalityKeys(contract: TelemetryContract): string[];
25
+ /**
26
+ * Predicate form of {@link highCardinalityKeys} — `true` when `key` is declared
27
+ * high-cardinality anywhere in the contract. Useful inside a custom
28
+ * `spanNameNormalizer` or redactor callback.
29
+ */
30
+ declare function isHighCardinalityKey(contract: TelemetryContract, key: string): boolean;
31
+ //#endregion
32
+ export { ATTRIBUTE_TYPES, type AttributeSpec, type AttributeType, type ChangeKind, type ChangeType, type ContractSnapshot, type OtelContext, type ReadableSpanLike, SCHEMA_ATTRS, SNAPSHOT_SPEC, STABILITIES, type SchemaAttributeKey, type SchemaProcessorMode, type SchemaValidationProcessorOptions, SchemaValidationSpanProcessor, type SchemaViolation, type SnapshotAttribute, type SnapshotChange, type SnapshotDiff, type SnapshotSpan, type SpanLike, type SpanProcessorLike, type SpanShape, type SpanSpec, type Stability, type TelemetryContract, type ValidateOptions, type ViolationCode, type ViolationSeverity, allowsAdditionalAttributes, contractToSnapshot, createSchemaValidationProcessor, defineContract, diffSnapshots, formatDiff, formatViolation, hasBreakingChanges, hasErrors, highCardinalityKeys, isHighCardinalityKey, parseSnapshot, resolveAttributeSpec, serializeSnapshot, validateSpan };
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/redaction.ts"],"mappings":";;;;;;;AAwDa;;;;;;;;;;;;;;;;iBApBG,mBAAA,CAAoB,QAA2B,EAAjB,iBAAiB;;;;;;iBAkB/C,oBAAA,CACd,QAAA,EAAU,iBAAiB,EAC3B,GAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import { a as SNAPSHOT_SPEC, i as SCHEMA_ATTRS, n as parseSnapshot, r as serializeSnapshot, t as contractToSnapshot } from "./snapshot-h8pb_Up_.js";
2
+ import { a as validateSpan, c as allowsAdditionalAttributes, i as hasErrors, l as defineContract, n as createSchemaValidationProcessor, o as ATTRIBUTE_TYPES, r as formatViolation, s as STABILITIES, t as SchemaValidationSpanProcessor, u as resolveAttributeSpec } from "./processor-FmvKYllX.js";
3
+ import { diffSnapshots, formatDiff, hasBreakingChanges } from "./diff.js";
4
+
5
+ //#region src/redaction.ts
6
+ /**
7
+ * Every attribute key in the contract flagged `highCardinality: true`, across
8
+ * both common and per-span attributes. Feed this into a redaction/normalization
9
+ * allow-list so the fields most useful to an agent reader survive.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { init } from 'autotel';
14
+ * import { highCardinalityKeys } from 'autotel-schema';
15
+ * import { contract } from './telemetry.contract';
16
+ *
17
+ * init({
18
+ * service: 'checkout',
19
+ * // keep user.id / request.id intact even under the strict redactor
20
+ * attributeRedactor: { allowKeys: highCardinalityKeys(contract), preset: 'strict' },
21
+ * });
22
+ * ```
23
+ */
24
+ function highCardinalityKeys(contract) {
25
+ const keys = /* @__PURE__ */ new Set();
26
+ for (const [key, spec] of Object.entries(contract.commonAttributes ?? {})) if (spec.highCardinality) keys.add(key);
27
+ for (const spanSpec of Object.values(contract.spans)) for (const [key, spec] of Object.entries(spanSpec.attributes ?? {})) if (spec.highCardinality) keys.add(key);
28
+ return [...keys].toSorted();
29
+ }
30
+ /**
31
+ * Predicate form of {@link highCardinalityKeys} — `true` when `key` is declared
32
+ * high-cardinality anywhere in the contract. Useful inside a custom
33
+ * `spanNameNormalizer` or redactor callback.
34
+ */
35
+ function isHighCardinalityKey(contract, key) {
36
+ if (contract.commonAttributes?.[key]?.highCardinality) return true;
37
+ for (const spanSpec of Object.values(contract.spans)) if (spanSpec.attributes?.[key]?.highCardinality) return true;
38
+ return false;
39
+ }
40
+
41
+ //#endregion
42
+ export { ATTRIBUTE_TYPES, SCHEMA_ATTRS, SNAPSHOT_SPEC, STABILITIES, SchemaValidationSpanProcessor, allowsAdditionalAttributes, contractToSnapshot, createSchemaValidationProcessor, defineContract, diffSnapshots, formatDiff, formatViolation, hasBreakingChanges, hasErrors, highCardinalityKeys, isHighCardinalityKey, parseSnapshot, resolveAttributeSpec, serializeSnapshot, validateSpan };
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/redaction.ts"],"sourcesContent":["/**\n * Cardinality posture helpers.\n *\n * The old cardinality rule — \"keep unique-value counts down\" — was a constraint\n * invented because dashboards have pixels and a graph with 10k series is\n * unreadable to a human. An agent does not look at the graph; it reads the\n * spans. A high-cardinality field (the user id, the sender domain, the request\n * id) is then the single most useful attribute on a trace when the agent is\n * chasing one specific failure.\n *\n * So the contract lets you mark attributes `highCardinality: true` as a\n * deliberate signal, and this module turns that into a *protect list*: the keys\n * a redactor or span-name normalizer must NOT strip, even when an aggressive\n * default would otherwise drop them.\n */\n\nimport type { TelemetryContract } from './contract.js';\n\n/**\n * Every attribute key in the contract flagged `highCardinality: true`, across\n * both common and per-span attributes. Feed this into a redaction/normalization\n * allow-list so the fields most useful to an agent reader survive.\n *\n * @example\n * ```ts\n * import { init } from 'autotel';\n * import { highCardinalityKeys } from 'autotel-schema';\n * import { contract } from './telemetry.contract';\n *\n * init({\n * service: 'checkout',\n * // keep user.id / request.id intact even under the strict redactor\n * attributeRedactor: { allowKeys: highCardinalityKeys(contract), preset: 'strict' },\n * });\n * ```\n */\nexport function highCardinalityKeys(contract: TelemetryContract): string[] {\n const keys = new Set<string>();\n for (const [key, spec] of Object.entries(contract.commonAttributes ?? {})) {\n if (spec.highCardinality) keys.add(key);\n }\n for (const spanSpec of Object.values(contract.spans)) {\n for (const [key, spec] of Object.entries(spanSpec.attributes ?? {})) {\n if (spec.highCardinality) keys.add(key);\n }\n }\n return [...keys].toSorted();\n}\n\n/**\n * Predicate form of {@link highCardinalityKeys} — `true` when `key` is declared\n * high-cardinality anywhere in the contract. Useful inside a custom\n * `spanNameNormalizer` or redactor callback.\n */\nexport function isHighCardinalityKey(\n contract: TelemetryContract,\n key: string,\n): boolean {\n if (contract.commonAttributes?.[key]?.highCardinality) return true;\n for (const spanSpec of Object.values(contract.spans)) {\n if (spanSpec.attributes?.[key]?.highCardinality) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,oBAAoB,UAAuC;CACzE,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,SAAS,oBAAoB,CAAC,CAAC,GACtE,IAAI,KAAK,iBAAiB,KAAK,IAAI,GAAG;CAExC,KAAK,MAAM,YAAY,OAAO,OAAO,SAAS,KAAK,GACjD,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,SAAS,cAAc,CAAC,CAAC,GAChE,IAAI,KAAK,iBAAiB,KAAK,IAAI,GAAG;CAG1C,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,SAAS;AAC5B;;;;;;AAOA,SAAgB,qBACd,UACA,KACS;CACT,IAAI,SAAS,mBAAmB,IAAI,EAAE,iBAAiB,OAAO;CAC9D,KAAK,MAAM,YAAY,OAAO,OAAO,SAAS,KAAK,GACjD,IAAI,SAAS,aAAa,IAAI,EAAE,iBAAiB,OAAO;CAE1D,OAAO;AACT"}
@@ -0,0 +1,100 @@
1
+ import { s as TelemetryContract } from "./contract-DGjxR9nb.js";
2
+
3
+ //#region src/validate.d.ts
4
+ /** Severity of a contract violation. `error` = a breaking-shaped problem. */
5
+ type ViolationSeverity = 'error' | 'warning';
6
+ type ViolationCode = 'unknown_span' | 'unknown_attribute' | 'type_mismatch' | 'missing_required' | 'deprecated_attribute' | 'enum_violation';
7
+ /** A single discrepancy between an emitted span and the contract. */
8
+ interface SchemaViolation {
9
+ code: ViolationCode;
10
+ severity: ViolationSeverity;
11
+ spanName: string;
12
+ /** Attribute key involved, when the violation is attribute-scoped. */
13
+ attribute?: string;
14
+ message: string;
15
+ /** Nearest declared key, for likely typos (`unknown_attribute` only). */
16
+ suggestion?: string;
17
+ }
18
+ /** Minimal emitted-span shape — avoids a hard dependency on the OTel SDK. */
19
+ interface SpanShape {
20
+ name: string;
21
+ attributes: Record<string, unknown>;
22
+ }
23
+ interface ValidateOptions {
24
+ /** Report `unknown_span` for span names not in the contract. Default `false`. */
25
+ strictSpanNames?: boolean;
26
+ }
27
+ /**
28
+ * Validate one emitted span against the contract, returning every discrepancy.
29
+ * Order is deterministic: required-but-missing first, then per-attribute checks
30
+ * in attribute insertion order.
31
+ */
32
+ declare function validateSpan(span: SpanShape, contract: TelemetryContract, options?: ValidateOptions): SchemaViolation[];
33
+ /** `true` when any violation is `error` severity. */
34
+ declare function hasErrors(violations: SchemaViolation[]): boolean;
35
+ /** One-line human/agent-readable rendering of a violation. */
36
+ declare function formatViolation(v: SchemaViolation): string;
37
+ //#endregion
38
+ //#region src/processor.d.ts
39
+ /** Minimal ReadableSpan shape — matches OTel without a hard SDK dependency. */
40
+ interface ReadableSpanLike {
41
+ name: string;
42
+ attributes: Record<string, unknown>;
43
+ }
44
+ interface SpanLike {
45
+ spanContext(): {
46
+ traceId: string;
47
+ spanId: string;
48
+ };
49
+ }
50
+ /** Opaque parent context — matches OTel SpanProcessor without importing it. */
51
+ type OtelContext = unknown;
52
+ interface SpanProcessorLike {
53
+ onStart(span: SpanLike, parentContext: OtelContext): void;
54
+ onEnd(span: ReadableSpanLike): void;
55
+ shutdown(): Promise<void>;
56
+ forceFlush(): Promise<void>;
57
+ }
58
+ /** How the processor reacts to a contract violation. */
59
+ type SchemaProcessorMode = 'warn' | 'throw' | 'silent';
60
+ interface SchemaValidationProcessorOptions extends ValidateOptions {
61
+ contract: TelemetryContract;
62
+ /**
63
+ * `warn` (default): log each distinct violation once per interval.
64
+ * `throw`: throw on the first error-severity violation — for tests/CI only.
65
+ * `silent`: collect via `onViolation` without logging.
66
+ */
67
+ mode?: SchemaProcessorMode;
68
+ /** Called for every violation, before mode handling. */
69
+ onViolation?: (violation: SchemaViolation, span: ReadableSpanLike) => void;
70
+ /** Override the warn sink (defaults to `console.warn`). */
71
+ onWarn?: (message: string) => void;
72
+ /** Run even when `NODE_ENV === 'production'`. Default `false`. */
73
+ enabledInProduction?: boolean;
74
+ /** Throttle window for repeated identical warnings (ms). Default 60s. */
75
+ warnIntervalMs?: number;
76
+ }
77
+ /**
78
+ * Validates each ending span against a {@link TelemetryContract}. Bounded,
79
+ * deduplicated warnings; fail-open on any internal error.
80
+ */
81
+ declare class SchemaValidationSpanProcessor implements SpanProcessorLike {
82
+ private readonly opts;
83
+ private readonly enabled;
84
+ private readonly warnIntervalMs;
85
+ private readonly lastWarnAt;
86
+ private violationCount;
87
+ constructor(opts: SchemaValidationProcessorOptions);
88
+ /** Number of violations seen since startup (across all spans). */
89
+ get totalViolations(): number;
90
+ onStart(_span: SpanLike, _parentContext: OtelContext): void;
91
+ onEnd(span: ReadableSpanLike): void;
92
+ private handle;
93
+ private maybeWarn;
94
+ forceFlush(): Promise<void>;
95
+ shutdown(): Promise<void>;
96
+ }
97
+ declare function createSchemaValidationProcessor(opts: SchemaValidationProcessorOptions): SchemaValidationSpanProcessor;
98
+ //#endregion
99
+ export { SchemaValidationSpanProcessor as a, createSchemaValidationProcessor as c, ValidateOptions as d, ViolationCode as f, validateSpan as g, hasErrors as h, SchemaValidationProcessorOptions as i, SchemaViolation as l, formatViolation as m, ReadableSpanLike as n, SpanLike as o, ViolationSeverity as p, SchemaProcessorMode as r, SpanProcessorLike as s, OtelContext as t, SpanShape as u };
100
+ //# sourceMappingURL=processor-CK7LAdaa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor-CK7LAdaa.d.ts","names":[],"sources":["../src/validate.ts","../src/processor.ts"],"mappings":";;;;KAcY,iBAAA;AAAA,KAEA,aAAA;AAAZ;AAAA,UASiB,eAAA;EACf,IAAA,EAAM,aAAA;EACN,QAAA,EAAU,iBAAiB;EAC3B,QAAA;EAHe;EAKf,SAAA;EACA,OAAA;EAJ2B;EAM3B,UAAA;AAAA;;UAIe,SAAA;EACf,IAAA;EACA,UAAA,EAAY,MAAM;AAAA;AAAA,UAGH,eAAA;EATL;EAWV,eAAe;AAAA;;;;;;iBAwHD,YAAA,CACd,IAAA,EAAM,SAAA,EACN,QAAA,EAAU,iBAAA,EACV,OAAA,GAAS,eAAA,GACR,eAAA;;iBA2Da,SAAA,CAAU,UAA6B,EAAjB,eAAe;AAzLrD;AAAA,iBA8LgB,eAAA,CAAgB,CAAkB,EAAf,eAAe;;;;UCvNjC,gBAAA;EACf,IAAA;EACA,UAAA,EAAY,MAAM;AAAA;AAAA,UAGH,QAAA;EACf,WAAA;IAAiB,OAAA;IAAiB,MAAA;EAAA;AAAA;;KAIxB,WAAA;AAAA,UAEK,iBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,QAAA,EAAU,aAAA,EAAe,WAAA;EACvC,KAAA,CAAM,IAAA,EAAM,gBAAA;EACZ,QAAA,IAAY,OAAA;EACZ,UAAA,IAAc,OAAA;AAAA;;KAIJ,mBAAA;AAAA,UAEK,gCAAA,SAAyC,eAAA;EACxD,QAAA,EAAU,iBAAA;EDEoB;;;AAEf;AAwHjB;ECtHE,IAAA,GAAO,mBAAA;;EAEP,WAAA,IAAe,SAAA,EAAW,eAAA,EAAiB,IAAA,EAAM,gBAAA;EDsHvC;ECpHV,MAAA,IAAU,OAAA;EDsHT;ECpHD,mBAAA;EDoHgB;EClHhB,cAAA;AAAA;;;;;cAaW,6BAAA,YAAyC,iBAAA;EAAA,iBACnC,IAAA;EAAA,iBACA,OAAA;EAAA,iBACA,cAAA;EAAA,iBACA,UAAA;EAAA,QACT,cAAA;cAEI,IAAA,EAAM,gCAAA;EDyJmC;EAAA,IClJjD,eAAA;EAIJ,OAAA,CAAQ,KAAA,EAAO,QAAA,EAAU,cAAA,EAAgB,WAAA;EAIzC,KAAA,CAAM,IAAA,EAAM,gBAAA;EAAA,QAqBJ,MAAA;EAAA,QAWA,SAAA;EAiBF,UAAA,IAAc,OAAA;EAId,QAAA,IAAY,OAAA;AAAA;AAAA,iBAKJ,+BAAA,CACd,IAAA,EAAM,gCAAA,GACL,6BAA6B"}
@@ -0,0 +1,100 @@
1
+ import { s as TelemetryContract } from "./contract-DGjxR9nb.cjs";
2
+
3
+ //#region src/validate.d.ts
4
+ /** Severity of a contract violation. `error` = a breaking-shaped problem. */
5
+ type ViolationSeverity = 'error' | 'warning';
6
+ type ViolationCode = 'unknown_span' | 'unknown_attribute' | 'type_mismatch' | 'missing_required' | 'deprecated_attribute' | 'enum_violation';
7
+ /** A single discrepancy between an emitted span and the contract. */
8
+ interface SchemaViolation {
9
+ code: ViolationCode;
10
+ severity: ViolationSeverity;
11
+ spanName: string;
12
+ /** Attribute key involved, when the violation is attribute-scoped. */
13
+ attribute?: string;
14
+ message: string;
15
+ /** Nearest declared key, for likely typos (`unknown_attribute` only). */
16
+ suggestion?: string;
17
+ }
18
+ /** Minimal emitted-span shape — avoids a hard dependency on the OTel SDK. */
19
+ interface SpanShape {
20
+ name: string;
21
+ attributes: Record<string, unknown>;
22
+ }
23
+ interface ValidateOptions {
24
+ /** Report `unknown_span` for span names not in the contract. Default `false`. */
25
+ strictSpanNames?: boolean;
26
+ }
27
+ /**
28
+ * Validate one emitted span against the contract, returning every discrepancy.
29
+ * Order is deterministic: required-but-missing first, then per-attribute checks
30
+ * in attribute insertion order.
31
+ */
32
+ declare function validateSpan(span: SpanShape, contract: TelemetryContract, options?: ValidateOptions): SchemaViolation[];
33
+ /** `true` when any violation is `error` severity. */
34
+ declare function hasErrors(violations: SchemaViolation[]): boolean;
35
+ /** One-line human/agent-readable rendering of a violation. */
36
+ declare function formatViolation(v: SchemaViolation): string;
37
+ //#endregion
38
+ //#region src/processor.d.ts
39
+ /** Minimal ReadableSpan shape — matches OTel without a hard SDK dependency. */
40
+ interface ReadableSpanLike {
41
+ name: string;
42
+ attributes: Record<string, unknown>;
43
+ }
44
+ interface SpanLike {
45
+ spanContext(): {
46
+ traceId: string;
47
+ spanId: string;
48
+ };
49
+ }
50
+ /** Opaque parent context — matches OTel SpanProcessor without importing it. */
51
+ type OtelContext = unknown;
52
+ interface SpanProcessorLike {
53
+ onStart(span: SpanLike, parentContext: OtelContext): void;
54
+ onEnd(span: ReadableSpanLike): void;
55
+ shutdown(): Promise<void>;
56
+ forceFlush(): Promise<void>;
57
+ }
58
+ /** How the processor reacts to a contract violation. */
59
+ type SchemaProcessorMode = 'warn' | 'throw' | 'silent';
60
+ interface SchemaValidationProcessorOptions extends ValidateOptions {
61
+ contract: TelemetryContract;
62
+ /**
63
+ * `warn` (default): log each distinct violation once per interval.
64
+ * `throw`: throw on the first error-severity violation — for tests/CI only.
65
+ * `silent`: collect via `onViolation` without logging.
66
+ */
67
+ mode?: SchemaProcessorMode;
68
+ /** Called for every violation, before mode handling. */
69
+ onViolation?: (violation: SchemaViolation, span: ReadableSpanLike) => void;
70
+ /** Override the warn sink (defaults to `console.warn`). */
71
+ onWarn?: (message: string) => void;
72
+ /** Run even when `NODE_ENV === 'production'`. Default `false`. */
73
+ enabledInProduction?: boolean;
74
+ /** Throttle window for repeated identical warnings (ms). Default 60s. */
75
+ warnIntervalMs?: number;
76
+ }
77
+ /**
78
+ * Validates each ending span against a {@link TelemetryContract}. Bounded,
79
+ * deduplicated warnings; fail-open on any internal error.
80
+ */
81
+ declare class SchemaValidationSpanProcessor implements SpanProcessorLike {
82
+ private readonly opts;
83
+ private readonly enabled;
84
+ private readonly warnIntervalMs;
85
+ private readonly lastWarnAt;
86
+ private violationCount;
87
+ constructor(opts: SchemaValidationProcessorOptions);
88
+ /** Number of violations seen since startup (across all spans). */
89
+ get totalViolations(): number;
90
+ onStart(_span: SpanLike, _parentContext: OtelContext): void;
91
+ onEnd(span: ReadableSpanLike): void;
92
+ private handle;
93
+ private maybeWarn;
94
+ forceFlush(): Promise<void>;
95
+ shutdown(): Promise<void>;
96
+ }
97
+ declare function createSchemaValidationProcessor(opts: SchemaValidationProcessorOptions): SchemaValidationSpanProcessor;
98
+ //#endregion
99
+ export { SchemaValidationSpanProcessor as a, createSchemaValidationProcessor as c, ValidateOptions as d, ViolationCode as f, validateSpan as g, hasErrors as h, SchemaValidationProcessorOptions as i, SchemaViolation as l, formatViolation as m, ReadableSpanLike as n, SpanLike as o, ViolationSeverity as p, SchemaProcessorMode as r, SpanProcessorLike as s, OtelContext as t, SpanShape as u };
100
+ //# sourceMappingURL=processor-CkBkzK6y.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor-CkBkzK6y.d.cts","names":[],"sources":["../src/validate.ts","../src/processor.ts"],"mappings":";;;;KAcY,iBAAA;AAAA,KAEA,aAAA;AAAZ;AAAA,UASiB,eAAA;EACf,IAAA,EAAM,aAAA;EACN,QAAA,EAAU,iBAAiB;EAC3B,QAAA;EAHe;EAKf,SAAA;EACA,OAAA;EAJ2B;EAM3B,UAAA;AAAA;;UAIe,SAAA;EACf,IAAA;EACA,UAAA,EAAY,MAAM;AAAA;AAAA,UAGH,eAAA;EATL;EAWV,eAAe;AAAA;;;;;;iBAwHD,YAAA,CACd,IAAA,EAAM,SAAA,EACN,QAAA,EAAU,iBAAA,EACV,OAAA,GAAS,eAAA,GACR,eAAA;;iBA2Da,SAAA,CAAU,UAA6B,EAAjB,eAAe;AAzLrD;AAAA,iBA8LgB,eAAA,CAAgB,CAAkB,EAAf,eAAe;;;;UCvNjC,gBAAA;EACf,IAAA;EACA,UAAA,EAAY,MAAM;AAAA;AAAA,UAGH,QAAA;EACf,WAAA;IAAiB,OAAA;IAAiB,MAAA;EAAA;AAAA;;KAIxB,WAAA;AAAA,UAEK,iBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,QAAA,EAAU,aAAA,EAAe,WAAA;EACvC,KAAA,CAAM,IAAA,EAAM,gBAAA;EACZ,QAAA,IAAY,OAAA;EACZ,UAAA,IAAc,OAAA;AAAA;;KAIJ,mBAAA;AAAA,UAEK,gCAAA,SAAyC,eAAA;EACxD,QAAA,EAAU,iBAAA;EDEoB;;;AAEf;AAwHjB;ECtHE,IAAA,GAAO,mBAAA;;EAEP,WAAA,IAAe,SAAA,EAAW,eAAA,EAAiB,IAAA,EAAM,gBAAA;EDsHvC;ECpHV,MAAA,IAAU,OAAA;EDsHT;ECpHD,mBAAA;EDoHgB;EClHhB,cAAA;AAAA;;;;;cAaW,6BAAA,YAAyC,iBAAA;EAAA,iBACnC,IAAA;EAAA,iBACA,OAAA;EAAA,iBACA,cAAA;EAAA,iBACA,UAAA;EAAA,QACT,cAAA;cAEI,IAAA,EAAM,gCAAA;EDyJmC;EAAA,IClJjD,eAAA;EAIJ,OAAA,CAAQ,KAAA,EAAO,QAAA,EAAU,cAAA,EAAgB,WAAA;EAIzC,KAAA,CAAM,IAAA,EAAM,gBAAA;EAAA,QAqBJ,MAAA;EAAA,QAWA,SAAA;EAiBF,UAAA,IAAc,OAAA;EAId,QAAA,IAAY,OAAA;AAAA;AAAA,iBAKJ,+BAAA,CACd,IAAA,EAAM,gCAAA,GACL,6BAA6B"}