@pristine-ts/telemetry 2.0.2 → 2.0.4
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 +182 -37
- 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/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/cjs/utils/span-runner.js +3 -77
- package/dist/lib/cjs/utils/span-runner.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 +184 -39
- 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/tsconfig.tsbuildinfo +1 -1
- package/dist/lib/esm/utils/span-runner.js +1 -76
- package/dist/lib/esm/utils/span-runner.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 +73 -7
- 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/utils/span-runner.d.ts +1 -59
- package/package.json +4 -4
|
@@ -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,10 +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.
|
|
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
|
+
*
|
|
39
|
+
* **Lifecycle: container-scoped, not singleton.** Each per-event DI child container gets
|
|
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.
|
|
27
46
|
*/
|
|
28
47
|
let TracingManager = class TracingManager {
|
|
29
48
|
/**
|
|
@@ -43,10 +62,27 @@ let TracingManager = class TracingManager {
|
|
|
43
62
|
this.isActive = isActive;
|
|
44
63
|
this.debug = debug;
|
|
45
64
|
this.tracingContext = tracingContext;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}
|
|
50
86
|
}
|
|
51
87
|
/**
|
|
52
88
|
* This methods starts the Tracing. This should be the first method called before doing anything else.
|
|
@@ -55,10 +91,19 @@ let TracingManager = class TracingManager {
|
|
|
55
91
|
* @param context The context if there is one.
|
|
56
92
|
*/
|
|
57
93
|
startTracing(spanRootKeyname = span_keyname_enum_1.SpanKeynameEnum.RootExecution, traceId, context) {
|
|
58
|
-
|
|
94
|
+
const trace = new trace_model_1.Trace(traceId, context);
|
|
95
|
+
this.setActiveTrace(trace);
|
|
59
96
|
const span = new span_model_1.Span(spanRootKeyname, undefined, context);
|
|
60
|
-
//
|
|
61
|
-
|
|
97
|
+
// Mirror the trace id into both the legacy `TracingContext` (back-compat for any
|
|
98
|
+
// existing consumer that still injects it) and the new ALS-propagated `EventContext`
|
|
99
|
+
// (the path forward; what `LogHandler` and other ALS-aware consumers will read).
|
|
100
|
+
// Both writes are cheap; the dual write is just a transition aid until TracingContext
|
|
101
|
+
// is fully removed in a later major.
|
|
102
|
+
this.tracingContext.traceId = trace.id;
|
|
103
|
+
const eventContext = common_1.EventContextManager.current();
|
|
104
|
+
if (eventContext !== undefined) {
|
|
105
|
+
eventContext.traceId = trace.id;
|
|
106
|
+
}
|
|
62
107
|
// If the tracing is not active, simply return the created span but don't send to the tracers.
|
|
63
108
|
if (this.isActive === false) {
|
|
64
109
|
return span;
|
|
@@ -69,17 +114,17 @@ let TracingManager = class TracingManager {
|
|
|
69
114
|
spanRootKeyname,
|
|
70
115
|
traceId,
|
|
71
116
|
context,
|
|
72
|
-
trace
|
|
117
|
+
trace,
|
|
73
118
|
span,
|
|
74
119
|
});
|
|
75
120
|
}
|
|
76
121
|
// Call the tracers and push the trace that was just started
|
|
77
122
|
this.tracers.forEach((tracer) => {
|
|
78
123
|
var _a;
|
|
79
|
-
(_a = tracer.traceStartedStream) === null || _a === void 0 ? void 0 : _a.push(
|
|
124
|
+
(_a = tracer.traceStartedStream) === null || _a === void 0 ? void 0 : _a.push(trace);
|
|
80
125
|
});
|
|
81
126
|
// Define the rootSpan of the trace as the newly created Span. This is the root span.
|
|
82
|
-
|
|
127
|
+
trace.rootSpan = span;
|
|
83
128
|
// Call the addSpan method to ensure that the span will be added.
|
|
84
129
|
this.addSpan(span);
|
|
85
130
|
return span;
|
|
@@ -95,29 +140,31 @@ let TracingManager = class TracingManager {
|
|
|
95
140
|
var _a;
|
|
96
141
|
// Make sure a trace exists. `startTracing` is the canonical entry point, but a direct
|
|
97
142
|
// `startSpan` call (e.g. from project code) should auto-start a trace rather than fail.
|
|
98
|
-
|
|
143
|
+
let trace = this.getActiveTrace();
|
|
144
|
+
if (trace === undefined) {
|
|
99
145
|
this.startTracing(span_keyname_enum_1.SpanKeynameEnum.RootExecution, undefined, context);
|
|
146
|
+
trace = this.getActiveTrace();
|
|
100
147
|
}
|
|
101
148
|
// Construct the span. NOTE the third constructor argument: `Span(keyname, id?, context?)`.
|
|
102
149
|
// A previous version of this code passed `context` in the `id` slot, which corrupted span
|
|
103
|
-
// identities and broke parent-by-id lookup
|
|
150
|
+
// identities and broke parent-by-id lookup silently. Always pass `undefined`
|
|
104
151
|
// for the id so a fresh UUID is generated, and put context in the third slot.
|
|
105
152
|
const span = new span_model_1.Span(keyname, undefined, context);
|
|
106
153
|
// Defensive: tracing must never throw. If the trace is somehow still undefined here
|
|
107
154
|
// (an exception inside `startTracing` that we swallowed and logged), return the bare
|
|
108
155
|
// span so the caller can still call `.end()` on it without exploding.
|
|
109
|
-
if (
|
|
156
|
+
if (trace === undefined) {
|
|
110
157
|
this.loghandler.error("Trace is undefined after startTracing; returning unattached span.", { span });
|
|
111
158
|
return span;
|
|
112
159
|
}
|
|
113
|
-
span.trace =
|
|
160
|
+
span.trace = trace;
|
|
114
161
|
// Resolve the parent span. The default parent is the trace's rootSpan, but we may not
|
|
115
162
|
// have one if the trace was started via a path that didn't set it (programming error
|
|
116
163
|
// upstream, but we tolerate it). When no rootSpan exists, attach the new span as a
|
|
117
164
|
// top-level orphan and warn-log once instead of crashing.
|
|
118
|
-
let parentSpan =
|
|
165
|
+
let parentSpan = trace.rootSpan;
|
|
119
166
|
if (parentKeyname) {
|
|
120
|
-
const parentSpans =
|
|
167
|
+
const parentSpans = trace.spansByKeyname[parentKeyname];
|
|
121
168
|
if (parentSpans) {
|
|
122
169
|
if (parentSpans.length > 1) {
|
|
123
170
|
if (parentId) {
|
|
@@ -136,7 +183,7 @@ let TracingManager = class TracingManager {
|
|
|
136
183
|
this.loghandler.warning("startSpan: no parent span available (rootSpan is undefined). Attaching as orphan.", {
|
|
137
184
|
keyname,
|
|
138
185
|
parentKeyname,
|
|
139
|
-
traceId:
|
|
186
|
+
traceId: trace.id,
|
|
140
187
|
});
|
|
141
188
|
}
|
|
142
189
|
else {
|
|
@@ -153,18 +200,20 @@ let TracingManager = class TracingManager {
|
|
|
153
200
|
// Tracing must never throw. If there's no active trace, log and return the span
|
|
154
201
|
// unchanged — caller can still call `.end()` on it because Span.end uses optional
|
|
155
202
|
// chaining on tracingManager.
|
|
156
|
-
|
|
203
|
+
const trace = this.getActiveTrace();
|
|
204
|
+
if (trace === undefined) {
|
|
157
205
|
this.loghandler.error("You cannot call 'addSpan' without having an existing Trace.", { span });
|
|
158
206
|
return span;
|
|
159
207
|
}
|
|
160
208
|
span.tracingManager = this;
|
|
161
|
-
span.trace =
|
|
162
|
-
// Add it to the
|
|
163
|
-
|
|
164
|
-
|
|
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];
|
|
165
214
|
}
|
|
166
215
|
else {
|
|
167
|
-
|
|
216
|
+
trace.spansByKeyname[span.keyname].push(span);
|
|
168
217
|
}
|
|
169
218
|
// If the tracing is deactivated, simply return the span and don't complain.
|
|
170
219
|
if (this.isActive === false) {
|
|
@@ -173,7 +222,7 @@ let TracingManager = class TracingManager {
|
|
|
173
222
|
if (this.debug) {
|
|
174
223
|
this.loghandler.debug(`[span:start] - ${span.keyname}`, {
|
|
175
224
|
keyname: span.keyname,
|
|
176
|
-
trace
|
|
225
|
+
trace,
|
|
177
226
|
span,
|
|
178
227
|
});
|
|
179
228
|
}
|
|
@@ -191,11 +240,16 @@ let TracingManager = class TracingManager {
|
|
|
191
240
|
* @param keyname The keyname of the span to end.
|
|
192
241
|
*/
|
|
193
242
|
endSpanKeyname(keyname) {
|
|
194
|
-
|
|
243
|
+
const trace = this.getActiveTrace();
|
|
244
|
+
if (trace === undefined) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const spans = trace.spansByKeyname[keyname];
|
|
248
|
+
if (!spans) {
|
|
195
249
|
return;
|
|
196
250
|
}
|
|
197
|
-
if (
|
|
198
|
-
return this.endSpan(
|
|
251
|
+
if (spans.length === 1) {
|
|
252
|
+
return this.endSpan(spans[0]);
|
|
199
253
|
}
|
|
200
254
|
this.loghandler.error("Error ending span by keyname since multiple spans exist with this keyname");
|
|
201
255
|
}
|
|
@@ -205,7 +259,7 @@ let TracingManager = class TracingManager {
|
|
|
205
259
|
* @param span The span to end.
|
|
206
260
|
*/
|
|
207
261
|
endSpan(span) {
|
|
208
|
-
var _a
|
|
262
|
+
var _a;
|
|
209
263
|
if (span.inProgress === false) {
|
|
210
264
|
return;
|
|
211
265
|
}
|
|
@@ -220,7 +274,7 @@ let TracingManager = class TracingManager {
|
|
|
220
274
|
}
|
|
221
275
|
if (this.debug) {
|
|
222
276
|
this.loghandler.debug(`[span:end] - ${span.keyname}`, {
|
|
223
|
-
trace: this.
|
|
277
|
+
trace: this.getActiveTrace(),
|
|
224
278
|
span,
|
|
225
279
|
});
|
|
226
280
|
}
|
|
@@ -230,7 +284,8 @@ let TracingManager = class TracingManager {
|
|
|
230
284
|
(_a = tracer.spanEndedStream) === null || _a === void 0 ? void 0 : _a.push(span);
|
|
231
285
|
});
|
|
232
286
|
// If the span is the root span, the trace has ended
|
|
233
|
-
|
|
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)) {
|
|
234
289
|
this.endTrace();
|
|
235
290
|
}
|
|
236
291
|
}
|
|
@@ -238,16 +293,17 @@ let TracingManager = class TracingManager {
|
|
|
238
293
|
* This method ends the trace entirely.
|
|
239
294
|
*/
|
|
240
295
|
endTrace() {
|
|
241
|
-
|
|
296
|
+
const trace = this.getActiveTrace();
|
|
297
|
+
if (trace === undefined || trace.hasEnded) {
|
|
242
298
|
return;
|
|
243
299
|
}
|
|
244
300
|
// End the trace by setting the end date.
|
|
245
|
-
|
|
301
|
+
trace.endDate = Date.now();
|
|
246
302
|
// End the trace.
|
|
247
|
-
|
|
303
|
+
trace.hasEnded = true;
|
|
248
304
|
// This method will recursively end all the spans
|
|
249
|
-
if (
|
|
250
|
-
this.endSpan(
|
|
305
|
+
if (trace.rootSpan !== undefined) {
|
|
306
|
+
this.endSpan(trace.rootSpan);
|
|
251
307
|
}
|
|
252
308
|
if (this.isActive === false) {
|
|
253
309
|
return;
|
|
@@ -258,15 +314,104 @@ let TracingManager = class TracingManager {
|
|
|
258
314
|
// tree-formatted output when the user opts into it.
|
|
259
315
|
this.tracers.forEach((tracer) => {
|
|
260
316
|
var _a;
|
|
261
|
-
(_a = tracer.traceEndedStream) === null || _a === void 0 ? void 0 : _a.push(
|
|
317
|
+
(_a = tracer.traceEndedStream) === null || _a === void 0 ? void 0 : _a.push(trace);
|
|
262
318
|
});
|
|
263
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
|
+
}
|
|
264
409
|
};
|
|
265
410
|
exports.TracingManager = TracingManager;
|
|
266
411
|
exports.TracingManager = TracingManager = __decorate([
|
|
267
412
|
(0, common_1.moduleScoped)(telemetry_module_keyname_1.TelemetryModuleKeyname),
|
|
268
413
|
(0, common_1.tag)("TracingManagerInterface"),
|
|
269
|
-
(0, tsyringe_1.
|
|
414
|
+
(0, tsyringe_1.scoped)(tsyringe_1.Lifecycle.ContainerScoped),
|
|
270
415
|
(0, tsyringe_1.injectable)(),
|
|
271
416
|
__param(0, (0, tsyringe_1.injectAll)(common_1.ServiceDefinitionTagEnum.Tracer, { isOptional: true })),
|
|
272
417
|
__param(1, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
@@ -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;AAGnE,iEAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKI,IAAM,cAA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,CAAC;gBACd,CAAC;YACH,CAAC;YACD,KAAK,MAAM,KAAK,IAAI,kBAAkB;gBAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAlaY,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;IAmBS,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;GAtBvD,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"}
|