@pristine-ts/telemetry 2.0.3 → 2.0.5
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/enums/span-keyname.enum.js +2 -30
- package/dist/lib/cjs/enums/span-keyname.enum.js.map +1 -1
- package/dist/lib/cjs/managers/tracing.manager.js +171 -42
- package/dist/lib/cjs/managers/tracing.manager.js.map +1 -1
- package/dist/lib/cjs/models/models.js +1 -0
- package/dist/lib/cjs/models/models.js.map +1 -1
- package/dist/lib/cjs/models/span-event.model.js +6 -0
- package/dist/lib/cjs/models/span-event.model.js.map +1 -0
- package/dist/lib/cjs/models/span.model.js +2 -68
- package/dist/lib/cjs/models/span.model.js.map +1 -1
- package/dist/lib/cjs/models/trace.model.js +2 -35
- package/dist/lib/cjs/models/trace.model.js.map +1 -1
- package/dist/lib/cjs/telemetry.module.js +0 -1
- package/dist/lib/cjs/telemetry.module.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/cjs/utils/utils.js +0 -1
- package/dist/lib/cjs/utils/utils.js.map +1 -1
- package/dist/lib/esm/enums/span-keyname.enum.js +1 -30
- package/dist/lib/esm/enums/span-keyname.enum.js.map +1 -1
- package/dist/lib/esm/managers/tracing.manager.js +171 -42
- package/dist/lib/esm/managers/tracing.manager.js.map +1 -1
- package/dist/lib/esm/models/models.js +1 -0
- package/dist/lib/esm/models/models.js.map +1 -1
- package/dist/lib/esm/models/span-event.model.js +2 -0
- package/dist/lib/esm/models/span-event.model.js.map +1 -0
- package/dist/lib/esm/models/span.model.js +1 -67
- package/dist/lib/esm/models/span.model.js.map +1 -1
- package/dist/lib/esm/models/trace.model.js +1 -34
- package/dist/lib/esm/models/trace.model.js.map +1 -1
- package/dist/lib/esm/telemetry.module.js +0 -1
- package/dist/lib/esm/telemetry.module.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/lib/esm/utils/utils.js +0 -1
- package/dist/lib/esm/utils/utils.js.map +1 -1
- package/dist/types/enums/span-keyname.enum.d.ts +1 -29
- package/dist/types/interfaces/tracing-manager.interface.d.ts +1 -50
- package/dist/types/managers/tracing.manager.d.ts +71 -13
- package/dist/types/models/models.d.ts +1 -0
- package/dist/types/models/span-event.model.d.ts +1 -0
- package/dist/types/models/span.model.d.ts +1 -73
- package/dist/types/models/trace.model.d.ts +1 -44
- package/dist/types/telemetry.module.d.ts +0 -1
- package/dist/types/utils/utils.d.ts +0 -1
- package/package.json +4 -4
- package/dist/lib/cjs/decorators/decorators.js +0 -18
- package/dist/lib/cjs/decorators/decorators.js.map +0 -1
- package/dist/lib/cjs/decorators/traced.decorator.js +0 -60
- package/dist/lib/cjs/decorators/traced.decorator.js.map +0 -1
- package/dist/lib/cjs/utils/span-runner.js +0 -112
- package/dist/lib/cjs/utils/span-runner.js.map +0 -1
- package/dist/lib/esm/decorators/decorators.js +0 -2
- package/dist/lib/esm/decorators/decorators.js.map +0 -1
- package/dist/lib/esm/decorators/traced.decorator.js +0 -57
- package/dist/lib/esm/decorators/traced.decorator.js.map +0 -1
- package/dist/lib/esm/utils/span-runner.js +0 -108
- package/dist/lib/esm/utils/span-runner.js.map +0 -1
- package/dist/types/decorators/decorators.d.ts +0 -1
- package/dist/types/decorators/traced.decorator.d.ts +0 -35
- package/dist/types/utils/span-runner.d.ts +0 -55
|
@@ -1,34 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SpanKeynameEnum = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
var SpanKeynameEnum;
|
|
8
|
-
(function (SpanKeynameEnum) {
|
|
9
|
-
SpanKeynameEnum["ChildContainerCreation"] = "child.container.creation";
|
|
10
|
-
SpanKeynameEnum["ChildContainerRegistration"] = "child.container.registration";
|
|
11
|
-
SpanKeynameEnum["ConfigurationInitialization"] = "configuration.initialization";
|
|
12
|
-
SpanKeynameEnum["ErrorResponseInterceptors"] = "error.response.interceptors";
|
|
13
|
-
SpanKeynameEnum["EventDispatcherResolver"] = "event.dispatcher.resolver";
|
|
14
|
-
SpanKeynameEnum["EventExecution"] = "event.execution";
|
|
15
|
-
SpanKeynameEnum["EventInitialization"] = "event.initialization";
|
|
16
|
-
SpanKeynameEnum["EventPreMappingInterception"] = "event.pre-mapping.interception";
|
|
17
|
-
SpanKeynameEnum["EventPostMappingInterception"] = "event.post-mapping.interception";
|
|
18
|
-
SpanKeynameEnum["EventPreResponseMappingInterception"] = "event.pre-response-mapping.interception";
|
|
19
|
-
SpanKeynameEnum["EventPostResponseMappingInterception"] = "event.post-response-mapping.interception";
|
|
20
|
-
SpanKeynameEnum["EventMapping"] = "event.mapping";
|
|
21
|
-
SpanKeynameEnum["KernelInitialization"] = "kernel.initialization";
|
|
22
|
-
SpanKeynameEnum["ModuleInitialization"] = "module.initialization";
|
|
23
|
-
SpanKeynameEnum["ModuleInitializationImportModules"] = "module.initialization.import.modules";
|
|
24
|
-
SpanKeynameEnum["RequestExecution"] = "request.execution";
|
|
25
|
-
SpanKeynameEnum["RequestInterceptors"] = "request.interceptors";
|
|
26
|
-
SpanKeynameEnum["ResponseInterceptors"] = "response.interceptors";
|
|
27
|
-
SpanKeynameEnum["RootExecution"] = "root.execution";
|
|
28
|
-
SpanKeynameEnum["RouterControllerResolver"] = "router.controller.resolver";
|
|
29
|
-
SpanKeynameEnum["RouterFindMethodRouterNode"] = "router.find.method.router.node";
|
|
30
|
-
SpanKeynameEnum["RouterRequestAuthentication"] = "router.request.authentication";
|
|
31
|
-
SpanKeynameEnum["RouterRequestExecution"] = "router.request.execution";
|
|
32
|
-
SpanKeynameEnum["RouterSetup"] = "router.setup";
|
|
33
|
-
})(SpanKeynameEnum || (exports.SpanKeynameEnum = SpanKeynameEnum = {}));
|
|
4
|
+
var common_1 = require("@pristine-ts/common");
|
|
5
|
+
Object.defineProperty(exports, "SpanKeynameEnum", { enumerable: true, get: function () { return common_1.SpanKeynameEnum; } });
|
|
34
6
|
//# sourceMappingURL=span-keyname.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span-keyname.enum.js","sourceRoot":"","sources":["../../../../src/enums/span-keyname.enum.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"span-keyname.enum.js","sourceRoot":"","sources":["../../../../src/enums/span-keyname.enum.ts"],"names":[],"mappings":";;;AAAA,8CAAoD;AAA5C,yGAAA,eAAe,OAAA"}
|
|
@@ -20,18 +20,29 @@ const span_model_1 = require("../models/span.model");
|
|
|
20
20
|
const common_1 = require("@pristine-ts/common");
|
|
21
21
|
const span_keyname_enum_1 = require("../enums/span-keyname.enum");
|
|
22
22
|
const telemetry_module_keyname_1 = require("../telemetry.module.keyname");
|
|
23
|
+
const span_event_model_1 = require("../models/span-event.model");
|
|
23
24
|
/**
|
|
24
25
|
* The Tracing Manager provides methods to help with tracing.
|
|
25
26
|
* It is tagged and can be injected using TracingManagerInterface which facilitates mocking.
|
|
26
27
|
* It is module scoped to the TelemetryModuleKeyname.
|
|
27
28
|
*
|
|
29
|
+
* **Where the active `Trace` lives.** The active trace is stored on `EventContext.trace`,
|
|
30
|
+
* propagated via `AsyncLocalStorage`. Every `TracingManager` instance — whether resolved
|
|
31
|
+
* from the root container (kernel boot) or from a per-event child container — reads and
|
|
32
|
+
* writes spans through the same `EventContext.trace` reference, so a span started in the
|
|
33
|
+
* kernel and an event added in a controller belong to the same trace tree.
|
|
34
|
+
*
|
|
35
|
+
* **Fallback `this.trace`.** During kernel boot (`Kernel.start()` and friends), there is
|
|
36
|
+
* no `EventContext` yet — the framework hasn't started handling an event. In that window
|
|
37
|
+
* the manager falls back to `this.trace`. This is the only time `this.trace` is touched.
|
|
38
|
+
*
|
|
28
39
|
* **Lifecycle: container-scoped, not singleton.** Each per-event DI child container gets
|
|
29
|
-
* its own `TracingManager` instance
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
40
|
+
* its own `TracingManager` instance. The per-instance `this.trace` fallback is what keeps
|
|
41
|
+
* parallel events isolated *if* tracing is somehow started outside an EventContext.
|
|
42
|
+
* Resolving `TracingManager` from the root container returns the root instance (used for
|
|
43
|
+
* kernel-initialization spans); resolving from a child container returns the per-event
|
|
44
|
+
* instance — both will agree on what trace is active inside an event because they read
|
|
45
|
+
* from EventContext.
|
|
35
46
|
*/
|
|
36
47
|
let TracingManager = class TracingManager {
|
|
37
48
|
/**
|
|
@@ -51,10 +62,27 @@ let TracingManager = class TracingManager {
|
|
|
51
62
|
this.isActive = isActive;
|
|
52
63
|
this.debug = debug;
|
|
53
64
|
this.tracingContext = tracingContext;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the currently active trace from the EventContext, falling back to the
|
|
68
|
+
* per-instance `this.trace` when no EventContext is active (kernel boot).
|
|
69
|
+
*/
|
|
70
|
+
getActiveTrace() {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
return (_b = (_a = common_1.EventContextManager.current()) === null || _a === void 0 ? void 0 : _a.trace) !== null && _b !== void 0 ? _b : this.trace;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stores `trace` as the active trace — on `EventContext.trace` when an event is active,
|
|
76
|
+
* otherwise on the instance fallback `this.trace`.
|
|
77
|
+
*/
|
|
78
|
+
setActiveTrace(trace) {
|
|
79
|
+
const eventContext = common_1.EventContextManager.current();
|
|
80
|
+
if (eventContext !== undefined) {
|
|
81
|
+
eventContext.trace = trace;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.trace = trace;
|
|
85
|
+
}
|
|
58
86
|
}
|
|
59
87
|
/**
|
|
60
88
|
* This methods starts the Tracing. This should be the first method called before doing anything else.
|
|
@@ -63,17 +91,18 @@ let TracingManager = class TracingManager {
|
|
|
63
91
|
* @param context The context if there is one.
|
|
64
92
|
*/
|
|
65
93
|
startTracing(spanRootKeyname = span_keyname_enum_1.SpanKeynameEnum.RootExecution, traceId, context) {
|
|
66
|
-
|
|
94
|
+
const trace = new trace_model_1.Trace(traceId, context);
|
|
95
|
+
this.setActiveTrace(trace);
|
|
67
96
|
const span = new span_model_1.Span(spanRootKeyname, undefined, context);
|
|
68
97
|
// Mirror the trace id into both the legacy `TracingContext` (back-compat for any
|
|
69
98
|
// existing consumer that still injects it) and the new ALS-propagated `EventContext`
|
|
70
99
|
// (the path forward; what `LogHandler` and other ALS-aware consumers will read).
|
|
71
100
|
// Both writes are cheap; the dual write is just a transition aid until TracingContext
|
|
72
101
|
// is fully removed in a later major.
|
|
73
|
-
this.tracingContext.traceId =
|
|
102
|
+
this.tracingContext.traceId = trace.id;
|
|
74
103
|
const eventContext = common_1.EventContextManager.current();
|
|
75
104
|
if (eventContext !== undefined) {
|
|
76
|
-
eventContext.traceId =
|
|
105
|
+
eventContext.traceId = trace.id;
|
|
77
106
|
}
|
|
78
107
|
// If the tracing is not active, simply return the created span but don't send to the tracers.
|
|
79
108
|
if (this.isActive === false) {
|
|
@@ -85,17 +114,17 @@ let TracingManager = class TracingManager {
|
|
|
85
114
|
spanRootKeyname,
|
|
86
115
|
traceId,
|
|
87
116
|
context,
|
|
88
|
-
trace
|
|
117
|
+
trace,
|
|
89
118
|
span,
|
|
90
119
|
});
|
|
91
120
|
}
|
|
92
121
|
// Call the tracers and push the trace that was just started
|
|
93
122
|
this.tracers.forEach((tracer) => {
|
|
94
123
|
var _a;
|
|
95
|
-
(_a = tracer.traceStartedStream) === null || _a === void 0 ? void 0 : _a.push(
|
|
124
|
+
(_a = tracer.traceStartedStream) === null || _a === void 0 ? void 0 : _a.push(trace);
|
|
96
125
|
});
|
|
97
126
|
// Define the rootSpan of the trace as the newly created Span. This is the root span.
|
|
98
|
-
|
|
127
|
+
trace.rootSpan = span;
|
|
99
128
|
// Call the addSpan method to ensure that the span will be added.
|
|
100
129
|
this.addSpan(span);
|
|
101
130
|
return span;
|
|
@@ -111,29 +140,31 @@ let TracingManager = class TracingManager {
|
|
|
111
140
|
var _a;
|
|
112
141
|
// Make sure a trace exists. `startTracing` is the canonical entry point, but a direct
|
|
113
142
|
// `startSpan` call (e.g. from project code) should auto-start a trace rather than fail.
|
|
114
|
-
|
|
143
|
+
let trace = this.getActiveTrace();
|
|
144
|
+
if (trace === undefined) {
|
|
115
145
|
this.startTracing(span_keyname_enum_1.SpanKeynameEnum.RootExecution, undefined, context);
|
|
146
|
+
trace = this.getActiveTrace();
|
|
116
147
|
}
|
|
117
148
|
// Construct the span. NOTE the third constructor argument: `Span(keyname, id?, context?)`.
|
|
118
149
|
// A previous version of this code passed `context` in the `id` slot, which corrupted span
|
|
119
|
-
// identities and broke parent-by-id lookup
|
|
150
|
+
// identities and broke parent-by-id lookup silently. Always pass `undefined`
|
|
120
151
|
// for the id so a fresh UUID is generated, and put context in the third slot.
|
|
121
152
|
const span = new span_model_1.Span(keyname, undefined, context);
|
|
122
153
|
// Defensive: tracing must never throw. If the trace is somehow still undefined here
|
|
123
154
|
// (an exception inside `startTracing` that we swallowed and logged), return the bare
|
|
124
155
|
// span so the caller can still call `.end()` on it without exploding.
|
|
125
|
-
if (
|
|
156
|
+
if (trace === undefined) {
|
|
126
157
|
this.loghandler.error("Trace is undefined after startTracing; returning unattached span.", { span });
|
|
127
158
|
return span;
|
|
128
159
|
}
|
|
129
|
-
span.trace =
|
|
160
|
+
span.trace = trace;
|
|
130
161
|
// Resolve the parent span. The default parent is the trace's rootSpan, but we may not
|
|
131
162
|
// have one if the trace was started via a path that didn't set it (programming error
|
|
132
163
|
// upstream, but we tolerate it). When no rootSpan exists, attach the new span as a
|
|
133
164
|
// top-level orphan and warn-log once instead of crashing.
|
|
134
|
-
let parentSpan =
|
|
165
|
+
let parentSpan = trace.rootSpan;
|
|
135
166
|
if (parentKeyname) {
|
|
136
|
-
const parentSpans =
|
|
167
|
+
const parentSpans = trace.spansByKeyname[parentKeyname];
|
|
137
168
|
if (parentSpans) {
|
|
138
169
|
if (parentSpans.length > 1) {
|
|
139
170
|
if (parentId) {
|
|
@@ -152,7 +183,7 @@ let TracingManager = class TracingManager {
|
|
|
152
183
|
this.loghandler.warning("startSpan: no parent span available (rootSpan is undefined). Attaching as orphan.", {
|
|
153
184
|
keyname,
|
|
154
185
|
parentKeyname,
|
|
155
|
-
traceId:
|
|
186
|
+
traceId: trace.id,
|
|
156
187
|
});
|
|
157
188
|
}
|
|
158
189
|
else {
|
|
@@ -169,18 +200,20 @@ let TracingManager = class TracingManager {
|
|
|
169
200
|
// Tracing must never throw. If there's no active trace, log and return the span
|
|
170
201
|
// unchanged — caller can still call `.end()` on it because Span.end uses optional
|
|
171
202
|
// chaining on tracingManager.
|
|
172
|
-
|
|
203
|
+
const trace = this.getActiveTrace();
|
|
204
|
+
if (trace === undefined) {
|
|
173
205
|
this.loghandler.error("You cannot call 'addSpan' without having an existing Trace.", { span });
|
|
174
206
|
return span;
|
|
175
207
|
}
|
|
176
208
|
span.tracingManager = this;
|
|
177
|
-
span.trace =
|
|
178
|
-
// Add it to the
|
|
179
|
-
|
|
180
|
-
|
|
209
|
+
span.trace = trace;
|
|
210
|
+
// Add it to the trace's by-keyname index so any TracingManager instance sharing this
|
|
211
|
+
// trace (via EventContext) can find it.
|
|
212
|
+
if (!trace.spansByKeyname[span.keyname]) {
|
|
213
|
+
trace.spansByKeyname[span.keyname] = [span];
|
|
181
214
|
}
|
|
182
215
|
else {
|
|
183
|
-
|
|
216
|
+
trace.spansByKeyname[span.keyname].push(span);
|
|
184
217
|
}
|
|
185
218
|
// If the tracing is deactivated, simply return the span and don't complain.
|
|
186
219
|
if (this.isActive === false) {
|
|
@@ -189,7 +222,7 @@ let TracingManager = class TracingManager {
|
|
|
189
222
|
if (this.debug) {
|
|
190
223
|
this.loghandler.debug(`[span:start] - ${span.keyname}`, {
|
|
191
224
|
keyname: span.keyname,
|
|
192
|
-
trace
|
|
225
|
+
trace,
|
|
193
226
|
span,
|
|
194
227
|
});
|
|
195
228
|
}
|
|
@@ -207,11 +240,16 @@ let TracingManager = class TracingManager {
|
|
|
207
240
|
* @param keyname The keyname of the span to end.
|
|
208
241
|
*/
|
|
209
242
|
endSpanKeyname(keyname) {
|
|
210
|
-
|
|
243
|
+
const trace = this.getActiveTrace();
|
|
244
|
+
if (trace === undefined) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const spans = trace.spansByKeyname[keyname];
|
|
248
|
+
if (!spans) {
|
|
211
249
|
return;
|
|
212
250
|
}
|
|
213
|
-
if (
|
|
214
|
-
return this.endSpan(
|
|
251
|
+
if (spans.length === 1) {
|
|
252
|
+
return this.endSpan(spans[0]);
|
|
215
253
|
}
|
|
216
254
|
this.loghandler.error("Error ending span by keyname since multiple spans exist with this keyname");
|
|
217
255
|
}
|
|
@@ -221,7 +259,7 @@ let TracingManager = class TracingManager {
|
|
|
221
259
|
* @param span The span to end.
|
|
222
260
|
*/
|
|
223
261
|
endSpan(span) {
|
|
224
|
-
var _a
|
|
262
|
+
var _a;
|
|
225
263
|
if (span.inProgress === false) {
|
|
226
264
|
return;
|
|
227
265
|
}
|
|
@@ -236,7 +274,7 @@ let TracingManager = class TracingManager {
|
|
|
236
274
|
}
|
|
237
275
|
if (this.debug) {
|
|
238
276
|
this.loghandler.debug(`[span:end] - ${span.keyname}`, {
|
|
239
|
-
trace: this.
|
|
277
|
+
trace: this.getActiveTrace(),
|
|
240
278
|
span,
|
|
241
279
|
});
|
|
242
280
|
}
|
|
@@ -246,7 +284,8 @@ let TracingManager = class TracingManager {
|
|
|
246
284
|
(_a = tracer.spanEndedStream) === null || _a === void 0 ? void 0 : _a.push(span);
|
|
247
285
|
});
|
|
248
286
|
// If the span is the root span, the trace has ended
|
|
249
|
-
|
|
287
|
+
const trace = this.getActiveTrace();
|
|
288
|
+
if (span.keyname === ((_a = trace === null || trace === void 0 ? void 0 : trace.rootSpan) === null || _a === void 0 ? void 0 : _a.keyname)) {
|
|
250
289
|
this.endTrace();
|
|
251
290
|
}
|
|
252
291
|
}
|
|
@@ -254,16 +293,17 @@ let TracingManager = class TracingManager {
|
|
|
254
293
|
* This method ends the trace entirely.
|
|
255
294
|
*/
|
|
256
295
|
endTrace() {
|
|
257
|
-
|
|
296
|
+
const trace = this.getActiveTrace();
|
|
297
|
+
if (trace === undefined || trace.hasEnded) {
|
|
258
298
|
return;
|
|
259
299
|
}
|
|
260
300
|
// End the trace by setting the end date.
|
|
261
|
-
|
|
301
|
+
trace.endDate = Date.now();
|
|
262
302
|
// End the trace.
|
|
263
|
-
|
|
303
|
+
trace.hasEnded = true;
|
|
264
304
|
// This method will recursively end all the spans
|
|
265
|
-
if (
|
|
266
|
-
this.endSpan(
|
|
305
|
+
if (trace.rootSpan !== undefined) {
|
|
306
|
+
this.endSpan(trace.rootSpan);
|
|
267
307
|
}
|
|
268
308
|
if (this.isActive === false) {
|
|
269
309
|
return;
|
|
@@ -274,9 +314,98 @@ let TracingManager = class TracingManager {
|
|
|
274
314
|
// tree-formatted output when the user opts into it.
|
|
275
315
|
this.tracers.forEach((tracer) => {
|
|
276
316
|
var _a;
|
|
277
|
-
(_a = tracer.traceEndedStream) === null || _a === void 0 ? void 0 : _a.push(
|
|
317
|
+
(_a = tracer.traceEndedStream) === null || _a === void 0 ? void 0 : _a.push(trace);
|
|
278
318
|
});
|
|
279
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Attaches a named, timestamped event to the most-recently-started in-progress span.
|
|
322
|
+
* Use for noteworthy moments that don't warrant a child span — "validation passed",
|
|
323
|
+
* "found 50 rows", "rate limit ok". Cheap (just pushes onto an array); shows up in
|
|
324
|
+
* the trace rendered by tracers (ConsoleTracer, FileTracer, X-Ray, etc.).
|
|
325
|
+
*
|
|
326
|
+
* If no span is currently active (no trace started, or every span has already ended),
|
|
327
|
+
* a warning is logged and the marker is dropped. The warning is the explicit signal
|
|
328
|
+
* that "this marker call had nowhere to go" — usually the sign of a missing
|
|
329
|
+
* `startTracing()` call earlier in the flow.
|
|
330
|
+
*/
|
|
331
|
+
addEventToCurrentSpan(message, attributes) {
|
|
332
|
+
const target = this.findActiveLeafSpan();
|
|
333
|
+
if (target === undefined) {
|
|
334
|
+
this.loghandler.warning("TracingManager.addEventToCurrentSpan called outside any active trace; marker dropped.", { extra: { message, attributes } });
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
target.events.push(new span_event_model_1.SpanEvent(message, attributes));
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Returns the active trace's spans + their events as a flat, timestamp-sorted list of
|
|
341
|
+
* `{kind, name, date, attributes}` entries. Public utility for custom tracers, debug
|
|
342
|
+
* endpoints, test helpers, or anyone who wants "the active trace as a flat list."
|
|
343
|
+
* Returns an empty array when no active trace exists.
|
|
344
|
+
*/
|
|
345
|
+
getCurrentTrail() {
|
|
346
|
+
const trace = this.getActiveTrace();
|
|
347
|
+
if ((trace === null || trace === void 0 ? void 0 : trace.rootSpan) === undefined)
|
|
348
|
+
return [];
|
|
349
|
+
const out = [];
|
|
350
|
+
const walk = (span) => {
|
|
351
|
+
var _a, _b;
|
|
352
|
+
const suffix = span.inProgress ? " (active)" : "";
|
|
353
|
+
out.push({
|
|
354
|
+
kind: "span",
|
|
355
|
+
name: `${span.keyname}${suffix}`,
|
|
356
|
+
date: new Date(span.startDate),
|
|
357
|
+
attributes: Object.assign({ spanId: span.id }, ((_a = span.context) !== null && _a !== void 0 ? _a : {})),
|
|
358
|
+
});
|
|
359
|
+
for (const event of span.events) {
|
|
360
|
+
out.push({
|
|
361
|
+
kind: "event",
|
|
362
|
+
name: event.message,
|
|
363
|
+
date: new Date(event.timestamp),
|
|
364
|
+
attributes: Object.assign({ spanKeyname: span.keyname }, ((_b = event.attributes) !== null && _b !== void 0 ? _b : {})),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
for (const child of span.children) {
|
|
368
|
+
walk(child);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
walk(trace.rootSpan);
|
|
372
|
+
out.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Finds the deepest in-progress span — the leaf of the still-open subtree. Used as
|
|
377
|
+
* the target for `addEventToCurrentSpan`. Intuition: events attach to whatever is
|
|
378
|
+
* currently open at the bottom of the call stack.
|
|
379
|
+
*
|
|
380
|
+
* Walking the in-progress subtree (rather than ranking all spans by start date)
|
|
381
|
+
* avoids the edge case where a parent and child have the same `Date.now()` value —
|
|
382
|
+
* picking the "latest started" by raw timestamp would incorrectly attach to the
|
|
383
|
+
* parent. Depth-first traversal of in-progress children naturally lands on the
|
|
384
|
+
* deepest leaf. Tie-broken by latest start date when multiple leaves exist.
|
|
385
|
+
*
|
|
386
|
+
* Returns undefined when nothing is in progress (no trace, or every span has ended).
|
|
387
|
+
* @private
|
|
388
|
+
*/
|
|
389
|
+
findActiveLeafSpan() {
|
|
390
|
+
const trace = this.getActiveTrace();
|
|
391
|
+
if ((trace === null || trace === void 0 ? void 0 : trace.rootSpan) === undefined)
|
|
392
|
+
return undefined;
|
|
393
|
+
let best;
|
|
394
|
+
const walk = (span) => {
|
|
395
|
+
const inProgressChildren = span.children.filter(c => c.inProgress);
|
|
396
|
+
if (span.inProgress && inProgressChildren.length === 0) {
|
|
397
|
+
// This span is a leaf of the in-progress subtree. Among multiple such leaves,
|
|
398
|
+
// prefer the latest-started one (most recent in time).
|
|
399
|
+
if (best === undefined || span.startDate >= best.startDate) {
|
|
400
|
+
best = span;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
for (const child of inProgressChildren)
|
|
404
|
+
walk(child);
|
|
405
|
+
};
|
|
406
|
+
walk(trace.rootSpan);
|
|
407
|
+
return best;
|
|
408
|
+
}
|
|
280
409
|
};
|
|
281
410
|
exports.TracingManager = TracingManager;
|
|
282
411
|
exports.TracingManager = TracingManager = __decorate([
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAGnE,iEAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKI,IAAM,cAAc,GAApB,MAAM,cAAc;IAOzB;;;;;;;;;;OAUG;IACH,YAAoG,OAA0B,EAC3D,UAA+B,EACb,QAAiB,EAClB,KAAc,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;IAClE,CAAC;IAED;;;OAGG;IACK,cAAc;;QACpB,OAAO,MAAA,MAAA,4BAAmB,CAAC,OAAO,EAAE,0CAAE,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,KAAY;QACjC,MAAM,YAAY,GAAG,4BAAmB,CAAC,OAAO,EAAE,CAAC;QACnD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;IACH,CAAC;IAED;;;;;OA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tBvD,cAAc,CAka1B"}
|
|
@@ -14,6 +14,7 @@ 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("./span-event.model"), exports);
|
|
17
18
|
__exportStar(require("./span.model"), exports);
|
|
18
19
|
__exportStar(require("./trace.model"), exports);
|
|
19
20
|
//# sourceMappingURL=models.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/models/models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/models/models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,+CAA6B;AAC7B,gDAA8B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpanEvent = void 0;
|
|
4
|
+
var common_1 = require("@pristine-ts/common");
|
|
5
|
+
Object.defineProperty(exports, "SpanEvent", { enumerable: true, get: function () { return common_1.SpanEvent; } });
|
|
6
|
+
//# sourceMappingURL=span-event.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-event.model.js","sourceRoot":"","sources":["../../../../src/models/span-event.model.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAAtC,mGAAA,SAAS,OAAA"}
|
|
@@ -1,72 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Span = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* This model represents a span.
|
|
7
|
-
*/
|
|
8
|
-
class Span {
|
|
9
|
-
/**
|
|
10
|
-
* This model represents a span.
|
|
11
|
-
* @param keyname The keyname of the span.
|
|
12
|
-
* @param id The unique id of the span.
|
|
13
|
-
* @param context The context to associate with the span.
|
|
14
|
-
*/
|
|
15
|
-
constructor(keyname, id, context) {
|
|
16
|
-
this.keyname = keyname;
|
|
17
|
-
/**
|
|
18
|
-
* The timestamp in milliseconds at which the span was started.
|
|
19
|
-
*/
|
|
20
|
-
this.startDate = Date.now();
|
|
21
|
-
/**
|
|
22
|
-
* The children spans.
|
|
23
|
-
*/
|
|
24
|
-
this.children = [];
|
|
25
|
-
/**
|
|
26
|
-
* The context associated with the span.
|
|
27
|
-
*/
|
|
28
|
-
this.context = {};
|
|
29
|
-
/**
|
|
30
|
-
* Whether or not the span is in progress, meaning it has not ended.
|
|
31
|
-
*/
|
|
32
|
-
this.inProgress = true;
|
|
33
|
-
this.id = id !== null && id !== void 0 ? id : (0, uuid_1.v4)();
|
|
34
|
-
this.context = context !== null && context !== void 0 ? context : {};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* This method returns the duration of the span in milliseconds.
|
|
38
|
-
*/
|
|
39
|
-
getDuration() {
|
|
40
|
-
var _a;
|
|
41
|
-
return ((_a = this.endDate) !== null && _a !== void 0 ? _a : Date.now()) - this.startDate;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* This method ends the span.
|
|
45
|
-
*/
|
|
46
|
-
end() {
|
|
47
|
-
var _a;
|
|
48
|
-
(_a = this.tracingManager) === null || _a === void 0 ? void 0 : _a.endSpan(this);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* This method sets the trace for the span and all of its children.
|
|
52
|
-
* @param trace The trace the span should be attached to.
|
|
53
|
-
*/
|
|
54
|
-
setTrace(trace) {
|
|
55
|
-
this.trace = trace;
|
|
56
|
-
this.children.forEach(childSpan => childSpan.setTrace(trace));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* This method adds a child span to the current span. It only adds it if it's not already part of the children.
|
|
60
|
-
* @param span The span to add as a child.
|
|
61
|
-
*/
|
|
62
|
-
addChild(span) {
|
|
63
|
-
const existingChildSpan = this.children.find(childSpan => childSpan.id === span.id);
|
|
64
|
-
if (existingChildSpan) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
span.parentSpan = this;
|
|
68
|
-
this.children.push(span);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.Span = Span;
|
|
4
|
+
var common_1 = require("@pristine-ts/common");
|
|
5
|
+
Object.defineProperty(exports, "Span", { enumerable: true, get: function () { return common_1.Span; } });
|
|
72
6
|
//# sourceMappingURL=span.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span.model.js","sourceRoot":"","sources":["../../../../src/models/span.model.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"span.model.js","sourceRoot":"","sources":["../../../../src/models/span.model.ts"],"names":[],"mappings":";;;AAAA,8CAAsE;AAA9D,8FAAA,IAAI,OAAA"}
|
|
@@ -1,39 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Trace = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* This model represents a trace.
|
|
7
|
-
*/
|
|
8
|
-
class Trace {
|
|
9
|
-
/**
|
|
10
|
-
* This model represents a trace.
|
|
11
|
-
* @param id The unique id of the trace.
|
|
12
|
-
* @param context The context associated with the trace.
|
|
13
|
-
*/
|
|
14
|
-
constructor(id, context) {
|
|
15
|
-
/**
|
|
16
|
-
* The timestamp in milliseconds at which the trace was started.
|
|
17
|
-
*/
|
|
18
|
-
this.startDate = Date.now();
|
|
19
|
-
/**
|
|
20
|
-
* The context associated with the trace.
|
|
21
|
-
*/
|
|
22
|
-
this.context = {};
|
|
23
|
-
/**
|
|
24
|
-
* Whether or not the trace was ended.
|
|
25
|
-
*/
|
|
26
|
-
this.hasEnded = false;
|
|
27
|
-
this.id = id !== null && id !== void 0 ? id : (0, uuid_1.v4)();
|
|
28
|
-
this.context = context !== null && context !== void 0 ? context : {};
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* This returns the duration of the trace in miliseconds.
|
|
32
|
-
*/
|
|
33
|
-
getDuration() {
|
|
34
|
-
var _a;
|
|
35
|
-
return ((_a = this.endDate) !== null && _a !== void 0 ? _a : Date.now()) - this.startDate;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.Trace = Trace;
|
|
4
|
+
var common_1 = require("@pristine-ts/common");
|
|
5
|
+
Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return common_1.Trace; } });
|
|
39
6
|
//# sourceMappingURL=trace.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.model.js","sourceRoot":"","sources":["../../../../src/models/trace.model.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"trace.model.js","sourceRoot":"","sources":["../../../../src/models/trace.model.ts"],"names":[],"mappings":";;;AAAA,8CAA0C;AAAlC,+FAAA,KAAK,OAAA"}
|
|
@@ -20,7 +20,6 @@ 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
22
|
const console_tracer_output_mode_enum_1 = require("./enums/console-tracer-output-mode.enum");
|
|
23
|
-
__exportStar(require("./decorators/decorators"), exports);
|
|
24
23
|
__exportStar(require("./enums/enums"), exports);
|
|
25
24
|
__exportStar(require("./interfaces/interfaces"), exports);
|
|
26
25
|
__exportStar(require("./managers/managers"), exports);
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,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,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