autotel-terminal 37.0.0 → 38.0.1
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/dist/cli.cjs +35 -25
- package/dist/cli.js +35 -25
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +1 -1
- package/dist/{src-B5rijglW.js → src-Db5VfN-J.js} +34 -25
- package/dist/{src-BH1qN4WA.cjs → src-g5ijfOwQ.cjs} +34 -25
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-g5ijfOwQ.cjs');
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_http = require("node:http");
|
|
5
5
|
let node_path = require("node:path");
|
|
@@ -92,6 +92,17 @@ var CliTerminalSpanStream = class {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/values.ts
|
|
97
|
+
/** The value as an object, or undefined when it is anything else. */
|
|
98
|
+
function asRecord(value) {
|
|
99
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
100
|
+
}
|
|
101
|
+
/** The string the value carries, or undefined when it carries anything else. */
|
|
102
|
+
function asString(value) {
|
|
103
|
+
return typeof value === "string" ? value : void 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
95
106
|
//#endregion
|
|
96
107
|
//#region src/otlp-http-json.ts
|
|
97
108
|
const MAX_BODY_BYTES = 10 * 1024 * 1024;
|
|
@@ -108,9 +119,7 @@ function anyValueToPrimitive(value) {
|
|
|
108
119
|
}
|
|
109
120
|
function attrsToRecord(attributes) {
|
|
110
121
|
if (!attributes || attributes.length === 0) return {};
|
|
111
|
-
|
|
112
|
-
for (const attribute of attributes) out[attribute.key] = anyValueToPrimitive(attribute.value);
|
|
113
|
-
return out;
|
|
122
|
+
return Object.fromEntries(attributes.map((attribute) => [attribute.key, anyValueToPrimitive(attribute.value)]));
|
|
114
123
|
}
|
|
115
124
|
function normalizeHexId(id, expectedHexLength) {
|
|
116
125
|
if (!id) return "".padStart(expectedHexLength, "0");
|
|
@@ -129,13 +138,14 @@ function toMs(unixNano) {
|
|
|
129
138
|
return parsed / 1e6;
|
|
130
139
|
}
|
|
131
140
|
function mapStatus(code) {
|
|
132
|
-
const normalized =
|
|
141
|
+
const normalized = asString(code)?.toUpperCase() ?? code;
|
|
133
142
|
if (normalized === 1 || normalized === "STATUS_CODE_OK" || normalized === "OK") return "OK";
|
|
134
143
|
if (normalized === 2 || normalized === "STATUS_CODE_ERROR" || normalized === "ERROR") return "ERROR";
|
|
135
144
|
return "UNSET";
|
|
136
145
|
}
|
|
137
146
|
function mapKind(kind) {
|
|
138
|
-
|
|
147
|
+
const named = asString(kind);
|
|
148
|
+
if (named !== void 0) return named.toUpperCase();
|
|
139
149
|
switch (kind) {
|
|
140
150
|
case 1: return "INTERNAL";
|
|
141
151
|
case 2: return "SERVER";
|
|
@@ -146,20 +156,19 @@ function mapKind(kind) {
|
|
|
146
156
|
}
|
|
147
157
|
}
|
|
148
158
|
function* extractSpans(payload) {
|
|
149
|
-
if (!payload
|
|
150
|
-
const resourceSpans = payload
|
|
159
|
+
if (!asRecord(payload)) return;
|
|
160
|
+
const { resourceSpans } = payload;
|
|
151
161
|
if (!Array.isArray(resourceSpans)) return;
|
|
152
162
|
for (const resourceSpan of resourceSpans) {
|
|
153
|
-
if (!resourceSpan
|
|
154
|
-
const
|
|
155
|
-
const resourceAttrs = attrsToRecord(resource?.attributes);
|
|
163
|
+
if (!asRecord(resourceSpan)) continue;
|
|
164
|
+
const resourceAttrs = attrsToRecord(resourceSpan.resource?.attributes);
|
|
156
165
|
const scopeSpans = resourceSpan.scopeSpans;
|
|
157
166
|
if (!Array.isArray(scopeSpans)) continue;
|
|
158
167
|
for (const scopeSpan of scopeSpans) {
|
|
159
|
-
if (!scopeSpan
|
|
168
|
+
if (!asRecord(scopeSpan)) continue;
|
|
160
169
|
const spans = scopeSpan.spans;
|
|
161
170
|
if (!Array.isArray(spans)) continue;
|
|
162
|
-
for (const span of spans) if (span
|
|
171
|
+
for (const span of spans) if (asRecord(span)) yield {
|
|
163
172
|
span,
|
|
164
173
|
resourceAttrs
|
|
165
174
|
};
|
|
@@ -183,7 +192,7 @@ function otlpSpanToTerminalEvent(span, resourceAttrs = {}) {
|
|
|
183
192
|
spanId: normalizeHexId(l.spanId, 16),
|
|
184
193
|
attributes: attrsToRecord(l.attributes)
|
|
185
194
|
})) : void 0;
|
|
186
|
-
|
|
195
|
+
const collected = {
|
|
187
196
|
name: span.name || "unnamed",
|
|
188
197
|
spanId: normalizeHexId(span.spanId, 16),
|
|
189
198
|
traceId: normalizeHexId(span.traceId, 32),
|
|
@@ -193,10 +202,11 @@ function otlpSpanToTerminalEvent(span, resourceAttrs = {}) {
|
|
|
193
202
|
durationMs: Math.max(0, endTime - startTime),
|
|
194
203
|
status: mapStatus(span.status?.code),
|
|
195
204
|
kind: mapKind(span.kind),
|
|
196
|
-
attributes: mergedAttrs
|
|
197
|
-
...parsedEvents ? { events: parsedEvents } : {},
|
|
198
|
-
...parsedLinks ? { links: parsedLinks } : {}
|
|
205
|
+
attributes: mergedAttrs
|
|
199
206
|
};
|
|
207
|
+
if (parsedEvents) collected.events = parsedEvents;
|
|
208
|
+
if (parsedLinks) collected.links = parsedLinks;
|
|
209
|
+
return collected;
|
|
200
210
|
}
|
|
201
211
|
async function readJsonBody(req) {
|
|
202
212
|
const chunks = [];
|
|
@@ -244,18 +254,18 @@ function bodyToMessage(body) {
|
|
|
244
254
|
return value === void 0 ? "" : String(value);
|
|
245
255
|
}
|
|
246
256
|
function* extractLogRecords(payload) {
|
|
247
|
-
if (!payload
|
|
248
|
-
const resourceLogs = payload
|
|
257
|
+
if (!asRecord(payload)) return;
|
|
258
|
+
const { resourceLogs } = payload;
|
|
249
259
|
if (!Array.isArray(resourceLogs)) return;
|
|
250
260
|
for (const resourceLog of resourceLogs) {
|
|
251
|
-
if (!resourceLog
|
|
261
|
+
if (!asRecord(resourceLog)) continue;
|
|
252
262
|
const scopeLogs = resourceLog.scopeLogs;
|
|
253
263
|
if (!Array.isArray(scopeLogs)) continue;
|
|
254
264
|
for (const scopeLog of scopeLogs) {
|
|
255
|
-
if (!scopeLog
|
|
265
|
+
if (!asRecord(scopeLog)) continue;
|
|
256
266
|
const logRecords = scopeLog.logRecords;
|
|
257
267
|
if (!Array.isArray(logRecords)) continue;
|
|
258
|
-
for (const record of logRecords) if (record
|
|
268
|
+
for (const record of logRecords) if (asRecord(record)) yield record;
|
|
259
269
|
}
|
|
260
270
|
}
|
|
261
271
|
}
|
|
@@ -277,14 +287,14 @@ function parseOtlpLogEvents(payload) {
|
|
|
277
287
|
function countOtlpMetrics(payload) {
|
|
278
288
|
if (!payload || typeof payload !== "object") return 0;
|
|
279
289
|
let count = 0;
|
|
280
|
-
const resourceMetrics = payload
|
|
290
|
+
const { resourceMetrics } = payload;
|
|
281
291
|
if (!Array.isArray(resourceMetrics)) return 0;
|
|
282
292
|
for (const resourceMetric of resourceMetrics) {
|
|
283
|
-
if (!resourceMetric
|
|
293
|
+
if (!asRecord(resourceMetric)) continue;
|
|
284
294
|
const scopeMetrics = resourceMetric.scopeMetrics;
|
|
285
295
|
if (!Array.isArray(scopeMetrics)) continue;
|
|
286
296
|
for (const scopeMetric of scopeMetrics) {
|
|
287
|
-
if (!scopeMetric
|
|
297
|
+
if (!asRecord(scopeMetric)) continue;
|
|
288
298
|
const metrics = scopeMetric.metrics;
|
|
289
299
|
if (Array.isArray(metrics)) count += metrics.length;
|
|
290
300
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as getTerminalLogStream, i as renderTerminal } from "./src-
|
|
2
|
+
import { a as getTerminalLogStream, i as renderTerminal } from "./src-Db5VfN-J.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import path from "node:path";
|
|
@@ -91,6 +91,17 @@ var CliTerminalSpanStream = class {
|
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/values.ts
|
|
96
|
+
/** The value as an object, or undefined when it is anything else. */
|
|
97
|
+
function asRecord(value) {
|
|
98
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
99
|
+
}
|
|
100
|
+
/** The string the value carries, or undefined when it carries anything else. */
|
|
101
|
+
function asString(value) {
|
|
102
|
+
return typeof value === "string" ? value : void 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
//#endregion
|
|
95
106
|
//#region src/otlp-http-json.ts
|
|
96
107
|
const MAX_BODY_BYTES = 10 * 1024 * 1024;
|
|
@@ -107,9 +118,7 @@ function anyValueToPrimitive(value) {
|
|
|
107
118
|
}
|
|
108
119
|
function attrsToRecord(attributes) {
|
|
109
120
|
if (!attributes || attributes.length === 0) return {};
|
|
110
|
-
|
|
111
|
-
for (const attribute of attributes) out[attribute.key] = anyValueToPrimitive(attribute.value);
|
|
112
|
-
return out;
|
|
121
|
+
return Object.fromEntries(attributes.map((attribute) => [attribute.key, anyValueToPrimitive(attribute.value)]));
|
|
113
122
|
}
|
|
114
123
|
function normalizeHexId(id, expectedHexLength) {
|
|
115
124
|
if (!id) return "".padStart(expectedHexLength, "0");
|
|
@@ -128,13 +137,14 @@ function toMs(unixNano) {
|
|
|
128
137
|
return parsed / 1e6;
|
|
129
138
|
}
|
|
130
139
|
function mapStatus(code) {
|
|
131
|
-
const normalized =
|
|
140
|
+
const normalized = asString(code)?.toUpperCase() ?? code;
|
|
132
141
|
if (normalized === 1 || normalized === "STATUS_CODE_OK" || normalized === "OK") return "OK";
|
|
133
142
|
if (normalized === 2 || normalized === "STATUS_CODE_ERROR" || normalized === "ERROR") return "ERROR";
|
|
134
143
|
return "UNSET";
|
|
135
144
|
}
|
|
136
145
|
function mapKind(kind) {
|
|
137
|
-
|
|
146
|
+
const named = asString(kind);
|
|
147
|
+
if (named !== void 0) return named.toUpperCase();
|
|
138
148
|
switch (kind) {
|
|
139
149
|
case 1: return "INTERNAL";
|
|
140
150
|
case 2: return "SERVER";
|
|
@@ -145,20 +155,19 @@ function mapKind(kind) {
|
|
|
145
155
|
}
|
|
146
156
|
}
|
|
147
157
|
function* extractSpans(payload) {
|
|
148
|
-
if (!payload
|
|
149
|
-
const resourceSpans = payload
|
|
158
|
+
if (!asRecord(payload)) return;
|
|
159
|
+
const { resourceSpans } = payload;
|
|
150
160
|
if (!Array.isArray(resourceSpans)) return;
|
|
151
161
|
for (const resourceSpan of resourceSpans) {
|
|
152
|
-
if (!resourceSpan
|
|
153
|
-
const
|
|
154
|
-
const resourceAttrs = attrsToRecord(resource?.attributes);
|
|
162
|
+
if (!asRecord(resourceSpan)) continue;
|
|
163
|
+
const resourceAttrs = attrsToRecord(resourceSpan.resource?.attributes);
|
|
155
164
|
const scopeSpans = resourceSpan.scopeSpans;
|
|
156
165
|
if (!Array.isArray(scopeSpans)) continue;
|
|
157
166
|
for (const scopeSpan of scopeSpans) {
|
|
158
|
-
if (!scopeSpan
|
|
167
|
+
if (!asRecord(scopeSpan)) continue;
|
|
159
168
|
const spans = scopeSpan.spans;
|
|
160
169
|
if (!Array.isArray(spans)) continue;
|
|
161
|
-
for (const span of spans) if (span
|
|
170
|
+
for (const span of spans) if (asRecord(span)) yield {
|
|
162
171
|
span,
|
|
163
172
|
resourceAttrs
|
|
164
173
|
};
|
|
@@ -182,7 +191,7 @@ function otlpSpanToTerminalEvent(span, resourceAttrs = {}) {
|
|
|
182
191
|
spanId: normalizeHexId(l.spanId, 16),
|
|
183
192
|
attributes: attrsToRecord(l.attributes)
|
|
184
193
|
})) : void 0;
|
|
185
|
-
|
|
194
|
+
const collected = {
|
|
186
195
|
name: span.name || "unnamed",
|
|
187
196
|
spanId: normalizeHexId(span.spanId, 16),
|
|
188
197
|
traceId: normalizeHexId(span.traceId, 32),
|
|
@@ -192,10 +201,11 @@ function otlpSpanToTerminalEvent(span, resourceAttrs = {}) {
|
|
|
192
201
|
durationMs: Math.max(0, endTime - startTime),
|
|
193
202
|
status: mapStatus(span.status?.code),
|
|
194
203
|
kind: mapKind(span.kind),
|
|
195
|
-
attributes: mergedAttrs
|
|
196
|
-
...parsedEvents ? { events: parsedEvents } : {},
|
|
197
|
-
...parsedLinks ? { links: parsedLinks } : {}
|
|
204
|
+
attributes: mergedAttrs
|
|
198
205
|
};
|
|
206
|
+
if (parsedEvents) collected.events = parsedEvents;
|
|
207
|
+
if (parsedLinks) collected.links = parsedLinks;
|
|
208
|
+
return collected;
|
|
199
209
|
}
|
|
200
210
|
async function readJsonBody(req) {
|
|
201
211
|
const chunks = [];
|
|
@@ -243,18 +253,18 @@ function bodyToMessage(body) {
|
|
|
243
253
|
return value === void 0 ? "" : String(value);
|
|
244
254
|
}
|
|
245
255
|
function* extractLogRecords(payload) {
|
|
246
|
-
if (!payload
|
|
247
|
-
const resourceLogs = payload
|
|
256
|
+
if (!asRecord(payload)) return;
|
|
257
|
+
const { resourceLogs } = payload;
|
|
248
258
|
if (!Array.isArray(resourceLogs)) return;
|
|
249
259
|
for (const resourceLog of resourceLogs) {
|
|
250
|
-
if (!resourceLog
|
|
260
|
+
if (!asRecord(resourceLog)) continue;
|
|
251
261
|
const scopeLogs = resourceLog.scopeLogs;
|
|
252
262
|
if (!Array.isArray(scopeLogs)) continue;
|
|
253
263
|
for (const scopeLog of scopeLogs) {
|
|
254
|
-
if (!scopeLog
|
|
264
|
+
if (!asRecord(scopeLog)) continue;
|
|
255
265
|
const logRecords = scopeLog.logRecords;
|
|
256
266
|
if (!Array.isArray(logRecords)) continue;
|
|
257
|
-
for (const record of logRecords) if (record
|
|
267
|
+
for (const record of logRecords) if (asRecord(record)) yield record;
|
|
258
268
|
}
|
|
259
269
|
}
|
|
260
270
|
}
|
|
@@ -276,14 +286,14 @@ function parseOtlpLogEvents(payload) {
|
|
|
276
286
|
function countOtlpMetrics(payload) {
|
|
277
287
|
if (!payload || typeof payload !== "object") return 0;
|
|
278
288
|
let count = 0;
|
|
279
|
-
const resourceMetrics = payload
|
|
289
|
+
const { resourceMetrics } = payload;
|
|
280
290
|
if (!Array.isArray(resourceMetrics)) return 0;
|
|
281
291
|
for (const resourceMetric of resourceMetrics) {
|
|
282
|
-
if (!resourceMetric
|
|
292
|
+
if (!asRecord(resourceMetric)) continue;
|
|
283
293
|
const scopeMetrics = resourceMetric.scopeMetrics;
|
|
284
294
|
if (!Array.isArray(scopeMetrics)) continue;
|
|
285
295
|
for (const scopeMetric of scopeMetrics) {
|
|
286
|
-
if (!scopeMetric
|
|
296
|
+
if (!asRecord(scopeMetric)) continue;
|
|
287
297
|
const metrics = scopeMetric.metrics;
|
|
288
298
|
if (Array.isArray(metrics)) count += metrics.length;
|
|
289
299
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-g5ijfOwQ.cjs');
|
|
3
3
|
let autotel_exporters = require("autotel/exporters");
|
|
4
4
|
let autotel = require("autotel");
|
|
5
5
|
|
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,20 @@ import { Context } from "@opentelemetry/api";
|
|
|
3
3
|
import "@json-render/ink";
|
|
4
4
|
import { SpanKind, SpanStatusCode } from "autotel";
|
|
5
5
|
import { PrettyConsoleExporter, PrettyConsoleExporterOptions } from "autotel/exporters";
|
|
6
|
+
//#region src/attrs.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Reading attributes off a span the terminal received.
|
|
9
|
+
*
|
|
10
|
+
* A span arrives over OTLP, so its attribute values are whatever the sender
|
|
11
|
+
* put there. Every screen that reads one wants the same thing - the string it
|
|
12
|
+
* should display - and asking for it in one place keeps that decision out of
|
|
13
|
+
* the twelve call sites that used to assert the type themselves.
|
|
14
|
+
*/
|
|
15
|
+
/** What an attribute holds once OTLP's AnyValue wrapper is unwrapped. */
|
|
16
|
+
type AttributeValue = string | number | boolean | null | undefined | Array<string | number | boolean | null>;
|
|
17
|
+
/** A span's attribute bag, as the terminal stores it. */
|
|
18
|
+
type SpanAttributes = Record<string, AttributeValue>;
|
|
19
|
+
//#endregion
|
|
6
20
|
//#region src/streaming-processor.d.ts
|
|
7
21
|
/**
|
|
8
22
|
* Span processor that wraps another processor and emits spans to subscribers
|
|
@@ -53,7 +67,7 @@ interface SpanEvent {
|
|
|
53
67
|
/** Time in milliseconds since epoch */
|
|
54
68
|
timeMs: number;
|
|
55
69
|
/** Event attributes */
|
|
56
|
-
attributes?:
|
|
70
|
+
attributes?: SpanAttributes;
|
|
57
71
|
}
|
|
58
72
|
/** Span link (cross-trace reference) */
|
|
59
73
|
interface SpanLink {
|
|
@@ -62,7 +76,7 @@ interface SpanLink {
|
|
|
62
76
|
/** Linked span ID */
|
|
63
77
|
spanId: string;
|
|
64
78
|
/** Link attributes */
|
|
65
|
-
attributes?:
|
|
79
|
+
attributes?: SpanAttributes;
|
|
66
80
|
}
|
|
67
81
|
/**
|
|
68
82
|
* Span event format for terminal dashboard consumption
|
|
@@ -87,7 +101,7 @@ interface TerminalSpanEvent {
|
|
|
87
101
|
/** Span kind (INTERNAL, SERVER, CLIENT, etc.) */
|
|
88
102
|
kind?: string;
|
|
89
103
|
/** Span attributes */
|
|
90
|
-
attributes?:
|
|
104
|
+
attributes?: SpanAttributes;
|
|
91
105
|
/** Span events (exceptions, annotations) */
|
|
92
106
|
events?: SpanEvent[];
|
|
93
107
|
/** Span links (cross-trace references) */
|
|
@@ -156,7 +170,7 @@ interface TerminalLogEvent {
|
|
|
156
170
|
/** Optional span correlation */
|
|
157
171
|
spanId?: string;
|
|
158
172
|
/** Structured attributes / fields */
|
|
159
|
-
attributes?:
|
|
173
|
+
attributes?: SpanAttributes;
|
|
160
174
|
}
|
|
161
175
|
//#endregion
|
|
162
176
|
//#region src/log-stream.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,20 @@ import "@json-render/ink";
|
|
|
3
3
|
import { PrettyConsoleExporter, PrettyConsoleExporterOptions } from "autotel/exporters";
|
|
4
4
|
import { ReadableSpan, ReadableSpan as ReadableSpan$1, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
5
5
|
import { Context } from "@opentelemetry/api";
|
|
6
|
+
//#region src/attrs.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Reading attributes off a span the terminal received.
|
|
9
|
+
*
|
|
10
|
+
* A span arrives over OTLP, so its attribute values are whatever the sender
|
|
11
|
+
* put there. Every screen that reads one wants the same thing - the string it
|
|
12
|
+
* should display - and asking for it in one place keeps that decision out of
|
|
13
|
+
* the twelve call sites that used to assert the type themselves.
|
|
14
|
+
*/
|
|
15
|
+
/** What an attribute holds once OTLP's AnyValue wrapper is unwrapped. */
|
|
16
|
+
type AttributeValue = string | number | boolean | null | undefined | Array<string | number | boolean | null>;
|
|
17
|
+
/** A span's attribute bag, as the terminal stores it. */
|
|
18
|
+
type SpanAttributes = Record<string, AttributeValue>;
|
|
19
|
+
//#endregion
|
|
6
20
|
//#region src/streaming-processor.d.ts
|
|
7
21
|
/**
|
|
8
22
|
* Span processor that wraps another processor and emits spans to subscribers
|
|
@@ -53,7 +67,7 @@ interface SpanEvent {
|
|
|
53
67
|
/** Time in milliseconds since epoch */
|
|
54
68
|
timeMs: number;
|
|
55
69
|
/** Event attributes */
|
|
56
|
-
attributes?:
|
|
70
|
+
attributes?: SpanAttributes;
|
|
57
71
|
}
|
|
58
72
|
/** Span link (cross-trace reference) */
|
|
59
73
|
interface SpanLink {
|
|
@@ -62,7 +76,7 @@ interface SpanLink {
|
|
|
62
76
|
/** Linked span ID */
|
|
63
77
|
spanId: string;
|
|
64
78
|
/** Link attributes */
|
|
65
|
-
attributes?:
|
|
79
|
+
attributes?: SpanAttributes;
|
|
66
80
|
}
|
|
67
81
|
/**
|
|
68
82
|
* Span event format for terminal dashboard consumption
|
|
@@ -87,7 +101,7 @@ interface TerminalSpanEvent {
|
|
|
87
101
|
/** Span kind (INTERNAL, SERVER, CLIENT, etc.) */
|
|
88
102
|
kind?: string;
|
|
89
103
|
/** Span attributes */
|
|
90
|
-
attributes?:
|
|
104
|
+
attributes?: SpanAttributes;
|
|
91
105
|
/** Span events (exceptions, annotations) */
|
|
92
106
|
events?: SpanEvent[];
|
|
93
107
|
/** Span links (cross-trace references) */
|
|
@@ -156,7 +170,7 @@ interface TerminalLogEvent {
|
|
|
156
170
|
/** Optional span correlation */
|
|
157
171
|
spanId?: string;
|
|
158
172
|
/** Structured attributes / fields */
|
|
159
|
-
attributes?:
|
|
173
|
+
attributes?: SpanAttributes;
|
|
160
174
|
}
|
|
161
175
|
//#endregion
|
|
162
176
|
//#region src/log-stream.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as getTerminalLogStream, i as renderTerminal, n as SpanKind, o as createTerminalSpanStream, r as SpanStatusCode, s as StreamingSpanProcessor, t as PrettyConsoleExporter } from "./src-
|
|
1
|
+
import { a as getTerminalLogStream, i as renderTerminal, n as SpanKind, o as createTerminalSpanStream, r as SpanStatusCode, s as StreamingSpanProcessor, t as PrettyConsoleExporter } from "./src-Db5VfN-J.js";
|
|
2
2
|
|
|
3
3
|
export { PrettyConsoleExporter, SpanKind, SpanStatusCode, StreamingSpanProcessor, createTerminalSpanStream, getTerminalLogStream, renderTerminal };
|
|
@@ -10,6 +10,16 @@ import { Renderer } from "@json-render/ink";
|
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { PrettyConsoleExporter } from "autotel/exporters";
|
|
12
12
|
|
|
13
|
+
//#region src/attrs.ts
|
|
14
|
+
/** The string an attribute carries, or undefined when it carried something else. */
|
|
15
|
+
function stringAttr(attrs, ...keys) {
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
const value = attrs?.[key];
|
|
18
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
13
23
|
//#region src/streaming-processor.ts
|
|
14
24
|
/**
|
|
15
25
|
* Span processor that wraps another processor and emits spans to subscribers
|
|
@@ -91,13 +101,13 @@ function mapStatus(code) {
|
|
|
91
101
|
* Map SpanKind number to string
|
|
92
102
|
*/
|
|
93
103
|
function mapKind(kind) {
|
|
94
|
-
return
|
|
95
|
-
[SpanKind.INTERNAL
|
|
96
|
-
[SpanKind.SERVER
|
|
97
|
-
[SpanKind.CLIENT
|
|
98
|
-
[SpanKind.PRODUCER
|
|
99
|
-
[SpanKind.CONSUMER
|
|
100
|
-
|
|
104
|
+
return (/* @__PURE__ */ new Map([
|
|
105
|
+
[SpanKind.INTERNAL, "INTERNAL"],
|
|
106
|
+
[SpanKind.SERVER, "SERVER"],
|
|
107
|
+
[SpanKind.CLIENT, "CLIENT"],
|
|
108
|
+
[SpanKind.PRODUCER, "PRODUCER"],
|
|
109
|
+
[SpanKind.CONSUMER, "CONSUMER"]
|
|
110
|
+
])).get(kind) ?? "UNKNOWN";
|
|
101
111
|
}
|
|
102
112
|
/**
|
|
103
113
|
* Create a terminal span stream from a streaming processor
|
|
@@ -126,11 +136,10 @@ function createTerminalSpanStream(processor) {
|
|
|
126
136
|
const startTime = timeToMs(span.startTime);
|
|
127
137
|
const endTime = timeToMs(span.endTime);
|
|
128
138
|
const durationMs = endTime - startTime;
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
for (const [k, v] of Object.entries(spanAttrs)) mergedAttrs[k] = v;
|
|
139
|
+
const mergedAttrs = {
|
|
140
|
+
...span.resource?.attributes,
|
|
141
|
+
...span.attributes
|
|
142
|
+
};
|
|
134
143
|
const spanEvents = span.events?.length ? span.events.map((e) => ({
|
|
135
144
|
name: e.name,
|
|
136
145
|
timeMs: timeToMs(e.time),
|
|
@@ -152,8 +161,8 @@ function createTerminalSpanStream(processor) {
|
|
|
152
161
|
status: mapStatus(span.status.code),
|
|
153
162
|
kind: mapKind(span.kind),
|
|
154
163
|
attributes: mergedAttrs,
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
events: spanEvents,
|
|
165
|
+
links: spanLinks
|
|
157
166
|
});
|
|
158
167
|
});
|
|
159
168
|
} };
|
|
@@ -520,7 +529,7 @@ function getTerminalLogStream() {
|
|
|
520
529
|
function computeServiceStats(spans) {
|
|
521
530
|
const byService = /* @__PURE__ */ new Map();
|
|
522
531
|
for (const span of spans) {
|
|
523
|
-
const serviceName = (span.attributes ?? {}
|
|
532
|
+
const serviceName = stringAttr(span.attributes ?? {}, "service.name") ?? "unknown";
|
|
524
533
|
const entry = byService.get(serviceName) ?? {
|
|
525
534
|
durations: [],
|
|
526
535
|
total: 0,
|
|
@@ -551,7 +560,7 @@ function computeServiceStats(spans) {
|
|
|
551
560
|
function computeRouteStats(spans) {
|
|
552
561
|
const byRoute = /* @__PURE__ */ new Map();
|
|
553
562
|
for (const span of spans) {
|
|
554
|
-
const route = (span.attributes ?? {}
|
|
563
|
+
const route = stringAttr(span.attributes ?? {}, "http.route") ?? null;
|
|
555
564
|
if (!route) continue;
|
|
556
565
|
const entry = byRoute.get(route) ?? {
|
|
557
566
|
durations: [],
|
|
@@ -607,10 +616,10 @@ function findHotSpanNames(spans, topN) {
|
|
|
607
616
|
//#endregion
|
|
608
617
|
//#region src/lib/filters.ts
|
|
609
618
|
function getServiceName$1(span) {
|
|
610
|
-
return (span.attributes ?? {}
|
|
619
|
+
return stringAttr(span.attributes ?? {}, "service.name") ?? void 0;
|
|
611
620
|
}
|
|
612
621
|
function getRoute(span) {
|
|
613
|
-
return (span.attributes ?? {}
|
|
622
|
+
return stringAttr(span.attributes ?? {}, "http.route") ?? void 0;
|
|
614
623
|
}
|
|
615
624
|
function getStatusCode(span) {
|
|
616
625
|
const code = (span.attributes ?? {})["http.status_code"];
|
|
@@ -697,11 +706,11 @@ function buildErrorSummaries(traceSummaries) {
|
|
|
697
706
|
//#region src/lib/topology-model.ts
|
|
698
707
|
function getServiceName(span) {
|
|
699
708
|
const attrs = span.attributes ?? {};
|
|
700
|
-
return (attrs
|
|
709
|
+
return (stringAttr(attrs, "service.name") ?? stringAttr(attrs, "resource.service.name")) || "unknown";
|
|
701
710
|
}
|
|
702
711
|
function getPeerService(span) {
|
|
703
712
|
const attrs = span.attributes ?? {};
|
|
704
|
-
return attrs
|
|
713
|
+
return stringAttr(attrs, "peer.service") ?? stringAttr(attrs, "db.system") ?? stringAttr(attrs, "messaging.system") ?? stringAttr(attrs, "http.host") ?? null;
|
|
705
714
|
}
|
|
706
715
|
function buildServiceGraph(spans) {
|
|
707
716
|
const byService = /* @__PURE__ */ new Map();
|
|
@@ -994,13 +1003,13 @@ function createTelemetryTools(ctx, onRenderUI) {
|
|
|
994
1003
|
execute: async ({ service, limit }) => {
|
|
995
1004
|
const max = limit ?? 10;
|
|
996
1005
|
let filtered = ctx.spans;
|
|
997
|
-
if (service) filtered = filtered.filter((s) => s.attributes
|
|
1006
|
+
if (service) filtered = filtered.filter((s) => stringAttr(s.attributes, "service.name") === service);
|
|
998
1007
|
return filtered.toSorted((a, b) => b.durationMs - a.durationMs).slice(0, max).map((s) => ({
|
|
999
1008
|
name: s.name,
|
|
1000
1009
|
durationMs: Math.round(s.durationMs),
|
|
1001
1010
|
status: s.status,
|
|
1002
|
-
service: s.attributes
|
|
1003
|
-
route: s.attributes
|
|
1011
|
+
service: stringAttr(s.attributes, "service.name") ?? "unknown",
|
|
1012
|
+
route: stringAttr(s.attributes, "http.route"),
|
|
1004
1013
|
traceId: s.traceId.slice(0, 8)
|
|
1005
1014
|
}));
|
|
1006
1015
|
}
|
|
@@ -1075,7 +1084,7 @@ function createTelemetryTools(ctx, onRenderUI) {
|
|
|
1075
1084
|
durationMs: Math.round(s.durationMs),
|
|
1076
1085
|
status: s.status,
|
|
1077
1086
|
traceId: s.traceId.slice(0, 8),
|
|
1078
|
-
service: s.attributes
|
|
1087
|
+
service: stringAttr(s.attributes, "service.name") ?? "unknown"
|
|
1079
1088
|
}));
|
|
1080
1089
|
}
|
|
1081
1090
|
}),
|
|
@@ -1341,7 +1350,7 @@ function Dashboard({ title, showStats, maxSpans, colors, stream, logStream, aiCo
|
|
|
1341
1350
|
const selectedServiceName = serviceStats[selected]?.serviceName ?? null;
|
|
1342
1351
|
const spansForSelectedService = useMemo(() => {
|
|
1343
1352
|
if (!selectedServiceName) return spans;
|
|
1344
|
-
return spans.filter((s) => s.attributes
|
|
1353
|
+
return spans.filter((s) => stringAttr(s.attributes, "service.name") === selectedServiceName);
|
|
1345
1354
|
}, [spans, selectedServiceName]);
|
|
1346
1355
|
const selectedServiceRouteStats = useMemo(() => computeRouteStats(spansForSelectedService).slice(0, 8), [spansForSelectedService]);
|
|
1347
1356
|
const selectedServiceHotSpans = useMemo(() => findHotSpanNames(spansForSelectedService, 8), [spansForSelectedService]);
|
|
@@ -38,6 +38,16 @@ let _json_render_ink = require("@json-render/ink");
|
|
|
38
38
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
39
39
|
let autotel_exporters = require("autotel/exporters");
|
|
40
40
|
|
|
41
|
+
//#region src/attrs.ts
|
|
42
|
+
/** The string an attribute carries, or undefined when it carried something else. */
|
|
43
|
+
function stringAttr(attrs, ...keys) {
|
|
44
|
+
for (const key of keys) {
|
|
45
|
+
const value = attrs?.[key];
|
|
46
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
41
51
|
//#region src/streaming-processor.ts
|
|
42
52
|
/**
|
|
43
53
|
* Span processor that wraps another processor and emits spans to subscribers
|
|
@@ -119,13 +129,13 @@ function mapStatus(code) {
|
|
|
119
129
|
* Map SpanKind number to string
|
|
120
130
|
*/
|
|
121
131
|
function mapKind(kind) {
|
|
122
|
-
return
|
|
123
|
-
[autotel.SpanKind.INTERNAL
|
|
124
|
-
[autotel.SpanKind.SERVER
|
|
125
|
-
[autotel.SpanKind.CLIENT
|
|
126
|
-
[autotel.SpanKind.PRODUCER
|
|
127
|
-
[autotel.SpanKind.CONSUMER
|
|
128
|
-
|
|
132
|
+
return (/* @__PURE__ */ new Map([
|
|
133
|
+
[autotel.SpanKind.INTERNAL, "INTERNAL"],
|
|
134
|
+
[autotel.SpanKind.SERVER, "SERVER"],
|
|
135
|
+
[autotel.SpanKind.CLIENT, "CLIENT"],
|
|
136
|
+
[autotel.SpanKind.PRODUCER, "PRODUCER"],
|
|
137
|
+
[autotel.SpanKind.CONSUMER, "CONSUMER"]
|
|
138
|
+
])).get(kind) ?? "UNKNOWN";
|
|
129
139
|
}
|
|
130
140
|
/**
|
|
131
141
|
* Create a terminal span stream from a streaming processor
|
|
@@ -154,11 +164,10 @@ function createTerminalSpanStream(processor) {
|
|
|
154
164
|
const startTime = timeToMs(span.startTime);
|
|
155
165
|
const endTime = timeToMs(span.endTime);
|
|
156
166
|
const durationMs = endTime - startTime;
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
for (const [k, v] of Object.entries(spanAttrs)) mergedAttrs[k] = v;
|
|
167
|
+
const mergedAttrs = {
|
|
168
|
+
...span.resource?.attributes,
|
|
169
|
+
...span.attributes
|
|
170
|
+
};
|
|
162
171
|
const spanEvents = span.events?.length ? span.events.map((e) => ({
|
|
163
172
|
name: e.name,
|
|
164
173
|
timeMs: timeToMs(e.time),
|
|
@@ -180,8 +189,8 @@ function createTerminalSpanStream(processor) {
|
|
|
180
189
|
status: mapStatus(span.status.code),
|
|
181
190
|
kind: mapKind(span.kind),
|
|
182
191
|
attributes: mergedAttrs,
|
|
183
|
-
|
|
184
|
-
|
|
192
|
+
events: spanEvents,
|
|
193
|
+
links: spanLinks
|
|
185
194
|
});
|
|
186
195
|
});
|
|
187
196
|
} };
|
|
@@ -548,7 +557,7 @@ function getTerminalLogStream() {
|
|
|
548
557
|
function computeServiceStats(spans) {
|
|
549
558
|
const byService = /* @__PURE__ */ new Map();
|
|
550
559
|
for (const span of spans) {
|
|
551
|
-
const serviceName = (span.attributes ?? {}
|
|
560
|
+
const serviceName = stringAttr(span.attributes ?? {}, "service.name") ?? "unknown";
|
|
552
561
|
const entry = byService.get(serviceName) ?? {
|
|
553
562
|
durations: [],
|
|
554
563
|
total: 0,
|
|
@@ -579,7 +588,7 @@ function computeServiceStats(spans) {
|
|
|
579
588
|
function computeRouteStats(spans) {
|
|
580
589
|
const byRoute = /* @__PURE__ */ new Map();
|
|
581
590
|
for (const span of spans) {
|
|
582
|
-
const route = (span.attributes ?? {}
|
|
591
|
+
const route = stringAttr(span.attributes ?? {}, "http.route") ?? null;
|
|
583
592
|
if (!route) continue;
|
|
584
593
|
const entry = byRoute.get(route) ?? {
|
|
585
594
|
durations: [],
|
|
@@ -635,10 +644,10 @@ function findHotSpanNames(spans, topN) {
|
|
|
635
644
|
//#endregion
|
|
636
645
|
//#region src/lib/filters.ts
|
|
637
646
|
function getServiceName$1(span) {
|
|
638
|
-
return (span.attributes ?? {}
|
|
647
|
+
return stringAttr(span.attributes ?? {}, "service.name") ?? void 0;
|
|
639
648
|
}
|
|
640
649
|
function getRoute(span) {
|
|
641
|
-
return (span.attributes ?? {}
|
|
650
|
+
return stringAttr(span.attributes ?? {}, "http.route") ?? void 0;
|
|
642
651
|
}
|
|
643
652
|
function getStatusCode(span) {
|
|
644
653
|
const code = (span.attributes ?? {})["http.status_code"];
|
|
@@ -725,11 +734,11 @@ function buildErrorSummaries(traceSummaries) {
|
|
|
725
734
|
//#region src/lib/topology-model.ts
|
|
726
735
|
function getServiceName(span) {
|
|
727
736
|
const attrs = span.attributes ?? {};
|
|
728
|
-
return (attrs
|
|
737
|
+
return (stringAttr(attrs, "service.name") ?? stringAttr(attrs, "resource.service.name")) || "unknown";
|
|
729
738
|
}
|
|
730
739
|
function getPeerService(span) {
|
|
731
740
|
const attrs = span.attributes ?? {};
|
|
732
|
-
return attrs
|
|
741
|
+
return stringAttr(attrs, "peer.service") ?? stringAttr(attrs, "db.system") ?? stringAttr(attrs, "messaging.system") ?? stringAttr(attrs, "http.host") ?? null;
|
|
733
742
|
}
|
|
734
743
|
function buildServiceGraph(spans) {
|
|
735
744
|
const byService = /* @__PURE__ */ new Map();
|
|
@@ -1022,13 +1031,13 @@ function createTelemetryTools(ctx, onRenderUI) {
|
|
|
1022
1031
|
execute: async ({ service, limit }) => {
|
|
1023
1032
|
const max = limit ?? 10;
|
|
1024
1033
|
let filtered = ctx.spans;
|
|
1025
|
-
if (service) filtered = filtered.filter((s) => s.attributes
|
|
1034
|
+
if (service) filtered = filtered.filter((s) => stringAttr(s.attributes, "service.name") === service);
|
|
1026
1035
|
return filtered.toSorted((a, b) => b.durationMs - a.durationMs).slice(0, max).map((s) => ({
|
|
1027
1036
|
name: s.name,
|
|
1028
1037
|
durationMs: Math.round(s.durationMs),
|
|
1029
1038
|
status: s.status,
|
|
1030
|
-
service: s.attributes
|
|
1031
|
-
route: s.attributes
|
|
1039
|
+
service: stringAttr(s.attributes, "service.name") ?? "unknown",
|
|
1040
|
+
route: stringAttr(s.attributes, "http.route"),
|
|
1032
1041
|
traceId: s.traceId.slice(0, 8)
|
|
1033
1042
|
}));
|
|
1034
1043
|
}
|
|
@@ -1103,7 +1112,7 @@ function createTelemetryTools(ctx, onRenderUI) {
|
|
|
1103
1112
|
durationMs: Math.round(s.durationMs),
|
|
1104
1113
|
status: s.status,
|
|
1105
1114
|
traceId: s.traceId.slice(0, 8),
|
|
1106
|
-
service: s.attributes
|
|
1115
|
+
service: stringAttr(s.attributes, "service.name") ?? "unknown"
|
|
1107
1116
|
}));
|
|
1108
1117
|
}
|
|
1109
1118
|
}),
|
|
@@ -1369,7 +1378,7 @@ function Dashboard({ title, showStats, maxSpans, colors, stream, logStream, aiCo
|
|
|
1369
1378
|
const selectedServiceName = serviceStats[selected]?.serviceName ?? null;
|
|
1370
1379
|
const spansForSelectedService = (0, react.useMemo)(() => {
|
|
1371
1380
|
if (!selectedServiceName) return spans;
|
|
1372
|
-
return spans.filter((s) => s.attributes
|
|
1381
|
+
return spans.filter((s) => stringAttr(s.attributes, "service.name") === selectedServiceName);
|
|
1373
1382
|
}, [spans, selectedServiceName]);
|
|
1374
1383
|
const selectedServiceRouteStats = (0, react.useMemo)(() => computeRouteStats(spansForSelectedService).slice(0, 8), [spansForSelectedService]);
|
|
1375
1384
|
const selectedServiceHotSpans = (0, react.useMemo)(() => findHotSpanNames(spansForSelectedService, 8), [spansForSelectedService]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-terminal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "38.0.1",
|
|
4
4
|
"description": "Terminal dashboard for autotel traces using react-ink",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@opentelemetry/api": "^1.9.1",
|
|
55
55
|
"@opentelemetry/sdk-trace-base": "^2.10.0",
|
|
56
|
-
"autotel": "
|
|
56
|
+
"autotel": "7.0.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"typescript": "^6.0.3",
|
|
71
71
|
"typescript-eslint": "^8.65.0",
|
|
72
72
|
"vitest": "^4.1.10",
|
|
73
|
-
"autotel": "
|
|
73
|
+
"autotel": "7.0.1"
|
|
74
74
|
},
|
|
75
75
|
"repository": {
|
|
76
76
|
"type": "git",
|