@sebspark/otel 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -7
- package/dist/index.mjs +9 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -222,6 +222,10 @@ function isHistogramLike(val) {
|
|
|
222
222
|
|
|
223
223
|
// src/loggers/formatters/span.ts
|
|
224
224
|
var import_api = require("@opentelemetry/api");
|
|
225
|
+
var LABEL_WIDTH = 20;
|
|
226
|
+
var DESCRIPTION_MAX_WIDTH = 16;
|
|
227
|
+
var BAR_MIN_WIDTH = 1;
|
|
228
|
+
var BAR_MAX_WIDTH = 20;
|
|
225
229
|
function formatSpans(spans) {
|
|
226
230
|
const rootSpan = spans[0];
|
|
227
231
|
const rootStart = hrTimeToMillis(rootSpan.startTime);
|
|
@@ -229,7 +233,8 @@ function formatSpans(spans) {
|
|
|
229
233
|
const totalDuration = rootEnd - rootStart;
|
|
230
234
|
const service = formatService(rootSpan.resource);
|
|
231
235
|
const timestamp = formatTimestamp(rootSpan.startTime);
|
|
232
|
-
const
|
|
236
|
+
const spanId = colors.gray(`[${rootSpan.spanContext().spanId}]`);
|
|
237
|
+
const lines = [`${service} ${timestamp} ${spanId}`];
|
|
233
238
|
for (const span of spans) {
|
|
234
239
|
const offset = hrTimeToMillis(span.startTime) - rootStart;
|
|
235
240
|
const depth = computeDepth(span, spans);
|
|
@@ -250,16 +255,14 @@ function formatSpan(span, opts) {
|
|
|
250
255
|
const desc = formatDescription(span);
|
|
251
256
|
const status = formatStatus(span);
|
|
252
257
|
const duration = formatDuration(span, opts?.offsetMs);
|
|
253
|
-
|
|
258
|
+
const traceId = colors.gray(`[${span.spanContext().traceId}]`);
|
|
259
|
+
return `${label} ${barColor(bar)} ${desc} ${status} ${duration} ${traceId}`;
|
|
254
260
|
}
|
|
255
|
-
var LABEL_WIDTH = 25;
|
|
256
261
|
function formatLabel(span, depth) {
|
|
257
262
|
const indent = " ".repeat(depth);
|
|
258
263
|
const label = `${indent}\u2514\u2500 ${span.name}`;
|
|
259
264
|
return label.padEnd(LABEL_WIDTH);
|
|
260
265
|
}
|
|
261
|
-
var BAR_MIN_WIDTH = 1;
|
|
262
|
-
var BAR_MAX_WIDTH = 20;
|
|
263
266
|
function buildBar(span, offsetMs, totalDurationMs) {
|
|
264
267
|
const duration = calculateDuration(span);
|
|
265
268
|
if (typeof offsetMs !== "number" || typeof totalDurationMs !== "number" || totalDurationMs === 0) {
|
|
@@ -281,7 +284,6 @@ function buildBar(span, offsetMs, totalDurationMs) {
|
|
|
281
284
|
const bar = "\u2588".repeat(barChars);
|
|
282
285
|
return (empty + bar).padEnd(BAR_MAX_WIDTH + 2);
|
|
283
286
|
}
|
|
284
|
-
var DESCRIPTION_MAX_WIDTH = 20;
|
|
285
287
|
function formatDescription(span) {
|
|
286
288
|
const keyPriority = [
|
|
287
289
|
// HTTP
|
|
@@ -356,7 +358,7 @@ function formatStatus(span) {
|
|
|
356
358
|
function formatDuration(span, offsetMs) {
|
|
357
359
|
const duration = calculateDuration(span);
|
|
358
360
|
const format = (ms) => ms >= 1e3 ? `${(ms / 1e3).toFixed(2)} s` : `${ms} ms`;
|
|
359
|
-
return
|
|
361
|
+
return `(${format(offsetMs || 0)}\u2013${format(duration)})`.padEnd(16);
|
|
360
362
|
}
|
|
361
363
|
function truncate(input, maxLength) {
|
|
362
364
|
const str = String(input ?? "");
|
package/dist/index.mjs
CHANGED
|
@@ -193,6 +193,10 @@ function isHistogramLike(val) {
|
|
|
193
193
|
|
|
194
194
|
// src/loggers/formatters/span.ts
|
|
195
195
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
196
|
+
var LABEL_WIDTH = 20;
|
|
197
|
+
var DESCRIPTION_MAX_WIDTH = 16;
|
|
198
|
+
var BAR_MIN_WIDTH = 1;
|
|
199
|
+
var BAR_MAX_WIDTH = 20;
|
|
196
200
|
function formatSpans(spans) {
|
|
197
201
|
const rootSpan = spans[0];
|
|
198
202
|
const rootStart = hrTimeToMillis(rootSpan.startTime);
|
|
@@ -200,7 +204,8 @@ function formatSpans(spans) {
|
|
|
200
204
|
const totalDuration = rootEnd - rootStart;
|
|
201
205
|
const service = formatService(rootSpan.resource);
|
|
202
206
|
const timestamp = formatTimestamp(rootSpan.startTime);
|
|
203
|
-
const
|
|
207
|
+
const spanId = colors.gray(`[${rootSpan.spanContext().spanId}]`);
|
|
208
|
+
const lines = [`${service} ${timestamp} ${spanId}`];
|
|
204
209
|
for (const span of spans) {
|
|
205
210
|
const offset = hrTimeToMillis(span.startTime) - rootStart;
|
|
206
211
|
const depth = computeDepth(span, spans);
|
|
@@ -221,16 +226,14 @@ function formatSpan(span, opts) {
|
|
|
221
226
|
const desc = formatDescription(span);
|
|
222
227
|
const status = formatStatus(span);
|
|
223
228
|
const duration = formatDuration(span, opts?.offsetMs);
|
|
224
|
-
|
|
229
|
+
const traceId = colors.gray(`[${span.spanContext().traceId}]`);
|
|
230
|
+
return `${label} ${barColor(bar)} ${desc} ${status} ${duration} ${traceId}`;
|
|
225
231
|
}
|
|
226
|
-
var LABEL_WIDTH = 25;
|
|
227
232
|
function formatLabel(span, depth) {
|
|
228
233
|
const indent = " ".repeat(depth);
|
|
229
234
|
const label = `${indent}\u2514\u2500 ${span.name}`;
|
|
230
235
|
return label.padEnd(LABEL_WIDTH);
|
|
231
236
|
}
|
|
232
|
-
var BAR_MIN_WIDTH = 1;
|
|
233
|
-
var BAR_MAX_WIDTH = 20;
|
|
234
237
|
function buildBar(span, offsetMs, totalDurationMs) {
|
|
235
238
|
const duration = calculateDuration(span);
|
|
236
239
|
if (typeof offsetMs !== "number" || typeof totalDurationMs !== "number" || totalDurationMs === 0) {
|
|
@@ -252,7 +255,6 @@ function buildBar(span, offsetMs, totalDurationMs) {
|
|
|
252
255
|
const bar = "\u2588".repeat(barChars);
|
|
253
256
|
return (empty + bar).padEnd(BAR_MAX_WIDTH + 2);
|
|
254
257
|
}
|
|
255
|
-
var DESCRIPTION_MAX_WIDTH = 20;
|
|
256
258
|
function formatDescription(span) {
|
|
257
259
|
const keyPriority = [
|
|
258
260
|
// HTTP
|
|
@@ -327,7 +329,7 @@ function formatStatus(span) {
|
|
|
327
329
|
function formatDuration(span, offsetMs) {
|
|
328
330
|
const duration = calculateDuration(span);
|
|
329
331
|
const format = (ms) => ms >= 1e3 ? `${(ms / 1e3).toFixed(2)} s` : `${ms} ms`;
|
|
330
|
-
return
|
|
332
|
+
return `(${format(offsetMs || 0)}\u2013${format(duration)})`.padEnd(16);
|
|
331
333
|
}
|
|
332
334
|
function truncate(input, maxLength) {
|
|
333
335
|
const str = String(input ?? "");
|