@libo11y/test 0.4.0 → 0.7.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 +7 -3
- package/dist/assertions.d.ts +1 -1
- package/dist/assertions.js +22 -3
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@ including Playwright's Node test runner. It does not run in browsers.
|
|
|
10
10
|
npm install --save-dev @libo11y/test
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
`@opentelemetry/api` is a peer dependency. npm 7 and later and Bun install
|
|
14
|
+
it automatically. If your application already depends on it, use a version
|
|
15
|
+
that satisfies `>=1.10.0 <1.11.0`.
|
|
16
|
+
|
|
13
17
|
## Quick start
|
|
14
18
|
|
|
15
19
|
```ts
|
|
@@ -24,7 +28,7 @@ rec.logs(); // log records as the OTLP leg emitted them, already classified
|
|
|
24
28
|
await rec.exemplars("http.server.request.duration");
|
|
25
29
|
|
|
26
30
|
await rec.assertConforms(); // tier-0 identity, no secrets, event contracts
|
|
27
|
-
rec.assertCorrelated(); // every log emitted inside a span carries its trace
|
|
31
|
+
rec.assertCorrelated(); // every log emitted inside a span carries its trace and span IDs
|
|
28
32
|
await rec.assertTriangle({ metric: "http.server.request.duration" });
|
|
29
33
|
await rec.shutdown();
|
|
30
34
|
```
|
|
@@ -61,7 +65,7 @@ defaults:
|
|
|
61
65
|
| `metricNames()` | the names of every instrument with recorded data |
|
|
62
66
|
| `exemplars(instrument)` | the exemplars on the named instrument, across its data points |
|
|
63
67
|
| `assertConforms()` | throws unless the tier-0 resource keys are present, no secret-classified attribute was counted or is visible in a log or span, and every registered event carries the attributes its contract requires. Call it before `shutdown` |
|
|
64
|
-
| `assertCorrelated()` | throws unless every log recorded inside a span carries that span's trace
|
|
68
|
+
| `assertCorrelated()` | throws unless every log recorded inside a span carries that span's trace and span IDs |
|
|
65
69
|
| `assertTriangle({ metric })` | throws unless a span, a log with its trace and span IDs, and an exemplar on `metric` with the same trace ID were all recorded |
|
|
66
70
|
| `shutdown()` | shuts the telemetry down. What was recorded stays readable |
|
|
67
71
|
|
|
@@ -116,6 +120,6 @@ exported for tests that decode bodies themselves.
|
|
|
116
120
|
|
|
117
121
|
## Parity
|
|
118
122
|
|
|
119
|
-
[docs/PARITY.md](https://github.com/
|
|
123
|
+
[docs/PARITY.md](https://github.com/libo11y/libo11y/blob/main/docs/PARITY.md)
|
|
120
124
|
lists where the TypeScript packages match Go and where they differ, with
|
|
121
125
|
the reasons.
|
package/dist/assertions.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface ConformanceInput {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function conformanceProblems(input: ConformanceInput): string[];
|
|
38
38
|
/**
|
|
39
|
-
* Go AssertCorrelated: a record emitted while a span was active must carry
|
|
39
|
+
* Go AssertCorrelated: a record emitted while a span was active must carry its trace and span IDs.
|
|
40
40
|
* "active" is the caller's active span at emission, not the context the emitter passed.
|
|
41
41
|
*/
|
|
42
42
|
export declare function correlationProblems(logs: readonly CapturedLog[]): string[];
|
package/dist/assertions.js
CHANGED
|
@@ -118,11 +118,25 @@ export function conformanceProblems(input) {
|
|
|
118
118
|
problems.push(`o11ytest: span ${goQuote(span.name)} carries secret-classified attribute ${goQuote(key)} in the clear`);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
for (const ev of span.events ?? []) {
|
|
122
|
+
for (const key of Object.keys(ev.attributes ?? {})) {
|
|
123
|
+
if (isSecret(key)) {
|
|
124
|
+
problems.push(`o11ytest: span ${goQuote(span.name)} event ${goQuote(ev.name)} carries secret-classified attribute ${goQuote(key)} in the clear`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const [i, link] of (span.links ?? []).entries()) {
|
|
129
|
+
for (const key of Object.keys(link.attributes ?? {})) {
|
|
130
|
+
if (isSecret(key)) {
|
|
131
|
+
problems.push(`o11ytest: span ${goQuote(span.name)} link ${i} carries secret-classified attribute ${goQuote(key)} in the clear`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
121
135
|
}
|
|
122
136
|
return problems;
|
|
123
137
|
}
|
|
124
138
|
/**
|
|
125
|
-
* Go AssertCorrelated: a record emitted while a span was active must carry
|
|
139
|
+
* Go AssertCorrelated: a record emitted while a span was active must carry its trace and span IDs.
|
|
126
140
|
* "active" is the caller's active span at emission, not the context the emitter passed.
|
|
127
141
|
*/
|
|
128
142
|
export function correlationProblems(logs) {
|
|
@@ -132,12 +146,17 @@ export function correlationProblems(logs) {
|
|
|
132
146
|
continue;
|
|
133
147
|
if (log.traceId === undefined) {
|
|
134
148
|
problems.push(`o11ytest: correlated record ${goQuote(log.body)} has no trace_id attribute`);
|
|
135
|
-
continue;
|
|
136
149
|
}
|
|
137
|
-
if (log.traceId !== active.traceId) {
|
|
150
|
+
else if (log.traceId !== active.traceId) {
|
|
138
151
|
problems.push(`o11ytest: record ${goQuote(log.body)} trace_id ${goQuote(log.traceId)} does not match its span ` +
|
|
139
152
|
goQuote(active.traceId));
|
|
140
153
|
}
|
|
154
|
+
if (log.spanId === undefined) {
|
|
155
|
+
problems.push(`o11ytest: correlated record ${goQuote(log.body)} has no span_id attribute`);
|
|
156
|
+
}
|
|
157
|
+
else if (log.spanId !== active.spanId) {
|
|
158
|
+
problems.push(`o11ytest: record ${goQuote(log.body)} span_id ${goQuote(log.spanId)} does not match its span ${goQuote(active.spanId)}`);
|
|
159
|
+
}
|
|
141
160
|
}
|
|
142
161
|
return problems;
|
|
143
162
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libo11y/test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The libo11y test harness for TypeScript: a hermetic recorder with conformance and correlation assertions, and an in-process OTLP/HTTP sink. Runs on Bun and Node.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -13,19 +13,22 @@
|
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/
|
|
16
|
+
"url": "git+https://github.com/libo11y/libo11y.git",
|
|
17
17
|
"directory": "ts/packages/test"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@libo11y/core": "0.
|
|
21
|
-
"@libo11y/spec": "0.
|
|
22
|
-
"@opentelemetry/api": "1.10.0",
|
|
20
|
+
"@libo11y/core": "0.7.0",
|
|
21
|
+
"@libo11y/spec": "0.7.0",
|
|
23
22
|
"@opentelemetry/context-async-hooks": "3.1.1",
|
|
24
23
|
"@opentelemetry/sdk-logs": "3.1.1",
|
|
25
24
|
"@opentelemetry/sdk-metrics": "3.1.1",
|
|
26
25
|
"@opentelemetry/sdk-trace": "3.1.1"
|
|
27
26
|
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@opentelemetry/api": ">=1.10.0 <1.11.0"
|
|
29
|
+
},
|
|
28
30
|
"devDependencies": {
|
|
31
|
+
"@opentelemetry/api": "1.10.0",
|
|
29
32
|
"@opentelemetry/otlp-transformer": "0.301.1"
|
|
30
33
|
},
|
|
31
34
|
"files": [
|