autotel-schema 2.0.5 → 4.0.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 +91 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/contract-Ymh_Q37N.d.cts +305 -0
- package/dist/contract-Ymh_Q37N.d.cts.map +1 -0
- package/dist/contract-Ymh_Q37N.d.ts +305 -0
- package/dist/contract-Ymh_Q37N.d.ts.map +1 -0
- package/dist/{diff-BQPh72vY.d.cts → diff-CAIC04O4.d.ts} +5 -4
- package/dist/diff-CAIC04O4.d.ts.map +1 -0
- package/dist/{diff-D7qkNn0-.d.ts → diff-CfvhW7ux.d.cts} +5 -4
- package/dist/diff-CfvhW7ux.d.cts.map +1 -0
- package/dist/diff.cjs.map +1 -1
- package/dist/diff.d.cts +1 -1
- package/dist/diff.d.ts +1 -1
- package/dist/diff.js.map +1 -1
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/processor-BPp_DewZ.js +635 -0
- package/dist/processor-BPp_DewZ.js.map +1 -0
- package/dist/{processor-CkBkzK6y.d.cts → processor-DVcsS6Rz.d.cts} +2 -3
- package/dist/processor-DVcsS6Rz.d.cts.map +1 -0
- package/dist/processor-Gu8Yl_dS.cjs +737 -0
- package/dist/processor-Gu8Yl_dS.cjs.map +1 -0
- package/dist/{processor-CK7LAdaa.d.ts → processor-TpuacLr5.d.ts} +2 -3
- package/dist/processor-TpuacLr5.d.ts.map +1 -0
- package/dist/processor.cjs +1 -1
- package/dist/processor.d.cts +1 -1
- package/dist/processor.d.ts +1 -1
- package/dist/processor.js +1 -1
- package/dist/snapshot-CyWGJaJT.cjs.map +1 -1
- package/dist/snapshot-h8pb_Up_.js.map +1 -1
- package/package.json +4 -4
- package/dist/contract-DGjxR9nb.d.cts +0 -123
- package/dist/contract-DGjxR9nb.d.cts.map +0 -1
- package/dist/contract-DGjxR9nb.d.ts +0 -123
- package/dist/contract-DGjxR9nb.d.ts.map +0 -1
- package/dist/diff-BQPh72vY.d.cts.map +0 -1
- package/dist/diff-D7qkNn0-.d.ts.map +0 -1
- package/dist/processor-CK7LAdaa.d.ts.map +0 -1
- package/dist/processor-CkBkzK6y.d.cts.map +0 -1
- package/dist/processor-D93TAXvZ.cjs +0 -366
- package/dist/processor-D93TAXvZ.cjs.map +0 -1
- package/dist/processor-FmvKYllX.js +0 -306
- package/dist/processor-FmvKYllX.js.map +0 -1
package/README.md
CHANGED
|
@@ -29,13 +29,21 @@ export const contract = defineContract({
|
|
|
29
29
|
service: 'checkout',
|
|
30
30
|
version: '1.2.0', // semver of the *contract*, not the app
|
|
31
31
|
commonAttributes: {
|
|
32
|
-
'user.id': {
|
|
32
|
+
'user.id': {
|
|
33
|
+
type: 'string',
|
|
34
|
+
highCardinality: true,
|
|
35
|
+
description: 'Authenticated user',
|
|
36
|
+
},
|
|
33
37
|
},
|
|
34
38
|
spans: {
|
|
35
39
|
'checkout.charge': {
|
|
36
40
|
description: 'Charge a payment method',
|
|
37
41
|
attributes: {
|
|
38
|
-
'payment.provider': {
|
|
42
|
+
'payment.provider': {
|
|
43
|
+
type: 'string',
|
|
44
|
+
required: true,
|
|
45
|
+
enum: ['stripe', 'paypal'],
|
|
46
|
+
},
|
|
39
47
|
'payment.amount_cents': { type: 'number', required: true },
|
|
40
48
|
},
|
|
41
49
|
},
|
|
@@ -71,7 +79,8 @@ const violations = validateSpan(
|
|
|
71
79
|
contract,
|
|
72
80
|
);
|
|
73
81
|
// → [missing_required payment.amount_cents, enum_violation payment.provider]
|
|
74
|
-
if (hasErrors(violations))
|
|
82
|
+
if (hasErrors(violations))
|
|
83
|
+
violations.forEach((v) => console.error(formatViolation(v)));
|
|
75
84
|
```
|
|
76
85
|
|
|
77
86
|
Violation codes: `missing_required`, `type_mismatch`, `enum_violation`, `unknown_attribute` (with a "did you mean?" suggestion via edit distance), and `unknown_span`.
|
|
@@ -85,7 +94,10 @@ import { contractToSnapshot, serializeSnapshot } from 'autotel-schema';
|
|
|
85
94
|
import { writeFileSync } from 'node:fs';
|
|
86
95
|
import { contract } from './telemetry.contract';
|
|
87
96
|
|
|
88
|
-
writeFileSync(
|
|
97
|
+
writeFileSync(
|
|
98
|
+
'telemetry.snapshot.json',
|
|
99
|
+
serializeSnapshot(contractToSnapshot(contract)),
|
|
100
|
+
);
|
|
89
101
|
```
|
|
90
102
|
|
|
91
103
|
Then in CI, with the bundled `autotel-schema` CLI:
|
|
@@ -100,7 +112,11 @@ autotel-schema diff telemetry.baseline.json telemetry.current.json --json
|
|
|
100
112
|
Programmatically:
|
|
101
113
|
|
|
102
114
|
```ts
|
|
103
|
-
import {
|
|
115
|
+
import {
|
|
116
|
+
diffSnapshots,
|
|
117
|
+
hasBreakingChanges,
|
|
118
|
+
formatDiff,
|
|
119
|
+
} from 'autotel-schema/diff';
|
|
104
120
|
|
|
105
121
|
const diff = diffSnapshots(baseline, current);
|
|
106
122
|
if (hasBreakingChanges(diff)) throw new Error(formatDiff(diff));
|
|
@@ -117,14 +133,81 @@ import { contract } from './telemetry.contract';
|
|
|
117
133
|
|
|
118
134
|
init({
|
|
119
135
|
service: 'checkout',
|
|
120
|
-
attributeRedactor: {
|
|
136
|
+
attributeRedactor: {
|
|
137
|
+
allowKeys: highCardinalityKeys(contract),
|
|
138
|
+
preset: 'strict',
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 5. Scenario conformance: contract one exercised flow
|
|
144
|
+
|
|
145
|
+
Spans and attributes contract your telemetry _surface_. A **scenario**contracts the _behaviour_ of one exercised flow: which events must fire, how many times, in what topology, and, for async flows,**when the observation is complete**, because without a completion boundary a missing event and an event that hasn't fired _yet_ are indistinguishable.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
export const contract = defineContract({
|
|
149
|
+
service: 'transfer',
|
|
150
|
+
version: '1.3.0',
|
|
151
|
+
spans: {/* ... */},
|
|
152
|
+
scenarios: {
|
|
153
|
+
'transfer.accept': {
|
|
154
|
+
completion: {
|
|
155
|
+
mode: 'terminal-event',
|
|
156
|
+
event: 'transfer.queued',
|
|
157
|
+
observationBudgetMs: 5000,
|
|
158
|
+
},
|
|
159
|
+
events: {
|
|
160
|
+
'transfer.request': { cardinality: 'exactly 1' },
|
|
161
|
+
'transfer.validate': { cardinality: 'exactly 1' },
|
|
162
|
+
'transfer.queued': { cardinality: 'exactly 1' },
|
|
163
|
+
'transfer.retry': { cardinality: 'at most 3' },
|
|
164
|
+
},
|
|
165
|
+
edges: [['transfer.request', 'transfer.validate']], // ancestor→descendant, infra spans in between are fine
|
|
166
|
+
},
|
|
167
|
+
},
|
|
121
168
|
});
|
|
122
169
|
```
|
|
123
170
|
|
|
171
|
+
Checking yields **three** outcomes, not two. Infrastructure slowness is not reported as behavioural regression:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { checkScenario, formatScenarioResult } from 'autotel-schema';
|
|
175
|
+
|
|
176
|
+
const result = await checkScenario(
|
|
177
|
+
contract.scenarios!['transfer.accept'],
|
|
178
|
+
() => collector.peekTrace(traceId), // TestSpanCollector from autotel — or any ScenarioSpan[] source
|
|
179
|
+
{ name: 'transfer.accept' },
|
|
180
|
+
);
|
|
181
|
+
// result.outcome:
|
|
182
|
+
// 'conformant' — boundary closed, signature satisfied
|
|
183
|
+
// 'non-conformant' — required behaviour missing or invalid (definitive)
|
|
184
|
+
// 'incomplete' — boundary didn't close within the observation budget
|
|
185
|
+
if (result.outcome !== 'conformant')
|
|
186
|
+
throw new Error(formatScenarioResult(result));
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Semantics worth knowing:
|
|
190
|
+
|
|
191
|
+
- **Absence is definitive only after closure** (closed-world). Excess is definitive immediately: an unexpected error span or an exceeded `max` cardinality fails fast while the flow is still open.
|
|
192
|
+
- **Undeclared events are additive**: reported in `result.additions`, never a failure. Improving instrumentation must not break CI.
|
|
193
|
+
- **The observation budget bounds how long the checker waits.** It is not a business SLO: assert deadlines separately on `result.spans`.
|
|
194
|
+
- An `externally-reconciled` boundary never closes in-process: use it for phases verified by a deferred job keyed by a durable business ID.
|
|
195
|
+
|
|
196
|
+
Don't hand-write the first draft. Record it:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { proposeScenario } from 'autotel-schema';
|
|
200
|
+
|
|
201
|
+
const { scenario, notes } = proposeScenario(runs); // runs: ScenarioSpan[][] from N controlled executions
|
|
202
|
+
// notes: 'transfer.validate: exactly 1 (20/20 runs)', 'notification.send: 0..1 (14/20 runs) — review: variable', ...
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Stable events become required cardinality, variable ones get ranges flagged for review, and the completion boundary + budget are suggested from observed timings. Review, trim, commit.
|
|
206
|
+
|
|
124
207
|
## What this is / isn't
|
|
125
208
|
|
|
126
|
-
- **Is**: a contract for your telemetry surface: span names, attribute keys, types, enums, stability, and breaking-vs-additive evolution.
|
|
127
|
-
- **Isn't**: a contract for application message payloads (use [`autotel-message-contract`](../autotel-message-contract)) or evidence that interactions ran (use [`autotel-pact`](../autotel-pact)). It does not require the OpenTelemetry SDK. The processor works against structural span types.
|
|
209
|
+
- **Is**: a contract for your telemetry surface: span names, attribute keys, types, enums, stability, and breaking-vs-additive evolution: and, per scenario, the behavioural signature of one exercised flow (events, cardinality, topology, completion).
|
|
210
|
+
- **Isn't**: a contract for application message payloads (use [`autotel-message-contract`](../autotel-message-contract)) or evidence that contracted interactions ran (use [`autotel-pact`](../autotel-pact)). It does not require the OpenTelemetry SDK. The processor works against structural span types.
|
|
128
211
|
|
|
129
212
|
## License
|
|
130
213
|
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","names":["diffSnapshots","parseSnapshot","formatDiff","hasBreakingChanges","path"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * autotel-schema CLI — the CI gate for your telemetry's public API.\n *\n * autotel-schema diff <baseline.json> <current.json> # classify changes\n * autotel-schema check <baseline.json> <current.json> # exit 1 on breaking\n *\n * Both operate on snapshot JSON produced by `serializeSnapshot(contractToSnapshot(contract))`.\n * Commit the baseline; regenerate `current` in CI; gate the merge on `check`.\n */\n\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseSnapshot } from './snapshot.js';\nimport {\n diffSnapshots,\n formatDiff,\n hasBreakingChanges,\n type SnapshotDiff,\n} from './diff.js';\n\ninterface Parsed {\n command: string | undefined;\n baseline: string | undefined;\n current: string | undefined;\n json: boolean;\n}\n\nfunction parseArgs(argv: string[]): Parsed {\n const positional: string[] = [];\n let json = false;\n for (const arg of argv) {\n if (arg === '--json') json = true;\n else if (arg === '-h' || arg === '--help') positional.unshift('help');\n else positional.push(arg);\n }\n return {\n command: positional[0],\n baseline: positional[1],\n current: positional[2],\n json,\n };\n}\n\nconst USAGE = `autotel-schema — treat your trace surface like a versioned public API\n\nUsage:\n autotel-schema diff <baseline.json> <current.json> [--json]\n autotel-schema check <baseline.json> <current.json> [--json]\n\nCommands:\n diff Print every change (breaking / additive / neutral). Always exits 0.\n check Like diff, but exits 1 if any breaking change is found (CI gate).\n\nSnapshots are produced with serializeSnapshot(contractToSnapshot(contract)).`;\n\nfunction loadDiff(baseline: string, current: string): SnapshotDiff {\n const prev = parseSnapshot(readFileSync(baseline, 'utf8'));\n const next = parseSnapshot(readFileSync(current, 'utf8'));\n return diffSnapshots(prev, next);\n}\n\nfunction emit(diff: SnapshotDiff, json: boolean): void {\n if (json) {\n console.log(JSON.stringify(diff, null, 2));\n } else {\n console.log(formatDiff(diff));\n }\n}\n\nexport function run(argv: string[]): number {\n const { command, baseline, current, json } = parseArgs(argv);\n\n if (!command || command === 'help') {\n console.log(USAGE);\n return command ? 0 : 1;\n }\n\n if (command !== 'diff' && command !== 'check') {\n console.error(`autotel-schema: unknown command \"${command}\"\\n\\n${USAGE}`);\n return 1;\n }\n\n if (!baseline || !current) {\n console.error('autotel-schema: both <baseline.json> and <current.json> are required\\n');\n console.error(USAGE);\n return 1;\n }\n\n let diff: SnapshotDiff;\n try {\n diff = loadDiff(baseline, current);\n } catch (error) {\n console.error(\n `autotel-schema: ${error instanceof Error ? error.message : String(error)}`,\n );\n return 1;\n }\n\n emit(diff, json);\n\n if (command === 'check' && hasBreakingChanges(diff)) {\n console.error(\n `\\nautotel-schema: ${diff.breaking.length} breaking change(s) to the telemetry contract. ` +\n `Bump the contract major version and update the committed snapshot.`,\n );\n return 1;\n }\n return 0;\n}\n\n// Only auto-run when invoked directly as the binary, not when imported in tests.\n// Match the basename so a repo path containing \"autotel-schema\" can't trigger it.\nconst entry = process.argv[1] ? path.basename(process.argv[1]) : '';\nif (entry === 'autotel-schema' || entry === 'cli.js' || entry === 'cli.cjs') {\n process.exit(run(process.argv.slice(2)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAS,UAAU,MAAwB;CACzC,MAAM,aAAuB,CAAC;CAC9B,IAAI,OAAO;CACX,KAAK,MAAM,OAAO,MAChB,IAAI,QAAQ,UAAU,OAAO;MACxB,IAAI,QAAQ,QAAQ,QAAQ,UAAU,WAAW,QAAQ,MAAM;MAC/D,WAAW,KAAK,GAAG;CAE1B,OAAO;EACL,SAAS,WAAW;EACpB,UAAU,WAAW;EACrB,SAAS,WAAW;EACpB;CACF;AACF;AAEA,MAAM,QAAQ;;;;;;;;;;;AAYd,SAAS,SAAS,UAAkB,SAA+B;CAGjE,OAAOA,2BAFMC,yDAA2B,UAAU,MAAM,CAEhC,GADXA,yDAA2B,SAAS,MAAM,CACzB,CAAC;AACjC;AAEA,SAAS,KAAK,MAAoB,MAAqB;CACrD,IAAI,MACF,QAAQ,IAAI,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;MAEzC,QAAQ,IAAIC,wBAAW,IAAI,CAAC;AAEhC;AAEA,SAAgB,IAAI,MAAwB;CAC1C,MAAM,EAAE,SAAS,UAAU,SAAS,SAAS,UAAU,IAAI;CAE3D,IAAI,CAAC,WAAW,YAAY,QAAQ;EAClC,QAAQ,IAAI,KAAK;EACjB,OAAO,UAAU,IAAI;CACvB;CAEA,IAAI,YAAY,UAAU,YAAY,SAAS;EAC7C,QAAQ,MAAM,oCAAoC,QAAQ,OAAO,OAAO;EACxE,OAAO;CACT;CAEA,IAAI,CAAC,YAAY,CAAC,SAAS;EACzB,QAAQ,
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["diffSnapshots","parseSnapshot","formatDiff","hasBreakingChanges","path"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * autotel-schema CLI — the CI gate for your telemetry's public API.\n *\n * autotel-schema diff <baseline.json> <current.json> # classify changes\n * autotel-schema check <baseline.json> <current.json> # exit 1 on breaking\n *\n * Both operate on snapshot JSON produced by `serializeSnapshot(contractToSnapshot(contract))`.\n * Commit the baseline; regenerate `current` in CI; gate the merge on `check`.\n */\n\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseSnapshot } from './snapshot.js';\nimport {\n diffSnapshots,\n formatDiff,\n hasBreakingChanges,\n type SnapshotDiff,\n} from './diff.js';\n\ninterface Parsed {\n command: string | undefined;\n baseline: string | undefined;\n current: string | undefined;\n json: boolean;\n}\n\nfunction parseArgs(argv: string[]): Parsed {\n const positional: string[] = [];\n let json = false;\n for (const arg of argv) {\n if (arg === '--json') json = true;\n else if (arg === '-h' || arg === '--help') positional.unshift('help');\n else positional.push(arg);\n }\n return {\n command: positional[0],\n baseline: positional[1],\n current: positional[2],\n json,\n };\n}\n\nconst USAGE = `autotel-schema — treat your trace surface like a versioned public API\n\nUsage:\n autotel-schema diff <baseline.json> <current.json> [--json]\n autotel-schema check <baseline.json> <current.json> [--json]\n\nCommands:\n diff Print every change (breaking / additive / neutral). Always exits 0.\n check Like diff, but exits 1 if any breaking change is found (CI gate).\n\nSnapshots are produced with serializeSnapshot(contractToSnapshot(contract)).`;\n\nfunction loadDiff(baseline: string, current: string): SnapshotDiff {\n const prev = parseSnapshot(readFileSync(baseline, 'utf8'));\n const next = parseSnapshot(readFileSync(current, 'utf8'));\n return diffSnapshots(prev, next);\n}\n\nfunction emit(diff: SnapshotDiff, json: boolean): void {\n if (json) {\n console.log(JSON.stringify(diff, null, 2));\n } else {\n console.log(formatDiff(diff));\n }\n}\n\nexport function run(argv: string[]): number {\n const { command, baseline, current, json } = parseArgs(argv);\n\n if (!command || command === 'help') {\n console.log(USAGE);\n return command ? 0 : 1;\n }\n\n if (command !== 'diff' && command !== 'check') {\n console.error(`autotel-schema: unknown command \"${command}\"\\n\\n${USAGE}`);\n return 1;\n }\n\n if (!baseline || !current) {\n console.error(\n 'autotel-schema: both <baseline.json> and <current.json> are required\\n',\n );\n console.error(USAGE);\n return 1;\n }\n\n let diff: SnapshotDiff;\n try {\n diff = loadDiff(baseline, current);\n } catch (error) {\n console.error(\n `autotel-schema: ${error instanceof Error ? error.message : String(error)}`,\n );\n return 1;\n }\n\n emit(diff, json);\n\n if (command === 'check' && hasBreakingChanges(diff)) {\n console.error(\n `\\nautotel-schema: ${diff.breaking.length} breaking change(s) to the telemetry contract. ` +\n `Bump the contract major version and update the committed snapshot.`,\n );\n return 1;\n }\n return 0;\n}\n\n// Only auto-run when invoked directly as the binary, not when imported in tests.\n// Match the basename so a repo path containing \"autotel-schema\" can't trigger it.\nconst entry = process.argv[1] ? path.basename(process.argv[1]) : '';\nif (entry === 'autotel-schema' || entry === 'cli.js' || entry === 'cli.cjs') {\n process.exit(run(process.argv.slice(2)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAS,UAAU,MAAwB;CACzC,MAAM,aAAuB,CAAC;CAC9B,IAAI,OAAO;CACX,KAAK,MAAM,OAAO,MAChB,IAAI,QAAQ,UAAU,OAAO;MACxB,IAAI,QAAQ,QAAQ,QAAQ,UAAU,WAAW,QAAQ,MAAM;MAC/D,WAAW,KAAK,GAAG;CAE1B,OAAO;EACL,SAAS,WAAW;EACpB,UAAU,WAAW;EACrB,SAAS,WAAW;EACpB;CACF;AACF;AAEA,MAAM,QAAQ;;;;;;;;;;;AAYd,SAAS,SAAS,UAAkB,SAA+B;CAGjE,OAAOA,2BAFMC,yDAA2B,UAAU,MAAM,CAEhC,GADXA,yDAA2B,SAAS,MAAM,CACzB,CAAC;AACjC;AAEA,SAAS,KAAK,MAAoB,MAAqB;CACrD,IAAI,MACF,QAAQ,IAAI,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;MAEzC,QAAQ,IAAIC,wBAAW,IAAI,CAAC;AAEhC;AAEA,SAAgB,IAAI,MAAwB;CAC1C,MAAM,EAAE,SAAS,UAAU,SAAS,SAAS,UAAU,IAAI;CAE3D,IAAI,CAAC,WAAW,YAAY,QAAQ;EAClC,QAAQ,IAAI,KAAK;EACjB,OAAO,UAAU,IAAI;CACvB;CAEA,IAAI,YAAY,UAAU,YAAY,SAAS;EAC7C,QAAQ,MAAM,oCAAoC,QAAQ,OAAO,OAAO;EACxE,OAAO;CACT;CAEA,IAAI,CAAC,YAAY,CAAC,SAAS;EACzB,QAAQ,MACN,wEACF;EACA,QAAQ,MAAM,KAAK;EACnB,OAAO;CACT;CAEA,IAAI;CACJ,IAAI;EACF,OAAO,SAAS,UAAU,OAAO;CACnC,SAAS,OAAO;EACd,QAAQ,MACN,mBAAmB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC1E;EACA,OAAO;CACT;CAEA,KAAK,MAAM,IAAI;CAEf,IAAI,YAAY,WAAWC,gCAAmB,IAAI,GAAG;EACnD,QAAQ,MACN,qBAAqB,KAAK,SAAS,OAAO,kHAE5C;EACA,OAAO;CACT;CACA,OAAO;AACT;AAIA,MAAM,QAAQ,QAAQ,KAAK,KAAKC,kBAAK,SAAS,QAAQ,KAAK,EAAE,IAAI;AACjE,IAAI,UAAU,oBAAoB,UAAU,YAAY,UAAU,WAChE,QAAQ,KAAK,IAAI,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC"}
|
package/dist/cli.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.cts","names":[],"sources":["../src/cli.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.cts","names":[],"sources":["../src/cli.ts"],"mappings":";;;;;;;;;;iBAsEgB,IAAI"}
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","names":[],"sources":["../src/cli.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","names":[],"sources":["../src/cli.ts"],"mappings":";;;;;;;;;;iBAsEgB,IAAI"}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * autotel-schema CLI — the CI gate for your telemetry's public API.\n *\n * autotel-schema diff <baseline.json> <current.json> # classify changes\n * autotel-schema check <baseline.json> <current.json> # exit 1 on breaking\n *\n * Both operate on snapshot JSON produced by `serializeSnapshot(contractToSnapshot(contract))`.\n * Commit the baseline; regenerate `current` in CI; gate the merge on `check`.\n */\n\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseSnapshot } from './snapshot.js';\nimport {\n diffSnapshots,\n formatDiff,\n hasBreakingChanges,\n type SnapshotDiff,\n} from './diff.js';\n\ninterface Parsed {\n command: string | undefined;\n baseline: string | undefined;\n current: string | undefined;\n json: boolean;\n}\n\nfunction parseArgs(argv: string[]): Parsed {\n const positional: string[] = [];\n let json = false;\n for (const arg of argv) {\n if (arg === '--json') json = true;\n else if (arg === '-h' || arg === '--help') positional.unshift('help');\n else positional.push(arg);\n }\n return {\n command: positional[0],\n baseline: positional[1],\n current: positional[2],\n json,\n };\n}\n\nconst USAGE = `autotel-schema — treat your trace surface like a versioned public API\n\nUsage:\n autotel-schema diff <baseline.json> <current.json> [--json]\n autotel-schema check <baseline.json> <current.json> [--json]\n\nCommands:\n diff Print every change (breaking / additive / neutral). Always exits 0.\n check Like diff, but exits 1 if any breaking change is found (CI gate).\n\nSnapshots are produced with serializeSnapshot(contractToSnapshot(contract)).`;\n\nfunction loadDiff(baseline: string, current: string): SnapshotDiff {\n const prev = parseSnapshot(readFileSync(baseline, 'utf8'));\n const next = parseSnapshot(readFileSync(current, 'utf8'));\n return diffSnapshots(prev, next);\n}\n\nfunction emit(diff: SnapshotDiff, json: boolean): void {\n if (json) {\n console.log(JSON.stringify(diff, null, 2));\n } else {\n console.log(formatDiff(diff));\n }\n}\n\nexport function run(argv: string[]): number {\n const { command, baseline, current, json } = parseArgs(argv);\n\n if (!command || command === 'help') {\n console.log(USAGE);\n return command ? 0 : 1;\n }\n\n if (command !== 'diff' && command !== 'check') {\n console.error(`autotel-schema: unknown command \"${command}\"\\n\\n${USAGE}`);\n return 1;\n }\n\n if (!baseline || !current) {\n console.error('autotel-schema: both <baseline.json> and <current.json> are required\\n');\n console.error(USAGE);\n return 1;\n }\n\n let diff: SnapshotDiff;\n try {\n diff = loadDiff(baseline, current);\n } catch (error) {\n console.error(\n `autotel-schema: ${error instanceof Error ? error.message : String(error)}`,\n );\n return 1;\n }\n\n emit(diff, json);\n\n if (command === 'check' && hasBreakingChanges(diff)) {\n console.error(\n `\\nautotel-schema: ${diff.breaking.length} breaking change(s) to the telemetry contract. ` +\n `Bump the contract major version and update the committed snapshot.`,\n );\n return 1;\n }\n return 0;\n}\n\n// Only auto-run when invoked directly as the binary, not when imported in tests.\n// Match the basename so a repo path containing \"autotel-schema\" can't trigger it.\nconst entry = process.argv[1] ? path.basename(process.argv[1]) : '';\nif (entry === 'autotel-schema' || entry === 'cli.js' || entry === 'cli.cjs') {\n process.exit(run(process.argv.slice(2)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAS,UAAU,MAAwB;CACzC,MAAM,aAAuB,CAAC;CAC9B,IAAI,OAAO;CACX,KAAK,MAAM,OAAO,MAChB,IAAI,QAAQ,UAAU,OAAO;MACxB,IAAI,QAAQ,QAAQ,QAAQ,UAAU,WAAW,QAAQ,MAAM;MAC/D,WAAW,KAAK,GAAG;CAE1B,OAAO;EACL,SAAS,WAAW;EACpB,UAAU,WAAW;EACrB,SAAS,WAAW;EACpB;CACF;AACF;AAEA,MAAM,QAAQ;;;;;;;;;;;AAYd,SAAS,SAAS,UAAkB,SAA+B;CAGjE,OAAO,cAFM,cAAc,aAAa,UAAU,MAAM,CAEhC,GADX,cAAc,aAAa,SAAS,MAAM,CACzB,CAAC;AACjC;AAEA,SAAS,KAAK,MAAoB,MAAqB;CACrD,IAAI,MACF,QAAQ,IAAI,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;MAEzC,QAAQ,IAAI,WAAW,IAAI,CAAC;AAEhC;AAEA,SAAgB,IAAI,MAAwB;CAC1C,MAAM,EAAE,SAAS,UAAU,SAAS,SAAS,UAAU,IAAI;CAE3D,IAAI,CAAC,WAAW,YAAY,QAAQ;EAClC,QAAQ,IAAI,KAAK;EACjB,OAAO,UAAU,IAAI;CACvB;CAEA,IAAI,YAAY,UAAU,YAAY,SAAS;EAC7C,QAAQ,MAAM,oCAAoC,QAAQ,OAAO,OAAO;EACxE,OAAO;CACT;CAEA,IAAI,CAAC,YAAY,CAAC,SAAS;EACzB,QAAQ,
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * autotel-schema CLI — the CI gate for your telemetry's public API.\n *\n * autotel-schema diff <baseline.json> <current.json> # classify changes\n * autotel-schema check <baseline.json> <current.json> # exit 1 on breaking\n *\n * Both operate on snapshot JSON produced by `serializeSnapshot(contractToSnapshot(contract))`.\n * Commit the baseline; regenerate `current` in CI; gate the merge on `check`.\n */\n\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseSnapshot } from './snapshot.js';\nimport {\n diffSnapshots,\n formatDiff,\n hasBreakingChanges,\n type SnapshotDiff,\n} from './diff.js';\n\ninterface Parsed {\n command: string | undefined;\n baseline: string | undefined;\n current: string | undefined;\n json: boolean;\n}\n\nfunction parseArgs(argv: string[]): Parsed {\n const positional: string[] = [];\n let json = false;\n for (const arg of argv) {\n if (arg === '--json') json = true;\n else if (arg === '-h' || arg === '--help') positional.unshift('help');\n else positional.push(arg);\n }\n return {\n command: positional[0],\n baseline: positional[1],\n current: positional[2],\n json,\n };\n}\n\nconst USAGE = `autotel-schema — treat your trace surface like a versioned public API\n\nUsage:\n autotel-schema diff <baseline.json> <current.json> [--json]\n autotel-schema check <baseline.json> <current.json> [--json]\n\nCommands:\n diff Print every change (breaking / additive / neutral). Always exits 0.\n check Like diff, but exits 1 if any breaking change is found (CI gate).\n\nSnapshots are produced with serializeSnapshot(contractToSnapshot(contract)).`;\n\nfunction loadDiff(baseline: string, current: string): SnapshotDiff {\n const prev = parseSnapshot(readFileSync(baseline, 'utf8'));\n const next = parseSnapshot(readFileSync(current, 'utf8'));\n return diffSnapshots(prev, next);\n}\n\nfunction emit(diff: SnapshotDiff, json: boolean): void {\n if (json) {\n console.log(JSON.stringify(diff, null, 2));\n } else {\n console.log(formatDiff(diff));\n }\n}\n\nexport function run(argv: string[]): number {\n const { command, baseline, current, json } = parseArgs(argv);\n\n if (!command || command === 'help') {\n console.log(USAGE);\n return command ? 0 : 1;\n }\n\n if (command !== 'diff' && command !== 'check') {\n console.error(`autotel-schema: unknown command \"${command}\"\\n\\n${USAGE}`);\n return 1;\n }\n\n if (!baseline || !current) {\n console.error(\n 'autotel-schema: both <baseline.json> and <current.json> are required\\n',\n );\n console.error(USAGE);\n return 1;\n }\n\n let diff: SnapshotDiff;\n try {\n diff = loadDiff(baseline, current);\n } catch (error) {\n console.error(\n `autotel-schema: ${error instanceof Error ? error.message : String(error)}`,\n );\n return 1;\n }\n\n emit(diff, json);\n\n if (command === 'check' && hasBreakingChanges(diff)) {\n console.error(\n `\\nautotel-schema: ${diff.breaking.length} breaking change(s) to the telemetry contract. ` +\n `Bump the contract major version and update the committed snapshot.`,\n );\n return 1;\n }\n return 0;\n}\n\n// Only auto-run when invoked directly as the binary, not when imported in tests.\n// Match the basename so a repo path containing \"autotel-schema\" can't trigger it.\nconst entry = process.argv[1] ? path.basename(process.argv[1]) : '';\nif (entry === 'autotel-schema' || entry === 'cli.js' || entry === 'cli.cjs') {\n process.exit(run(process.argv.slice(2)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAS,UAAU,MAAwB;CACzC,MAAM,aAAuB,CAAC;CAC9B,IAAI,OAAO;CACX,KAAK,MAAM,OAAO,MAChB,IAAI,QAAQ,UAAU,OAAO;MACxB,IAAI,QAAQ,QAAQ,QAAQ,UAAU,WAAW,QAAQ,MAAM;MAC/D,WAAW,KAAK,GAAG;CAE1B,OAAO;EACL,SAAS,WAAW;EACpB,UAAU,WAAW;EACrB,SAAS,WAAW;EACpB;CACF;AACF;AAEA,MAAM,QAAQ;;;;;;;;;;;AAYd,SAAS,SAAS,UAAkB,SAA+B;CAGjE,OAAO,cAFM,cAAc,aAAa,UAAU,MAAM,CAEhC,GADX,cAAc,aAAa,SAAS,MAAM,CACzB,CAAC;AACjC;AAEA,SAAS,KAAK,MAAoB,MAAqB;CACrD,IAAI,MACF,QAAQ,IAAI,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;MAEzC,QAAQ,IAAI,WAAW,IAAI,CAAC;AAEhC;AAEA,SAAgB,IAAI,MAAwB;CAC1C,MAAM,EAAE,SAAS,UAAU,SAAS,SAAS,UAAU,IAAI;CAE3D,IAAI,CAAC,WAAW,YAAY,QAAQ;EAClC,QAAQ,IAAI,KAAK;EACjB,OAAO,UAAU,IAAI;CACvB;CAEA,IAAI,YAAY,UAAU,YAAY,SAAS;EAC7C,QAAQ,MAAM,oCAAoC,QAAQ,OAAO,OAAO;EACxE,OAAO;CACT;CAEA,IAAI,CAAC,YAAY,CAAC,SAAS;EACzB,QAAQ,MACN,wEACF;EACA,QAAQ,MAAM,KAAK;EACnB,OAAO;CACT;CAEA,IAAI;CACJ,IAAI;EACF,OAAO,SAAS,UAAU,OAAO;CACnC,SAAS,OAAO;EACd,QAAQ,MACN,mBAAmB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC1E;EACA,OAAO;CACT;CAEA,KAAK,MAAM,IAAI;CAEf,IAAI,YAAY,WAAW,mBAAmB,IAAI,GAAG;EACnD,QAAQ,MACN,qBAAqB,KAAK,SAAS,OAAO,kHAE5C;EACA,OAAO;CACT;CACA,OAAO;AACT;AAIA,MAAM,QAAQ,QAAQ,KAAK,KAAK,KAAK,SAAS,QAAQ,KAAK,EAAE,IAAI;AACjE,IAAI,UAAU,oBAAoB,UAAU,YAAY,UAAU,WAChE,QAAQ,KAAK,IAAI,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
//#region src/scenario.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Scenario conformance — a flow-level contract checked against collected spans.
|
|
4
|
+
*
|
|
5
|
+
* Where {@link ./contract} declares the *surface* of your telemetry (span
|
|
6
|
+
* names + attributes), a scenario declares the *behaviour* of one exercised
|
|
7
|
+
* flow: which events must fire, how many times, in what parent/child
|
|
8
|
+
* topology, and — critically — **when the observation is complete**, because
|
|
9
|
+
* for an async flow a missing event and an event that has not fired *yet* are
|
|
10
|
+
* indistinguishable without a completion boundary.
|
|
11
|
+
*
|
|
12
|
+
* Checking a scenario yields one of three outcomes, not two:
|
|
13
|
+
*
|
|
14
|
+
* - `conformant` — the boundary closed and the signature satisfied the contract
|
|
15
|
+
* - `non-conformant` — required behaviour was missing or invalid (definitive)
|
|
16
|
+
* - `incomplete` — the boundary did not close within the observation budget;
|
|
17
|
+
* infrastructure slowness is *not* reported as behavioural regression
|
|
18
|
+
*
|
|
19
|
+
* Absence is definitive only after closure (closed-world semantics). Excess
|
|
20
|
+
* is definitive immediately: a `max` cardinality violation or an unexpected
|
|
21
|
+
* error span fails the check even while the flow is still open.
|
|
22
|
+
*
|
|
23
|
+
* Undeclared events are **additive**: reported in `result.additions`, never a
|
|
24
|
+
* failure — improving instrumentation must not break CI.
|
|
25
|
+
*
|
|
26
|
+
* The span input shape is structurally compatible with `SerializedSpan` from
|
|
27
|
+
* `autotel/test-span-collector`, so a test can feed a collector's output
|
|
28
|
+
* straight in. Like the rest of this package the module is dependency-free —
|
|
29
|
+
* usable from vitest, a deferred reconciliation job, or a CLI alike.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const result = await checkScenario(
|
|
34
|
+
* contract.scenarios!['transfer.accept'],
|
|
35
|
+
* () => collector.peekTrace(traceId),
|
|
36
|
+
* { name: 'transfer.accept' },
|
|
37
|
+
* );
|
|
38
|
+
* if (result.outcome === 'non-conformant') throw new Error(formatScenarioResult(result));
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
/** A finished span/event as the scenario checker sees it. */
|
|
42
|
+
interface ScenarioSpan {
|
|
43
|
+
spanId: string;
|
|
44
|
+
parentSpanId?: string;
|
|
45
|
+
name: string;
|
|
46
|
+
status: 'ok' | 'error' | 'unset';
|
|
47
|
+
attributes?: Record<string, unknown>;
|
|
48
|
+
/** Epoch ms. Optional — used by {@link proposeScenario} to suggest budgets. */
|
|
49
|
+
startTimeMs?: number;
|
|
50
|
+
durationMs?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Canonical cardinality range. `max` omitted = unbounded. */
|
|
53
|
+
interface Cardinality {
|
|
54
|
+
min: number;
|
|
55
|
+
max?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse a cardinality shorthand: `'exactly 1'`, `'at least 1'`, `'at most 3'`,
|
|
59
|
+
* `'0..1'`, `'2..'`. A canonical {@link Cardinality} passes through.
|
|
60
|
+
*/
|
|
61
|
+
declare function parseCardinality(input: string | Cardinality): Cardinality;
|
|
62
|
+
/** Declaration for one event (span name) a scenario expects to observe. */
|
|
63
|
+
interface ScenarioEventSpec {
|
|
64
|
+
/** How many occurrences are permitted. Defaults to `'at least 1'`. */
|
|
65
|
+
cardinality?: string | Cardinality;
|
|
66
|
+
/**
|
|
67
|
+
* Expected terminal status. Defaults to non-error: an `error` status on an
|
|
68
|
+
* event not declared `status: 'error'` is a definitive violation.
|
|
69
|
+
*/
|
|
70
|
+
status?: 'ok' | 'error';
|
|
71
|
+
description?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* How the observed phase of a scenario becomes complete. Every async
|
|
75
|
+
* conformance check must declare this — it is what makes absence meaningful.
|
|
76
|
+
*
|
|
77
|
+
* `externally-reconciled` never closes in-process: the phase is verified
|
|
78
|
+
* elsewhere (a deferred reconciliation job keyed by a durable business ID),
|
|
79
|
+
* so an in-process check reports at most definitive violations, never absence.
|
|
80
|
+
*/
|
|
81
|
+
type CompletionBoundary = {
|
|
82
|
+
mode: 'root-span-closed';
|
|
83
|
+
observationBudgetMs: number;
|
|
84
|
+
} | {
|
|
85
|
+
mode: 'terminal-event';
|
|
86
|
+
event: string;
|
|
87
|
+
observationBudgetMs: number;
|
|
88
|
+
} | {
|
|
89
|
+
mode: 'externally-reconciled';
|
|
90
|
+
reconciliationDeadlineMs: number;
|
|
91
|
+
};
|
|
92
|
+
/** The flow-level contract for one exercised scenario (or one phase of one). */
|
|
93
|
+
interface ScenarioSpec {
|
|
94
|
+
description?: string;
|
|
95
|
+
/** When the observed phase is complete. See {@link CompletionBoundary}. */
|
|
96
|
+
completion: CompletionBoundary;
|
|
97
|
+
/** Events this scenario must (or may) observe, keyed by span name. */
|
|
98
|
+
events: Record<string, ScenarioEventSpec>;
|
|
99
|
+
/**
|
|
100
|
+
* Required ancestor→descendant edges by span name. Ancestor — not immediate
|
|
101
|
+
* parent — so a framework span inserted between the two does not break the
|
|
102
|
+
* contract (canonicalisation: infrastructure spans are not behaviour).
|
|
103
|
+
*/
|
|
104
|
+
edges?: ReadonlyArray<readonly [string, string]>;
|
|
105
|
+
/** Edges that may appear but are not required. Documented, never enforced. */
|
|
106
|
+
optionalEdges?: ReadonlyArray<readonly [string, string]>;
|
|
107
|
+
}
|
|
108
|
+
type ScenarioOutcome = 'conformant' | 'non-conformant' | 'incomplete';
|
|
109
|
+
type ScenarioViolationCode = 'missing_event' | 'cardinality_violation' | 'missing_edge' | 'unexpected_error';
|
|
110
|
+
/** A definitive (breaking) discrepancy between observed spans and the scenario. */
|
|
111
|
+
interface ScenarioViolation {
|
|
112
|
+
code: ScenarioViolationCode;
|
|
113
|
+
event?: string;
|
|
114
|
+
edge?: readonly [string, string];
|
|
115
|
+
message: string;
|
|
116
|
+
}
|
|
117
|
+
/** An additive observation — reported, never a failure. */
|
|
118
|
+
interface ScenarioAddition {
|
|
119
|
+
code: 'undeclared_event';
|
|
120
|
+
event: string;
|
|
121
|
+
count: number;
|
|
122
|
+
message: string;
|
|
123
|
+
}
|
|
124
|
+
interface ScenarioResult {
|
|
125
|
+
scenario: string;
|
|
126
|
+
outcome: ScenarioOutcome;
|
|
127
|
+
/** Whether the completion boundary closed within the observation window. */
|
|
128
|
+
closed: boolean;
|
|
129
|
+
violations: ScenarioViolation[];
|
|
130
|
+
additions: ScenarioAddition[];
|
|
131
|
+
/** The evaluated snapshot — assert business values on this in your test. */
|
|
132
|
+
spans: ScenarioSpan[];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Structural validation for one scenario declaration. Called by
|
|
136
|
+
* `defineContract()` so a malformed scenario throws at module load.
|
|
137
|
+
*/
|
|
138
|
+
declare function validateScenarioSpec(name: string, spec: ScenarioSpec): void;
|
|
139
|
+
/** Whether the scenario's completion boundary has closed for these spans. */
|
|
140
|
+
declare function isScenarioClosed(spec: ScenarioSpec, spans: readonly ScenarioSpan[]): boolean;
|
|
141
|
+
interface EvaluateScenarioOptions {
|
|
142
|
+
/** Name used in the result/messages. Defaults to `'scenario'`. */
|
|
143
|
+
name?: string;
|
|
144
|
+
/** Override closure detection (e.g. the poller already knows). */
|
|
145
|
+
closed?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Pure three-state evaluation of collected spans against a scenario.
|
|
149
|
+
*
|
|
150
|
+
* Definitive at any time (no closure needed): an unexpected error status, a
|
|
151
|
+
* `max` cardinality exceeded. Meaningful only after closure: a missing event,
|
|
152
|
+
* a `min` cardinality not reached, a missing required edge.
|
|
153
|
+
*/
|
|
154
|
+
declare function evaluateScenario(spec: ScenarioSpec, spans: readonly ScenarioSpan[], options?: EvaluateScenarioOptions): ScenarioResult;
|
|
155
|
+
interface CheckScenarioOptions {
|
|
156
|
+
/** Name used in the result/messages. Defaults to `'scenario'`. */
|
|
157
|
+
name?: string;
|
|
158
|
+
/** Poll interval while waiting for closure. Default 25ms. */
|
|
159
|
+
pollIntervalMs?: number;
|
|
160
|
+
/** Override the boundary's observation budget (how long the checker waits). */
|
|
161
|
+
budgetMs?: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Poll `getSpans` until the scenario's completion boundary closes, a
|
|
165
|
+
* definitive violation appears (fail fast), or the observation budget is
|
|
166
|
+
* spent — then evaluate.
|
|
167
|
+
*
|
|
168
|
+
* The observation budget bounds how long *this checker* waits; it is not a
|
|
169
|
+
* statement that the operation is allowed to take that long. Express a
|
|
170
|
+
* business deadline as its own assertion on the returned spans.
|
|
171
|
+
*
|
|
172
|
+
* An `externally-reconciled` boundary never closes in-process: the check
|
|
173
|
+
* evaluates the current snapshot once and reports `incomplete` unless a
|
|
174
|
+
* definitive violation is already present.
|
|
175
|
+
*/
|
|
176
|
+
declare function checkScenario(spec: ScenarioSpec, getSpans: () => readonly ScenarioSpan[] | Promise<readonly ScenarioSpan[]>, options?: CheckScenarioOptions): Promise<ScenarioResult>;
|
|
177
|
+
/** Human-readable summary of a scenario result, for assertion messages. */
|
|
178
|
+
declare function formatScenarioResult(result: ScenarioResult): string;
|
|
179
|
+
interface ScenarioProposal {
|
|
180
|
+
scenario: ScenarioSpec;
|
|
181
|
+
/** Review annotations — what was observed and what to double-check. */
|
|
182
|
+
notes: string[];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Draft a scenario contract from repeated controlled runs (record → propose →
|
|
186
|
+
* commit). Events stable across every run become required with their observed
|
|
187
|
+
* cardinality; variable ones get a range and a review note. The draft is a
|
|
188
|
+
* starting point for human curation, not a finished contract.
|
|
189
|
+
*/
|
|
190
|
+
declare function proposeScenario(runs: ReadonlyArray<ReadonlyArray<ScenarioSpan>>, options?: {
|
|
191
|
+
name?: string;
|
|
192
|
+
}): ScenarioProposal;
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/contract.d.ts
|
|
195
|
+
/** Scalar and array attribute types permitted on a span (OTLP value shapes). */
|
|
196
|
+
type AttributeType = 'string' | 'number' | 'boolean' | 'string[]' | 'number[]' | 'boolean[]';
|
|
197
|
+
declare const ATTRIBUTE_TYPES: readonly AttributeType[];
|
|
198
|
+
/**
|
|
199
|
+
* Lifecycle of a span or attribute, mirroring how the OpenTelemetry semantic
|
|
200
|
+
* conventions stage their own surface. `stable` is a promise to agent readers
|
|
201
|
+
* that the name will not change without a major contract bump.
|
|
202
|
+
*/
|
|
203
|
+
type Stability = 'stable' | 'experimental' | 'deprecated';
|
|
204
|
+
declare const STABILITIES: readonly Stability[];
|
|
205
|
+
/** Declaration for a single attribute key on a span. */
|
|
206
|
+
interface AttributeSpec {
|
|
207
|
+
/** OTLP value shape. Validated at runtime against the emitted value. */
|
|
208
|
+
type: AttributeType;
|
|
209
|
+
/** Lifecycle stage. Defaults to `stable`. */
|
|
210
|
+
stability?: Stability;
|
|
211
|
+
/** When `true`, the attribute must be present on every matching span. */
|
|
212
|
+
required?: boolean;
|
|
213
|
+
/** Human/agent-facing description of what the attribute means. */
|
|
214
|
+
description?: string;
|
|
215
|
+
/**
|
|
216
|
+
* Marks an attribute as intentionally high-cardinality (user id, sender
|
|
217
|
+
* domain, request id). For an agent reader these are the single most useful
|
|
218
|
+
* fields on a trace, so {@link ./redaction.highCardinalityKeys} surfaces them
|
|
219
|
+
* as a *protect* list — telling redactors/normalizers NOT to strip them.
|
|
220
|
+
*/
|
|
221
|
+
highCardinality?: boolean;
|
|
222
|
+
/** Closed set of permitted values. Reported as `enum_violation` if exceeded. */
|
|
223
|
+
enum?: readonly (string | number)[];
|
|
224
|
+
/** Set when `stability: 'deprecated'`; explains what to use instead. */
|
|
225
|
+
replacedBy?: string;
|
|
226
|
+
/** Free-text note shown alongside deprecation warnings. */
|
|
227
|
+
deprecatedReason?: string;
|
|
228
|
+
}
|
|
229
|
+
/** Declaration for a single span name your service emits. */
|
|
230
|
+
interface SpanSpec {
|
|
231
|
+
/** Human/agent-facing description of when this span is produced. */
|
|
232
|
+
description?: string;
|
|
233
|
+
/** Lifecycle stage. Defaults to `stable`. */
|
|
234
|
+
stability?: Stability;
|
|
235
|
+
/** Attributes specific to this span, keyed by attribute name. */
|
|
236
|
+
attributes?: Record<string, AttributeSpec>;
|
|
237
|
+
/**
|
|
238
|
+
* When `true`, attributes not declared here are allowed without an
|
|
239
|
+
* `unknown_attribute` violation. Defaults to the contract-level setting.
|
|
240
|
+
*/
|
|
241
|
+
additionalAttributes?: boolean;
|
|
242
|
+
}
|
|
243
|
+
/** The full telemetry contract for one service. */
|
|
244
|
+
interface TelemetryContract {
|
|
245
|
+
/** `service.name` this contract describes. */
|
|
246
|
+
service: string;
|
|
247
|
+
/**
|
|
248
|
+
* Semver of the *contract itself* (not the app). Bumped when the trace
|
|
249
|
+
* surface changes; surfaced to readers as the `telemetry.schema.version`
|
|
250
|
+
* resource attribute via {@link ./attrs.SCHEMA_ATTRS}.
|
|
251
|
+
*/
|
|
252
|
+
version: string;
|
|
253
|
+
/** Spans this service emits, keyed by span name. */
|
|
254
|
+
spans: Record<string, SpanSpec>;
|
|
255
|
+
/** Attributes permitted on *any* span (e.g. `user.id`, `tenant.id`). */
|
|
256
|
+
commonAttributes?: Record<string, AttributeSpec>;
|
|
257
|
+
/**
|
|
258
|
+
* Default for `SpanSpec.additionalAttributes` when a span does not set it.
|
|
259
|
+
* Defaults to `false` (declared-only — the stricter, agent-friendlier mode).
|
|
260
|
+
*/
|
|
261
|
+
additionalAttributes?: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Flow-level scenario contracts, keyed by scenario name: which events one
|
|
264
|
+
* exercised flow must emit, their cardinality and topology, and when the
|
|
265
|
+
* observation is complete. Checked with `checkScenario` ({@link ./scenario}).
|
|
266
|
+
*/
|
|
267
|
+
scenarios?: Record<string, ScenarioSpec>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Validate and freeze a telemetry contract. Throws on structural mistakes
|
|
271
|
+
* (bad semver, unknown attribute type, deprecation with no replacement) so the
|
|
272
|
+
* contract fails loudly at module load, not silently at runtime.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* export const contract = defineContract({
|
|
277
|
+
* service: 'checkout',
|
|
278
|
+
* version: '1.2.0',
|
|
279
|
+
* commonAttributes: {
|
|
280
|
+
* 'user.id': { type: 'string', highCardinality: true, description: 'Authenticated user' },
|
|
281
|
+
* },
|
|
282
|
+
* spans: {
|
|
283
|
+
* 'checkout.charge': {
|
|
284
|
+
* description: 'Charge a payment method',
|
|
285
|
+
* attributes: {
|
|
286
|
+
* 'payment.provider': { type: 'string', required: true, enum: ['stripe', 'paypal'] },
|
|
287
|
+
* 'payment.amount_cents': { type: 'number', required: true },
|
|
288
|
+
* },
|
|
289
|
+
* },
|
|
290
|
+
* },
|
|
291
|
+
* });
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
declare function defineContract(contract: TelemetryContract): TelemetryContract;
|
|
295
|
+
/**
|
|
296
|
+
* Resolve the effective attribute spec for `key` on `spanName`: span-specific
|
|
297
|
+
* attributes win over common attributes. Returns `undefined` when the key is
|
|
298
|
+
* declared nowhere.
|
|
299
|
+
*/
|
|
300
|
+
declare function resolveAttributeSpec(contract: TelemetryContract, spanName: string, key: string): AttributeSpec | undefined;
|
|
301
|
+
/** Whether attributes outside the declared set are tolerated for a span. */
|
|
302
|
+
declare function allowsAdditionalAttributes(contract: TelemetryContract, spanName: string): boolean;
|
|
303
|
+
//#endregion
|
|
304
|
+
export { validateScenarioSpec as A, ScenarioViolationCode as C, isScenarioClosed as D, formatScenarioResult as E, parseCardinality as O, ScenarioViolation as S, evaluateScenario as T, ScenarioOutcome as _, SpanSpec as a, ScenarioSpan as b, allowsAdditionalAttributes as c, Cardinality as d, CheckScenarioOptions as f, ScenarioEventSpec as g, ScenarioAddition as h, STABILITIES as i, proposeScenario as k, defineContract as l, EvaluateScenarioOptions as m, AttributeSpec as n, Stability as o, CompletionBoundary as p, AttributeType as r, TelemetryContract as s, ATTRIBUTE_TYPES as t, resolveAttributeSpec as u, ScenarioProposal as v, checkScenario as w, ScenarioSpec as x, ScenarioResult as y };
|
|
305
|
+
//# sourceMappingURL=contract-Ymh_Q37N.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-Ymh_Q37N.d.cts","names":[],"sources":["../src/scenario.ts","../src/contract.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAyCiB;EACf;EACA;EACA;EACA;EACA,aAAa;;EAEb;EACA;;;UAIe;EACf;EACA;;;;;;iBAOc,iBAAiB,gBAAgB,cAAc;;UAmC9C;;EAEf,uBAAuB;;;;;EAKvB;EACA;;;;;;;;;;KAWU;EACN;EAA0B;;EAC1B;EAAwB;EAAe;;EACvC;EAA+B;;;UAGpB;EACf;;EAEA,YAAY;;EAEZ,QAAQ,eAAe;;;;;;EAMvB,QAAQ;;EAER,gBAAgB;;KAGN;KAEA;;UAOK;EACf,MAAM;EACN;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA,SAAS;;EAET;EACA,YAAY;EACZ,WAAW;;EAEX,OAAO;;;;;;iBAmBO,qBAAqB,cAAc,MAAM;;iBA8DzC,iBACd,MAAM,cACN,gBAAgB;UAgCD;;EAEf;;EAEA;;;;;;;;;iBAUc,iBACd,MAAM,cACN,gBAAgB,gBAChB,UAAU,0BACT;UA0Fc;;EAEf;;EAEA;;EAEA;;;;;;;;;;;;;;;iBAgBoB,cACpB,MAAM,cACN,yBAAyB,iBAAiB,iBAAiB,iBAC3D,UAAU,uBACT,QAAQ;;iBAkDK,qBAAqB,QAAQ;UAS5B;EACf,UAAU;;EAEV;;;;;;;;iBASc,gBACd,MAAM,cAAc,cAAc,gBAClC;EAAY;IACX;;;;KCxdS;cAGC,0BAA0B;;;;;;KAc3B;cAEC,sBAAsB;;UAOlB;;EAEf,MAAM;;EAEN,YAAY;;EAEZ;;EAEA;;;;;;;EAOA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA,YAAY;;EAEZ,aAAa,eAAe;;;;;EAK5B;;;UAIe;;EAEf;;;;;;EAMA;;EAEA,OAAO,eAAe;;EAEtB,mBAAmB,eAAe;;;;;EAKlC;;;;;;EAMA,YAAY,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiEb,eAAe,UAAU,oBAAoB;;;;;;iBAwC7C,qBACd,UAAU,mBACV,kBACA,cACC;;iBAQa,2BACd,UAAU,mBACV"}
|