@pristine-ts/telemetry 2.0.1 → 2.0.3
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/lib/cjs/decorators/decorators.js +18 -0
- package/dist/lib/cjs/decorators/decorators.js.map +1 -0
- package/dist/lib/cjs/decorators/traced.decorator.js +60 -0
- package/dist/lib/cjs/decorators/traced.decorator.js.map +1 -0
- package/dist/lib/cjs/enums/console-tracer-output-mode.enum.js +16 -0
- package/dist/lib/cjs/enums/console-tracer-output-mode.enum.js.map +1 -0
- package/dist/lib/cjs/enums/enums.js +1 -0
- package/dist/lib/cjs/enums/enums.js.map +1 -1
- package/dist/lib/cjs/managers/tracing.manager.js +56 -41
- package/dist/lib/cjs/managers/tracing.manager.js.map +1 -1
- package/dist/lib/cjs/telemetry.configuration-keys.js +7 -0
- package/dist/lib/cjs/telemetry.configuration-keys.js.map +1 -1
- package/dist/lib/cjs/telemetry.module.js +90 -0
- package/dist/lib/cjs/telemetry.module.js.map +1 -1
- package/dist/lib/cjs/tracers/console.tracer.js +106 -0
- package/dist/lib/cjs/tracers/console.tracer.js.map +1 -0
- package/dist/lib/cjs/tracers/file.tracer.js +161 -0
- package/dist/lib/cjs/tracers/file.tracer.js.map +1 -0
- package/dist/lib/cjs/tracers/tracers.js +2 -1
- package/dist/lib/cjs/tracers/tracers.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/cjs/utils/span-runner.js +112 -0
- package/dist/lib/cjs/utils/span-runner.js.map +1 -0
- package/dist/lib/cjs/utils/trace-renderer.js +128 -0
- package/dist/lib/cjs/utils/trace-renderer.js.map +1 -0
- package/dist/lib/cjs/utils/utils.js +19 -0
- package/dist/lib/cjs/utils/utils.js.map +1 -0
- package/dist/lib/esm/decorators/decorators.js +2 -0
- package/dist/lib/esm/decorators/decorators.js.map +1 -0
- package/dist/lib/esm/decorators/traced.decorator.js +57 -0
- package/dist/lib/esm/decorators/traced.decorator.js.map +1 -0
- package/dist/lib/esm/enums/console-tracer-output-mode.enum.js +13 -0
- package/dist/lib/esm/enums/console-tracer-output-mode.enum.js.map +1 -0
- package/dist/lib/esm/enums/enums.js +1 -0
- package/dist/lib/esm/enums/enums.js.map +1 -1
- package/dist/lib/esm/managers/tracing.manager.js +58 -43
- package/dist/lib/esm/managers/tracing.manager.js.map +1 -1
- package/dist/lib/esm/telemetry.configuration-keys.js +7 -0
- package/dist/lib/esm/telemetry.configuration-keys.js.map +1 -1
- package/dist/lib/esm/telemetry.module.js +91 -1
- package/dist/lib/esm/telemetry.module.js.map +1 -1
- package/dist/lib/esm/tracers/console.tracer.js +103 -0
- package/dist/lib/esm/tracers/console.tracer.js.map +1 -0
- package/dist/lib/esm/tracers/file.tracer.js +125 -0
- package/dist/lib/esm/tracers/file.tracer.js.map +1 -0
- package/dist/lib/esm/tracers/tracers.js +2 -1
- package/dist/lib/esm/tracers/tracers.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/lib/esm/utils/span-runner.js +108 -0
- package/dist/lib/esm/utils/span-runner.js.map +1 -0
- package/dist/lib/esm/utils/trace-renderer.js +124 -0
- package/dist/lib/esm/utils/trace-renderer.js.map +1 -0
- package/dist/lib/esm/utils/utils.js +3 -0
- package/dist/lib/esm/utils/utils.js.map +1 -0
- package/dist/types/decorators/decorators.d.ts +1 -0
- package/dist/types/decorators/traced.decorator.d.ts +35 -0
- package/dist/types/enums/console-tracer-output-mode.enum.d.ts +11 -0
- package/dist/types/enums/enums.d.ts +1 -0
- package/dist/types/managers/tracing.manager.d.ts +11 -1
- package/dist/types/telemetry.configuration-keys.d.ts +15 -0
- package/dist/types/telemetry.module.d.ts +2 -0
- package/dist/types/tracers/console.tracer.d.ts +28 -0
- package/dist/types/tracers/file.tracer.d.ts +34 -0
- package/dist/types/tracers/tracers.d.ts +2 -1
- package/dist/types/utils/span-runner.d.ts +55 -0
- package/dist/types/utils/trace-renderer.d.ts +41 -0
- package/dist/types/utils/utils.d.ts +2 -0
- package/package.json +4 -4
- package/dist/lib/cjs/tracers/basic.tracer.js +0 -50
- package/dist/lib/cjs/tracers/basic.tracer.js.map +0 -1
- package/dist/lib/esm/tracers/basic.tracer.js +0 -47
- package/dist/lib/esm/tracers/basic.tracer.js.map +0 -1
- package/dist/types/tracers/basic.tracer.d.ts +0 -12
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./traced.decorator"), exports);
|
|
18
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traced = traced;
|
|
4
|
+
const span_runner_1 = require("../utils/span-runner");
|
|
5
|
+
/**
|
|
6
|
+
* Method decorator that wraps the decorated method in a span. The span is automatically
|
|
7
|
+
* ended when the method returns or throws, and the `TracingManager` is auto-resolved
|
|
8
|
+
* from the active `EventContext` — no need to inject it manually.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* class PaymentService {
|
|
12
|
+
* @traced() // span name = "PaymentService.charge"
|
|
13
|
+
* async charge(amount: number) { ... }
|
|
14
|
+
*
|
|
15
|
+
* @traced("payment.refund.action") // explicit name
|
|
16
|
+
* async refund(chargeId: string) { ... }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* **Behavior outside an event context.** When the decorated method runs without an
|
|
21
|
+
* active `EventContext` (e.g. a unit test calling the method directly, or background
|
|
22
|
+
* work that escaped the event lifecycle), the decorator is a no-op — the original
|
|
23
|
+
* method runs unchanged. Tracing must never throw or alter semantics.
|
|
24
|
+
*
|
|
25
|
+
* **Sync methods become async.** The decorator awaits the wrapped method internally,
|
|
26
|
+
* so any decorated method returns a `Promise`. Decorating a sync method changes its
|
|
27
|
+
* signature visible to callers — apply `@traced` to methods you'd already be awaiting
|
|
28
|
+
* (DB calls, HTTP, expensive computations), not to tight sync helpers.
|
|
29
|
+
*
|
|
30
|
+
* **Type-level caveat.** TypeScript's parameter and method decorator types don't carry
|
|
31
|
+
* enough information for the compiler to verify that the wrapped method's return type
|
|
32
|
+
* is compatible with `Promise<T>`. The wrapper is type-safe at runtime; the call site's
|
|
33
|
+
* static types are unchanged. Pair with explicit `: Promise<T>` annotations on the
|
|
34
|
+
* method when you want the static type to match what's actually returned.
|
|
35
|
+
*
|
|
36
|
+
* @param spanName Optional explicit name for the span. Defaults to
|
|
37
|
+
* `${ClassName}.${methodName}`.
|
|
38
|
+
*/
|
|
39
|
+
function traced(spanName) {
|
|
40
|
+
return (target, propertyKey, descriptor) => {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
const original = descriptor.value;
|
|
43
|
+
if (typeof original !== "function") {
|
|
44
|
+
// Decorator was applied to something other than a method (a getter, a property
|
|
45
|
+
// with no initial value, etc.). Leave it alone — silently no-op rather than
|
|
46
|
+
// throw at decoration time.
|
|
47
|
+
return descriptor;
|
|
48
|
+
}
|
|
49
|
+
// Resolve a stable default name at decoration time. `target.constructor.name` is
|
|
50
|
+
// the class name for instance methods; for static methods, `target.name` is the
|
|
51
|
+
// class. We cover both via the fallback chain.
|
|
52
|
+
const className = (_c = (_b = (_a = target === null || target === void 0 ? void 0 : target.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : target === null || target === void 0 ? void 0 : target.name) !== null && _c !== void 0 ? _c : "anonymous";
|
|
53
|
+
const resolvedName = spanName !== null && spanName !== void 0 ? spanName : `${className}.${String(propertyKey)}`;
|
|
54
|
+
descriptor.value = function (...args) {
|
|
55
|
+
return span_runner_1.spanRunner.runWithSpan(resolvedName, () => original.apply(this, args));
|
|
56
|
+
};
|
|
57
|
+
return descriptor;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=traced.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/traced.decorator.ts"],"names":[],"mappings":";;AAoCA,wBAsBC;AA1DD,sDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,SAAgB,MAAM,CAAC,QAAiB;IACtC,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,UAA8B,EAAE,EAAE;;QACnF,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC;QAClC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,+EAA+E;YAC/E,4EAA4E;YAC5E,4BAA4B;YAC5B,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,iFAAiF;QACjF,gFAAgF;QAChF,+CAA+C;QAC/C,MAAM,SAAS,GAAW,MAAA,MAAA,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,0CAAE,IAAI,mCAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,WAAW,CAAC;QACnF,MAAM,YAAY,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,GAAG,SAAS,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QAEvE,UAAU,CAAC,KAAK,GAAG,UAAyB,GAAG,IAAW;YACxD,OAAO,wBAAU,CAAC,WAAW,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAChF,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleTracerOutputModeEnum = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* How `ConsoleTracer` renders a completed trace.
|
|
6
|
+
*/
|
|
7
|
+
var ConsoleTracerOutputModeEnum;
|
|
8
|
+
(function (ConsoleTracerOutputModeEnum) {
|
|
9
|
+
/** Indented ASCII tree mirroring the span hierarchy. Best for human readers. */
|
|
10
|
+
ConsoleTracerOutputModeEnum["Tree"] = "tree";
|
|
11
|
+
/** Pretty-printed JSON dump of the trace + every span. Best for piping into a tool. */
|
|
12
|
+
ConsoleTracerOutputModeEnum["Json"] = "json";
|
|
13
|
+
/** One span per line, no indentation, sorted by start time. Best for grep. */
|
|
14
|
+
ConsoleTracerOutputModeEnum["Flat"] = "flat";
|
|
15
|
+
})(ConsoleTracerOutputModeEnum || (exports.ConsoleTracerOutputModeEnum = ConsoleTracerOutputModeEnum = {}));
|
|
16
|
+
//# sourceMappingURL=console-tracer-output-mode.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-tracer-output-mode.enum.js","sourceRoot":"","sources":["../../../../src/enums/console-tracer-output-mode.enum.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,2BAOX;AAPD,WAAY,2BAA2B;IACrC,gFAAgF;IAChF,4CAAa,CAAA;IACb,uFAAuF;IACvF,4CAAa,CAAA;IACb,8EAA8E;IAC9E,4CAAa,CAAA;AACf,CAAC,EAPW,2BAA2B,2CAA3B,2BAA2B,QAOtC"}
|
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./console-tracer-output-mode.enum"), exports);
|
|
17
18
|
__exportStar(require("./span-keyname.enum"), exports);
|
|
18
19
|
//# sourceMappingURL=enums.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../src/enums/enums.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../src/enums/enums.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD;AAClD,sDAAoC"}
|
|
@@ -24,6 +24,14 @@ const telemetry_module_keyname_1 = require("../telemetry.module.keyname");
|
|
|
24
24
|
* The Tracing Manager provides methods to help with tracing.
|
|
25
25
|
* It is tagged and can be injected using TracingManagerInterface which facilitates mocking.
|
|
26
26
|
* It is module scoped to the TelemetryModuleKeyname.
|
|
27
|
+
*
|
|
28
|
+
* **Lifecycle: container-scoped, not singleton.** Each per-event DI child container gets
|
|
29
|
+
* its own `TracingManager` instance with its own `trace` and `spans` state. Earlier
|
|
30
|
+
* versions used `@singleton()` — a single instance shared across every event — which
|
|
31
|
+
* was a latent bug: parallel events would clobber each other's `this.trace`. Resolving
|
|
32
|
+
* `TracingManager` from the root container still returns the root instance (used for
|
|
33
|
+
* kernel-initialization spans before any event has started); resolving from a child
|
|
34
|
+
* container returns the per-event instance, which is what application code wants.
|
|
27
35
|
*/
|
|
28
36
|
let TracingManager = class TracingManager {
|
|
29
37
|
/**
|
|
@@ -57,8 +65,16 @@ let TracingManager = class TracingManager {
|
|
|
57
65
|
startTracing(spanRootKeyname = span_keyname_enum_1.SpanKeynameEnum.RootExecution, traceId, context) {
|
|
58
66
|
this.trace = new trace_model_1.Trace(traceId, context);
|
|
59
67
|
const span = new span_model_1.Span(spanRootKeyname, undefined, context);
|
|
60
|
-
//
|
|
68
|
+
// Mirror the trace id into both the legacy `TracingContext` (back-compat for any
|
|
69
|
+
// existing consumer that still injects it) and the new ALS-propagated `EventContext`
|
|
70
|
+
// (the path forward; what `LogHandler` and other ALS-aware consumers will read).
|
|
71
|
+
// Both writes are cheap; the dual write is just a transition aid until TracingContext
|
|
72
|
+
// is fully removed in a later major.
|
|
61
73
|
this.tracingContext.traceId = this.trace.id;
|
|
74
|
+
const eventContext = common_1.EventContextManager.current();
|
|
75
|
+
if (eventContext !== undefined) {
|
|
76
|
+
eventContext.traceId = this.trace.id;
|
|
77
|
+
}
|
|
62
78
|
// If the tracing is not active, simply return the created span but don't send to the tracers.
|
|
63
79
|
if (this.isActive === false) {
|
|
64
80
|
return span;
|
|
@@ -93,43 +109,55 @@ let TracingManager = class TracingManager {
|
|
|
93
109
|
*/
|
|
94
110
|
startSpan(keyname, parentKeyname, parentId, context) {
|
|
95
111
|
var _a;
|
|
96
|
-
//
|
|
112
|
+
// Make sure a trace exists. `startTracing` is the canonical entry point, but a direct
|
|
113
|
+
// `startSpan` call (e.g. from project code) should auto-start a trace rather than fail.
|
|
97
114
|
if (this.trace === undefined) {
|
|
98
115
|
this.startTracing(span_keyname_enum_1.SpanKeynameEnum.RootExecution, undefined, context);
|
|
99
116
|
}
|
|
100
|
-
//
|
|
101
|
-
|
|
117
|
+
// Construct the span. NOTE the third constructor argument: `Span(keyname, id?, context?)`.
|
|
118
|
+
// A previous version of this code passed `context` in the `id` slot, which corrupted span
|
|
119
|
+
// identities and broke parent-by-id lookup at line 133 silently. Always pass `undefined`
|
|
120
|
+
// for the id so a fresh UUID is generated, and put context in the third slot.
|
|
121
|
+
const span = new span_model_1.Span(keyname, undefined, context);
|
|
122
|
+
// Defensive: tracing must never throw. If the trace is somehow still undefined here
|
|
123
|
+
// (an exception inside `startTracing` that we swallowed and logged), return the bare
|
|
124
|
+
// span so the caller can still call `.end()` on it without exploding.
|
|
102
125
|
if (this.trace === undefined) {
|
|
103
|
-
this.loghandler.error("
|
|
104
|
-
return span;
|
|
126
|
+
this.loghandler.error("Trace is undefined after startTracing; returning unattached span.", { span });
|
|
127
|
+
return span;
|
|
105
128
|
}
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
107
129
|
span.trace = this.trace;
|
|
108
|
-
//
|
|
109
|
-
//
|
|
130
|
+
// Resolve the parent span. The default parent is the trace's rootSpan, but we may not
|
|
131
|
+
// have one if the trace was started via a path that didn't set it (programming error
|
|
132
|
+
// upstream, but we tolerate it). When no rootSpan exists, attach the new span as a
|
|
133
|
+
// top-level orphan and warn-log once instead of crashing.
|
|
110
134
|
let parentSpan = this.trace.rootSpan;
|
|
111
|
-
// Check to find the parentKeyname in our internal map of spans. If n ot, the rootSpan will be the parent since every span
|
|
112
|
-
// needs at least one parent.
|
|
113
135
|
if (parentKeyname) {
|
|
114
136
|
const parentSpans = this.spans[parentKeyname];
|
|
115
|
-
// If multiple spans have the same keyname we need an id to find the parent
|
|
116
137
|
if (parentSpans) {
|
|
117
138
|
if (parentSpans.length > 1) {
|
|
118
|
-
if (
|
|
119
|
-
//this.loghandler.error("Error finding the parent span, there are multiple spans with that keyname and no id is provided.", {parentKeyname});
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
139
|
+
if (parentId) {
|
|
122
140
|
parentSpan = (_a = parentSpans.find(span => span.id === parentId)) !== null && _a !== void 0 ? _a : parentSpan;
|
|
123
141
|
}
|
|
142
|
+
// If multiple parents exist with the same keyname and no id was provided, fall back
|
|
143
|
+
// to the existing default (rootSpan or whatever parentSpan was) — silent rather
|
|
144
|
+
// than noisy because this is recoverable.
|
|
124
145
|
}
|
|
125
146
|
else if (parentSpans.length === 1) {
|
|
126
|
-
// If only one span has the keyname we can use it
|
|
127
147
|
parentSpan = parentSpans[0];
|
|
128
148
|
}
|
|
129
149
|
}
|
|
130
150
|
}
|
|
131
|
-
|
|
132
|
-
|
|
151
|
+
if (parentSpan === undefined) {
|
|
152
|
+
this.loghandler.warning("startSpan: no parent span available (rootSpan is undefined). Attaching as orphan.", {
|
|
153
|
+
keyname,
|
|
154
|
+
parentKeyname,
|
|
155
|
+
traceId: this.trace.id,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
parentSpan.addChild(span);
|
|
160
|
+
}
|
|
133
161
|
this.addSpan(span);
|
|
134
162
|
return span;
|
|
135
163
|
}
|
|
@@ -138,18 +166,14 @@ let TracingManager = class TracingManager {
|
|
|
138
166
|
* @param span The span to add.
|
|
139
167
|
*/
|
|
140
168
|
addSpan(span) {
|
|
141
|
-
//
|
|
169
|
+
// Tracing must never throw. If there's no active trace, log and return the span
|
|
170
|
+
// unchanged — caller can still call `.end()` on it because Span.end uses optional
|
|
171
|
+
// chaining on tracingManager.
|
|
142
172
|
if (this.trace === undefined) {
|
|
143
173
|
this.loghandler.error("You cannot call 'addSpan' without having an existing Trace.", { span });
|
|
144
174
|
return span;
|
|
145
175
|
}
|
|
146
|
-
// Assign the tracing manager and the current trace to the span.
|
|
147
176
|
span.tracingManager = this;
|
|
148
|
-
if (this.trace === undefined) {
|
|
149
|
-
this.loghandler.error("The trace should not be undefined at this point.");
|
|
150
|
-
return span; // Return because tracing should not throw.
|
|
151
|
-
}
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
153
177
|
span.trace = this.trace;
|
|
154
178
|
// Add it to the map of spans
|
|
155
179
|
if (!this.spans[span.keyname]) {
|
|
@@ -244,32 +268,23 @@ let TracingManager = class TracingManager {
|
|
|
244
268
|
if (this.isActive === false) {
|
|
245
269
|
return;
|
|
246
270
|
}
|
|
247
|
-
// Notify
|
|
271
|
+
// Notify every registered tracer that the trace ended. The tracers handle their own
|
|
272
|
+
// formatting + transport (console pretty-print, file dump, X-Ray export, etc.). The
|
|
273
|
+
// manager itself no longer logs a summary here — `ConsoleTracer` produces a richer
|
|
274
|
+
// tree-formatted output when the user opts into it.
|
|
248
275
|
this.tracers.forEach((tracer) => {
|
|
249
276
|
var _a;
|
|
250
277
|
(_a = tracer.traceEndedStream) === null || _a === void 0 ? void 0 : _a.push(this.trace);
|
|
251
278
|
});
|
|
252
|
-
// Trace time
|
|
253
|
-
// Top 5 longest spans
|
|
254
|
-
const longestSpans = Object.values(this.spans).flat(2).sort((a, b) => b.getDuration() - a.getDuration());
|
|
255
|
-
longestSpans.splice(5);
|
|
256
|
-
this.loghandler.debug("Ending the trace. \n" +
|
|
257
|
-
"Trace duration: " + this.trace.getDuration() + " ms \n" +
|
|
258
|
-
"Top 5 longest spans: \n" + longestSpans.map(span => "\t" + span.getDuration() + " ms - " + span.keyname).join("\n"), {
|
|
259
|
-
extra: {
|
|
260
|
-
trace: this.trace,
|
|
261
|
-
},
|
|
262
|
-
eventId: this.trace.id,
|
|
263
|
-
});
|
|
264
279
|
}
|
|
265
280
|
};
|
|
266
281
|
exports.TracingManager = TracingManager;
|
|
267
282
|
exports.TracingManager = TracingManager = __decorate([
|
|
268
283
|
(0, common_1.moduleScoped)(telemetry_module_keyname_1.TelemetryModuleKeyname),
|
|
269
284
|
(0, common_1.tag)("TracingManagerInterface"),
|
|
270
|
-
(0, tsyringe_1.
|
|
285
|
+
(0, tsyringe_1.scoped)(tsyringe_1.Lifecycle.ContainerScoped),
|
|
271
286
|
(0, tsyringe_1.injectable)(),
|
|
272
|
-
__param(0, (0, tsyringe_1.injectAll)(common_1.ServiceDefinitionTagEnum.Tracer)),
|
|
287
|
+
__param(0, (0, tsyringe_1.injectAll)(common_1.ServiceDefinitionTagEnum.Tracer, { isOptional: true })),
|
|
273
288
|
__param(1, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
274
289
|
__param(2, (0, common_1.injectConfig)(telemetry_configuration_keys_1.TelemetryConfigurationKeys.Active)),
|
|
275
290
|
__param(3, (0, common_1.injectConfig)(telemetry_configuration_keys_1.TelemetryConfigurationKeys.Debug)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.manager.js","sourceRoot":"","sources":["../../../../src/managers/tracing.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"tracing.manager.js","sourceRoot":"","sources":["../../../../src/managers/tracing.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAA0E;AAC1E,kFAA2E;AAC3E,uDAA4C;AAC5C,qDAA0C;AAE1C,gDAAmI;AACnI,kEAA2D;AAC3D,0EAAmE;AAInE;;;;;;;;;;;;GAYG;AAKI,IAAM,cAAc,GAApB,MAAM,cAAc;IAWzB;;;;;;;;;;OAUG;IACH,YAAmF,OAA2C,EAC5E,UAAgD,EAC9B,QAAkC,EACnC,KAA+B,EAC9D,cAA8B;QAJkC,YAAO,GAAP,OAAO,CAAmB;QAC3D,eAAU,GAAV,UAAU,CAAqB;QACb,aAAQ,GAAR,QAAQ,CAAS;QAClB,UAAK,GAAL,KAAK,CAAS;QAC9D,mBAAc,GAAd,cAAc,CAAgB;QApBlE;;WAEG;QACI,UAAK,GAAkC,EAAE,CAAC;IAkBjD,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,kBAA0B,mCAAe,CAAC,aAAa,EAAE,OAAgB,EAAE,OAEvF;QACC,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAK,CAAC,OAAO,EAAE,OAAO,CAAC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C;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,oFAAoF;QACpF,oFAAoF;QACpF,mFAAmF;QACnF,oDAAoD;QACpD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAuB,EAAE,EAAE;;YAC/C,MAAA,MAAM,CAAC,gBAAgB,0CAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AA1RY,wCAAc;yBAAd,cAAc;IAJ1B,IAAA,qBAAY,EAAC,iDAAsB,CAAC;IACpC,IAAA,YAAG,EAAC,yBAAyB,CAAC;IAC9B,IAAA,iBAAM,EAAC,oBAAS,CAAC,eAAe,CAAC;IACjC,IAAA,qBAAU,GAAE;IAuBS,WAAA,IAAA,oBAAS,EAAC,iCAAwB,CAAC,MAAM,EAAE,EAAC,UAAU,EAAE,IAAI,EAAC,CAAC,CAAA;IAC9D,WAAA,IAAA,iBAAM,EAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,IAAA,qBAAY,EAAC,yDAA0B,CAAC,MAAM,CAAC,CAAA;IAC/C,WAAA,IAAA,qBAAY,EAAC,yDAA0B,CAAC,KAAK,CAAC,CAAA;sEACd,uBAAc;GA1BvD,cAAc,CA0R1B"}
|
|
@@ -15,5 +15,12 @@ exports.TelemetryConfigurationKeys = void 0;
|
|
|
15
15
|
exports.TelemetryConfigurationKeys = {
|
|
16
16
|
Active: "pristine.telemetry.active",
|
|
17
17
|
Debug: "pristine.telemetry.debug",
|
|
18
|
+
ConsoleTracerActivated: "pristine.telemetry.console-tracer.activated",
|
|
19
|
+
ConsoleTracerOutputMode: "pristine.telemetry.console-tracer.output-mode",
|
|
20
|
+
ConsoleTracerMinimumDurationMs: "pristine.telemetry.console-tracer.minimum-duration-ms",
|
|
21
|
+
FileTracerActivated: "pristine.telemetry.file-tracer.activated",
|
|
22
|
+
FileTracerOutputMode: "pristine.telemetry.file-tracer.output-mode",
|
|
23
|
+
FileTracerDirectory: "pristine.telemetry.file-tracer.directory",
|
|
24
|
+
FileTracerFilenamePattern: "pristine.telemetry.file-tracer.filename-pattern",
|
|
18
25
|
};
|
|
19
26
|
//# sourceMappingURL=telemetry.configuration-keys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.configuration-keys.js","sourceRoot":"","sources":["../../../src/telemetry.configuration-keys.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACU,QAAA,0BAA0B,GAAG;IACxC,MAAM,EAAE,2BAA2B;IACnC,KAAK,EAAE,0BAA0B;
|
|
1
|
+
{"version":3,"file":"telemetry.configuration-keys.js","sourceRoot":"","sources":["../../../src/telemetry.configuration-keys.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACU,QAAA,0BAA0B,GAAG;IACxC,MAAM,EAAE,2BAA2B;IACnC,KAAK,EAAE,0BAA0B;IACjC,sBAAsB,EAAE,6CAA6C;IACrE,uBAAuB,EAAE,+CAA+C;IACxE,8BAA8B,EAAE,uDAAuD;IACvF,mBAAmB,EAAE,0CAA0C;IAC/D,oBAAoB,EAAE,4CAA4C;IAClE,mBAAmB,EAAE,0CAA0C;IAC/D,yBAAyB,EAAE,iDAAiD;CACpE,CAAC"}
|
|
@@ -19,11 +19,14 @@ const common_1 = require("@pristine-ts/common");
|
|
|
19
19
|
const telemetry_module_keyname_1 = require("./telemetry.module.keyname");
|
|
20
20
|
const logging_1 = require("@pristine-ts/logging");
|
|
21
21
|
const configuration_1 = require("@pristine-ts/configuration");
|
|
22
|
+
const console_tracer_output_mode_enum_1 = require("./enums/console-tracer-output-mode.enum");
|
|
23
|
+
__exportStar(require("./decorators/decorators"), exports);
|
|
22
24
|
__exportStar(require("./enums/enums"), exports);
|
|
23
25
|
__exportStar(require("./interfaces/interfaces"), exports);
|
|
24
26
|
__exportStar(require("./managers/managers"), exports);
|
|
25
27
|
__exportStar(require("./models/models"), exports);
|
|
26
28
|
__exportStar(require("./tracers/tracers"), exports);
|
|
29
|
+
__exportStar(require("./utils/utils"), exports);
|
|
27
30
|
__exportStar(require("./telemetry.configuration-keys"), exports);
|
|
28
31
|
exports.TelemetryModule = {
|
|
29
32
|
keyname: telemetry_module_keyname_1.TelemetryModuleKeyname,
|
|
@@ -55,6 +58,93 @@ exports.TelemetryModule = {
|
|
|
55
58
|
defaultResolvers: [
|
|
56
59
|
new configuration_1.BooleanResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_TRACING_DEBUG")),
|
|
57
60
|
]
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Whether `ConsoleTracer` should print completed traces to stdout. Off by default —
|
|
64
|
+
* when on, every trace whose duration exceeds `console-tracer.minimum-duration-ms`
|
|
65
|
+
* is rendered. Best for local development; in production prefer a real backend.
|
|
66
|
+
*/
|
|
67
|
+
{
|
|
68
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".console-tracer.activated",
|
|
69
|
+
defaultValue: false,
|
|
70
|
+
isRequired: false,
|
|
71
|
+
defaultResolvers: [
|
|
72
|
+
new configuration_1.BooleanResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_CONSOLE_TRACER_ACTIVATED")),
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Output format for `ConsoleTracer`. See `ConsoleTracerOutputModeEnum`.
|
|
77
|
+
*/
|
|
78
|
+
{
|
|
79
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".console-tracer.output-mode",
|
|
80
|
+
defaultValue: console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum.Tree,
|
|
81
|
+
isRequired: false,
|
|
82
|
+
defaultResolvers: [
|
|
83
|
+
new configuration_1.EnumResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_CONSOLE_TRACER_OUTPUT_MODE"), console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum),
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Skip rendering traces shorter than this many milliseconds. Useful when most requests
|
|
88
|
+
* are fast and you only want to see the slow outliers. `0` means render everything.
|
|
89
|
+
*/
|
|
90
|
+
{
|
|
91
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".console-tracer.minimum-duration-ms",
|
|
92
|
+
defaultValue: 0,
|
|
93
|
+
isRequired: false,
|
|
94
|
+
defaultResolvers: [
|
|
95
|
+
new configuration_1.NumberResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_CONSOLE_TRACER_MINIMUM_DURATION_MS")),
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Whether `FileTracer` should write completed traces to disk. Off by default. When on,
|
|
100
|
+
* one file per trace is written to `directory` using `filename-pattern`.
|
|
101
|
+
*/
|
|
102
|
+
{
|
|
103
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".file-tracer.activated",
|
|
104
|
+
defaultValue: false,
|
|
105
|
+
isRequired: false,
|
|
106
|
+
defaultResolvers: [
|
|
107
|
+
new configuration_1.BooleanResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_FILE_TRACER_ACTIVATED")),
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Output format for `FileTracer`. Reuses the same enum as `ConsoleTracer` — `json`
|
|
112
|
+
* is the practical default for files since it's machine-readable.
|
|
113
|
+
*/
|
|
114
|
+
{
|
|
115
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".file-tracer.output-mode",
|
|
116
|
+
defaultValue: console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum.Json,
|
|
117
|
+
isRequired: false,
|
|
118
|
+
defaultResolvers: [
|
|
119
|
+
new configuration_1.EnumResolver(new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_FILE_TRACER_OUTPUT_MODE"), console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum),
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Directory where `FileTracer` writes trace files. Resolved relative to `process.cwd()`
|
|
124
|
+
* if not absolute. The directory is created on demand if it doesn't exist.
|
|
125
|
+
*/
|
|
126
|
+
{
|
|
127
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".file-tracer.directory",
|
|
128
|
+
defaultValue: "./traces",
|
|
129
|
+
isRequired: false,
|
|
130
|
+
defaultResolvers: [
|
|
131
|
+
new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_FILE_TRACER_DIRECTORY"),
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Filename pattern for `FileTracer`. Supports the placeholders:
|
|
136
|
+
* - `<traceId>` — the trace's UUID (also used as the eventId throughout Pristine)
|
|
137
|
+
* - `<date>` — UTC date as `YYYY-MM-DD`
|
|
138
|
+
* - `<timestamp>` — milliseconds since epoch at the moment the trace ended
|
|
139
|
+
* Default: `<traceId>.json` (or `.txt` if you change the output mode away from json).
|
|
140
|
+
*/
|
|
141
|
+
{
|
|
142
|
+
parameterName: telemetry_module_keyname_1.TelemetryModuleKeyname + ".file-tracer.filename-pattern",
|
|
143
|
+
defaultValue: "<traceId>.json",
|
|
144
|
+
isRequired: false,
|
|
145
|
+
defaultResolvers: [
|
|
146
|
+
new configuration_1.EnvironmentVariableResolver("PRISTINE_TELEMETRY_FILE_TRACER_FILENAME_PATTERN"),
|
|
147
|
+
]
|
|
58
148
|
}
|
|
59
149
|
]
|
|
60
150
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.module.js","sourceRoot":"","sources":["../../../src/telemetry.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAAkE;AAClE,yEAAkE;AAClE,kDAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"telemetry.module.js","sourceRoot":"","sources":["../../../src/telemetry.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAAkE;AAClE,yEAAkE;AAClE,kDAAmD;AACnD,8DAAsH;AACtH,6FAAoF;AAEpF,0DAAwC;AACxC,gDAA8B;AAC9B,0DAAwC;AACxC,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAE9B,iEAA+C;AAClC,QAAA,eAAe,GAAoB;IAC9C,OAAO,EAAE,iDAAsB;IAC/B,aAAa,EAAE;QACb,qBAAY;QACZ,uBAAa;KACd;IACD,qBAAqB,EAAE,EAAE;IACzB,wBAAwB,EAAE;QACxB;;WAEG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,SAAS;YACjD,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,4BAA4B,CAAC,CAAC;aACnF;SACF;QACD;;;WAGG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,QAAQ;YAChD,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,wBAAwB,CAAC,CAAC;aAC/E;SACF;QACD;;;;WAIG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,2BAA2B;YACnE,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,6CAA6C,CAAC,CAAC;aACpG;SACF;QACD;;WAEG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,6BAA6B;YACrE,YAAY,EAAE,6DAA2B,CAAC,IAAI;YAC9C,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,4BAAY,CAAC,IAAI,2CAA2B,CAAC,+CAA+C,CAAC,EAAE,6DAA2B,CAAC;aAChI;SACF;QACD;;;WAGG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,qCAAqC;YAC7E,YAAY,EAAE,CAAC;YACf,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,8BAAc,CAAC,IAAI,2CAA2B,CAAC,uDAAuD,CAAC,CAAC;aAC7G;SACF;QACD;;;WAGG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,wBAAwB;YAChE,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,+BAAe,CAAC,IAAI,2CAA2B,CAAC,0CAA0C,CAAC,CAAC;aACjG;SACF;QACD;;;WAGG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,0BAA0B;YAClE,YAAY,EAAE,6DAA2B,CAAC,IAAI;YAC9C,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,4BAAY,CAAC,IAAI,2CAA2B,CAAC,4CAA4C,CAAC,EAAE,6DAA2B,CAAC;aAC7H;SACF;QACD;;;WAGG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,wBAAwB;YAChE,YAAY,EAAE,UAAU;YACxB,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,2CAA2B,CAAC,0CAA0C,CAAC;aAC5E;SACF;QACD;;;;;;WAMG;QACH;YACE,aAAa,EAAE,iDAAsB,GAAG,+BAA+B;YACvE,YAAY,EAAE,gBAAgB;YAC9B,UAAU,EAAE,KAAK;YACjB,gBAAgB,EAAE;gBAChB,IAAI,2CAA2B,CAAC,iDAAiD,CAAC;aACnF;SACF;KACF;CACF,CAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ConsoleTracer = void 0;
|
|
16
|
+
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const stream_1 = require("stream");
|
|
18
|
+
const common_1 = require("@pristine-ts/common");
|
|
19
|
+
const console_tracer_output_mode_enum_1 = require("../enums/console-tracer-output-mode.enum");
|
|
20
|
+
const telemetry_configuration_keys_1 = require("../telemetry.configuration-keys");
|
|
21
|
+
const telemetry_module_keyname_1 = require("../telemetry.module.keyname");
|
|
22
|
+
const trace_renderer_1 = require("../utils/trace-renderer");
|
|
23
|
+
/**
|
|
24
|
+
* `ConsoleTracer` prints a completed trace to stdout when the trace ends. Its main purpose
|
|
25
|
+
* is **developer-readable feedback during local development**: see what spans ran, in what
|
|
26
|
+
* order, and which one was the bottleneck — without wiring up an external tracing backend.
|
|
27
|
+
*
|
|
28
|
+
* Off by default. Enable via `pristine.telemetry.console-tracer.activated = true` (or
|
|
29
|
+
* `PRISTINE_TELEMETRY_CONSOLE_TRACER_ACTIVATED=true`). Three output modes:
|
|
30
|
+
* - `tree` (default): indented ASCII tree, durations right-aligned, slowest leaf flagged.
|
|
31
|
+
* - `json`: pretty-printed JSON dump.
|
|
32
|
+
* - `flat`: one line per span, no indentation, start-time-sorted.
|
|
33
|
+
*
|
|
34
|
+
* Crash-isolated: a throw inside the formatting code becomes a stderr line, never an
|
|
35
|
+
* unhandled error or process crash.
|
|
36
|
+
*/
|
|
37
|
+
let ConsoleTracer = class ConsoleTracer {
|
|
38
|
+
constructor(activated, outputMode, minimumDurationMs, logHandler) {
|
|
39
|
+
this.activated = activated;
|
|
40
|
+
this.outputMode = outputMode;
|
|
41
|
+
this.minimumDurationMs = minimumDurationMs;
|
|
42
|
+
this.logHandler = logHandler;
|
|
43
|
+
this.traceEndedStream = new stream_1.Readable({
|
|
44
|
+
objectMode: true,
|
|
45
|
+
read(_size) { return true; },
|
|
46
|
+
});
|
|
47
|
+
this.traceEndedStream.on("data", (trace) => {
|
|
48
|
+
try {
|
|
49
|
+
this.handleTraceEnded(trace);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.reportFailure(error);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.traceEndedStream.on("error", (error) => {
|
|
56
|
+
this.reportFailure(error);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
handleTraceEnded(trace) {
|
|
60
|
+
if (this.activated === false) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (trace.getDuration() < this.minimumDurationMs) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let output;
|
|
67
|
+
switch (this.outputMode) {
|
|
68
|
+
case console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum.Json:
|
|
69
|
+
output = trace_renderer_1.traceRenderer.renderJson(trace);
|
|
70
|
+
break;
|
|
71
|
+
case console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum.Flat:
|
|
72
|
+
output = trace_renderer_1.traceRenderer.renderFlat(trace);
|
|
73
|
+
break;
|
|
74
|
+
case console_tracer_output_mode_enum_1.ConsoleTracerOutputModeEnum.Tree:
|
|
75
|
+
default:
|
|
76
|
+
output = trace_renderer_1.traceRenderer.renderTree(trace);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
// Write directly to stdout. Going through the LogHandler would (a) tag every trace
|
|
80
|
+
// line with severity headers the reader doesn't want, and (b) require the user's log
|
|
81
|
+
// level to be Debug to see anything — defeating the point of opting in.
|
|
82
|
+
process.stdout.write(output + "\n");
|
|
83
|
+
}
|
|
84
|
+
reportFailure(error) {
|
|
85
|
+
const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
86
|
+
try {
|
|
87
|
+
process.stderr.write(`[pristine][tracer:ConsoleTracer] ${message}\n`);
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
// If stderr is unwritable too, there's nothing useful left to do.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.ConsoleTracer = ConsoleTracer;
|
|
95
|
+
exports.ConsoleTracer = ConsoleTracer = __decorate([
|
|
96
|
+
(0, common_1.moduleScoped)(telemetry_module_keyname_1.TelemetryModuleKeyname),
|
|
97
|
+
(0, tsyringe_1.singleton)(),
|
|
98
|
+
(0, common_1.tag)(common_1.ServiceDefinitionTagEnum.Tracer),
|
|
99
|
+
(0, tsyringe_1.injectable)(),
|
|
100
|
+
__param(0, (0, common_1.injectConfig)(telemetry_configuration_keys_1.TelemetryConfigurationKeys.ConsoleTracerActivated)),
|
|
101
|
+
__param(1, (0, common_1.injectConfig)(telemetry_configuration_keys_1.TelemetryConfigurationKeys.ConsoleTracerOutputMode)),
|
|
102
|
+
__param(2, (0, common_1.injectConfig)(telemetry_configuration_keys_1.TelemetryConfigurationKeys.ConsoleTracerMinimumDurationMs)),
|
|
103
|
+
__param(3, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
104
|
+
__metadata("design:paramtypes", [Boolean, String, Number, Object])
|
|
105
|
+
], ConsoleTracer);
|
|
106
|
+
//# sourceMappingURL=console.tracer.js.map
|
|
@@ -0,0 +1 @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