@pristine-ts/common 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/common.module.js +1 -0
- package/dist/lib/cjs/common.module.js.map +1 -1
- package/dist/lib/cjs/contexts/contexts.js +1 -0
- package/dist/lib/cjs/contexts/contexts.js.map +1 -1
- package/dist/lib/cjs/contexts/event-context.js +23 -0
- package/dist/lib/cjs/contexts/event-context.js.map +1 -0
- package/dist/lib/cjs/contexts/tracing.context.js +14 -0
- package/dist/lib/cjs/contexts/tracing.context.js.map +1 -1
- package/dist/lib/cjs/decorators/decorators.js +1 -0
- package/dist/lib/cjs/decorators/decorators.js.map +1 -1
- package/dist/lib/cjs/decorators/traced.decorator.js +65 -0
- package/dist/lib/cjs/decorators/traced.decorator.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/enums/span-keyname.enum.js +34 -0
- package/dist/lib/cjs/enums/span-keyname.enum.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
- package/dist/lib/cjs/interfaces/tracing-manager.interface.js +3 -0
- package/dist/lib/cjs/interfaces/tracing-manager.interface.js.map +1 -0
- package/dist/lib/cjs/managers/event-context.manager.js +107 -0
- package/dist/lib/cjs/managers/event-context.manager.js.map +1 -0
- package/dist/lib/cjs/managers/managers.js +18 -0
- package/dist/lib/cjs/managers/managers.js.map +1 -0
- package/dist/lib/cjs/models/models.js +3 -0
- package/dist/lib/cjs/models/models.js.map +1 -1
- package/dist/lib/cjs/models/span-event.model.js +28 -0
- package/dist/lib/cjs/models/span-event.model.js.map +1 -0
- package/dist/lib/cjs/models/span.model.js +79 -0
- package/dist/lib/cjs/models/span.model.js.map +1 -0
- package/dist/lib/cjs/models/trace.model.js +46 -0
- package/dist/lib/cjs/models/trace.model.js.map +1 -0
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/cjs/utils/span-runner.js +117 -0
- package/dist/lib/cjs/utils/span-runner.js.map +1 -0
- package/dist/lib/cjs/utils/utils.js +1 -0
- package/dist/lib/cjs/utils/utils.js.map +1 -1
- package/dist/lib/esm/common.module.js +1 -0
- package/dist/lib/esm/common.module.js.map +1 -1
- package/dist/lib/esm/contexts/contexts.js +1 -0
- package/dist/lib/esm/contexts/contexts.js.map +1 -1
- package/dist/lib/esm/contexts/event-context.js +19 -0
- package/dist/lib/esm/contexts/event-context.js.map +1 -0
- package/dist/lib/esm/contexts/tracing.context.js +14 -0
- package/dist/lib/esm/contexts/tracing.context.js.map +1 -1
- package/dist/lib/esm/decorators/decorators.js +1 -0
- package/dist/lib/esm/decorators/decorators.js.map +1 -1
- package/dist/lib/esm/decorators/traced.decorator.js +62 -0
- package/dist/lib/esm/decorators/traced.decorator.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/enums/span-keyname.enum.js +31 -0
- package/dist/lib/esm/enums/span-keyname.enum.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +1 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
- package/dist/lib/esm/interfaces/tracing-manager.interface.js +2 -0
- package/dist/lib/esm/interfaces/tracing-manager.interface.js.map +1 -0
- package/dist/lib/esm/managers/event-context.manager.js +104 -0
- package/dist/lib/esm/managers/event-context.manager.js.map +1 -0
- package/dist/lib/esm/managers/managers.js +2 -0
- package/dist/lib/esm/managers/managers.js.map +1 -0
- package/dist/lib/esm/models/models.js +3 -0
- package/dist/lib/esm/models/models.js.map +1 -1
- package/dist/lib/esm/models/span-event.model.js +24 -0
- package/dist/lib/esm/models/span-event.model.js.map +1 -0
- package/dist/lib/esm/models/span.model.js +75 -0
- package/dist/lib/esm/models/span.model.js.map +1 -0
- package/dist/lib/esm/models/trace.model.js +42 -0
- package/dist/lib/esm/models/trace.model.js.map +1 -0
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/lib/esm/utils/span-runner.js +113 -0
- package/dist/lib/esm/utils/span-runner.js.map +1 -0
- package/dist/lib/esm/utils/utils.js +1 -0
- package/dist/lib/esm/utils/utils.js.map +1 -1
- package/dist/types/common.module.d.ts +1 -0
- package/dist/types/contexts/contexts.d.ts +1 -0
- package/dist/types/contexts/event-context.d.ts +35 -0
- package/dist/types/contexts/tracing.context.d.ts +14 -0
- package/dist/types/decorators/decorators.d.ts +1 -0
- package/dist/types/decorators/traced.decorator.d.ts +40 -0
- package/dist/types/enums/enums.d.ts +1 -0
- package/dist/types/enums/span-keyname.enum.d.ts +29 -0
- package/dist/types/interfaces/interfaces.d.ts +1 -0
- package/dist/types/interfaces/tracing-manager.interface.d.ts +78 -0
- package/dist/types/managers/event-context.manager.d.ts +58 -0
- package/dist/types/managers/managers.d.ts +1 -0
- package/dist/types/models/models.d.ts +3 -0
- package/dist/types/models/span-event.model.d.ts +30 -0
- package/dist/types/models/span.model.d.ts +90 -0
- package/dist/types/models/trace.model.d.ts +53 -0
- package/dist/types/utils/span-runner.d.ts +55 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
|
@@ -20,6 +20,7 @@ __exportStar(require("./contexts/contexts"), exports);
|
|
|
20
20
|
__exportStar(require("./decorators/decorators"), exports);
|
|
21
21
|
__exportStar(require("./enums/enums"), exports);
|
|
22
22
|
__exportStar(require("./errors/errors"), exports);
|
|
23
|
+
__exportStar(require("./managers/managers"), exports);
|
|
23
24
|
__exportStar(require("./models/models"), exports);
|
|
24
25
|
__exportStar(require("./interfaces/interfaces"), exports);
|
|
25
26
|
__exportStar(require("./types/types"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.module.js","sourceRoot":"","sources":["../../../src/common.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mEAA4D;AAG5D,sDAAoC;AACpC,0DAAwC;AACxC,gDAA8B;AAC9B,kDAAgC;AAChC,kDAAgC;AAChC,0DAAwC;AACxC,gDAA8B;AAC9B,gDAA8B;AAC9B,0DAAwC;AAE3B,QAAA,YAAY,GAAoB;IAC3C,OAAO,EAAE,2CAAmB;IAC5B,aAAa,EAAE,EAAE;IACjB,qBAAqB,EAAE,EAAE;CAC1B,CAAA"}
|
|
1
|
+
{"version":3,"file":"common.module.js","sourceRoot":"","sources":["../../../src/common.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mEAA4D;AAG5D,sDAAoC;AACpC,0DAAwC;AACxC,gDAA8B;AAC9B,kDAAgC;AAChC,sDAAoC;AACpC,kDAAgC;AAChC,0DAAwC;AACxC,gDAA8B;AAC9B,gDAA8B;AAC9B,0DAAwC;AAE3B,QAAA,YAAY,GAAoB;IAC3C,OAAO,EAAE,2CAAmB;IAC5B,aAAa,EAAE,EAAE;IACjB,qBAAqB,EAAE,EAAE;CAC1B,CAAA"}
|
|
@@ -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("./event-context"), exports);
|
|
17
18
|
__exportStar(require("./tracing.context"), exports);
|
|
18
19
|
//# sourceMappingURL=contexts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../../../src/contexts/contexts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../../../src/contexts/contexts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,oDAAkC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventContext = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Per-event runtime state — the framework's correlation primitives plus a handle to
|
|
6
|
+
* the per-event DI child container and the active trace. Propagated implicitly via
|
|
7
|
+
* `AsyncLocalStorage` (managed by `EventContextManager`) so downstream code doesn't
|
|
8
|
+
* have to thread these fields through every method signature.
|
|
9
|
+
*
|
|
10
|
+
* **Not to be confused with `ExecutionContextInterface` (in `@pristine-ts/core`):**
|
|
11
|
+
* - `ExecutionContext` describes *where* the framework is running (AWS Lambda, CLI,
|
|
12
|
+
* Express, etc.) — set once per `kernel.handle()` call, immutable, host-shaped.
|
|
13
|
+
* - `EventContext` describes *which specific event* is being handled — set per event
|
|
14
|
+
* in the pipeline, mutable (`traceId` / `trace` fill in once tracing starts),
|
|
15
|
+
* correlation-shaped.
|
|
16
|
+
*
|
|
17
|
+
* One `kernel.handle()` call can produce multiple events (each event mapper can return
|
|
18
|
+
* a list); each event gets its own `EventContext` instance.
|
|
19
|
+
*/
|
|
20
|
+
class EventContext {
|
|
21
|
+
}
|
|
22
|
+
exports.EventContext = EventContext;
|
|
23
|
+
//# sourceMappingURL=event-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-context.js","sourceRoot":"","sources":["../../../../src/contexts/event-context.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAa,YAAY;CAmBxB;AAnBD,oCAmBC"}
|
|
@@ -9,6 +9,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.TracingContext = void 0;
|
|
10
10
|
require("reflect-metadata");
|
|
11
11
|
const tsyringe_1 = require("tsyringe");
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Read the trace id from the active `EventContext` instead:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import {EventContextManager} from "@pristine-ts/common";
|
|
17
|
+
*
|
|
18
|
+
* const traceId = EventContextManager.traceId();
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* `TracingContext` predates the `AsyncLocalStorage`-backed `EventContext` and survives
|
|
22
|
+
* only as a back-compat shim. `TracingManager.startTracing()` still mirrors the trace id
|
|
23
|
+
* into this class so existing consumers keep working, but new code should read from
|
|
24
|
+
* `EventContextManager`. This class will be removed in a future major.
|
|
25
|
+
*/
|
|
12
26
|
let TracingContext = class TracingContext {
|
|
13
27
|
};
|
|
14
28
|
exports.TracingContext = TracingContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.context.js","sourceRoot":"","sources":["../../../../src/contexts/tracing.context.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4BAA0B;AAC1B,uCAAuD;
|
|
1
|
+
{"version":3,"file":"tracing.context.js","sourceRoot":"","sources":["../../../../src/contexts/tracing.context.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4BAA0B;AAC1B,uCAAuD;AAEvD;;;;;;;;;;;;;GAaG;AAGI,IAAM,cAAc,GAApB,MAAM,cAAc;CAE1B,CAAA;AAFY,wCAAc;yBAAd,cAAc;IAF1B,IAAA,qBAAU,GAAE;IACZ,IAAA,iBAAM,EAAC,oBAAS,CAAC,eAAe,CAAC;GACrB,cAAc,CAE1B"}
|
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./inject-config.decorator"), exports);
|
|
18
18
|
__exportStar(require("./module-scoped.decorator"), exports);
|
|
19
19
|
__exportStar(require("./tag.decorator"), exports);
|
|
20
|
+
__exportStar(require("./traced.decorator"), exports);
|
|
20
21
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,4DAA0C;AAC1C,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,4DAA0C;AAC1C,kDAAgC;AAChC,qDAAmC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
* **Lives in `@pristine-ts/common`** so any package can use it without taking a direct
|
|
37
|
+
* dep on `@pristine-ts/telemetry`. The actual `TracingManager` implementation still
|
|
38
|
+
* lives in telemetry; this decorator only reads the active manager from the
|
|
39
|
+
* EventContext when one is present.
|
|
40
|
+
*
|
|
41
|
+
* @param spanName Optional explicit name for the span. Defaults to
|
|
42
|
+
* `${ClassName}.${methodName}`.
|
|
43
|
+
*/
|
|
44
|
+
function traced(spanName) {
|
|
45
|
+
return (target, propertyKey, descriptor) => {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
const original = descriptor.value;
|
|
48
|
+
if (typeof original !== "function") {
|
|
49
|
+
// Decorator was applied to something other than a method (a getter, a property
|
|
50
|
+
// with no initial value, etc.). Leave it alone — silently no-op rather than
|
|
51
|
+
// throw at decoration time.
|
|
52
|
+
return descriptor;
|
|
53
|
+
}
|
|
54
|
+
// Resolve a stable default name at decoration time. `target.constructor.name` is
|
|
55
|
+
// the class name for instance methods; for static methods, `target.name` is the
|
|
56
|
+
// class. We cover both via the fallback chain.
|
|
57
|
+
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";
|
|
58
|
+
const resolvedName = spanName !== null && spanName !== void 0 ? spanName : `${className}.${String(propertyKey)}`;
|
|
59
|
+
descriptor.value = function (...args) {
|
|
60
|
+
return span_runner_1.spanRunner.runWithSpan(resolvedName, () => original.apply(this, args));
|
|
61
|
+
};
|
|
62
|
+
return descriptor;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=traced.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/traced.decorator.ts"],"names":[],"mappings":";;AAyCA,wBAsBC;AA/DD,sDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;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"}
|
|
@@ -18,4 +18,5 @@ __exportStar(require("./http-method.enum"), exports);
|
|
|
18
18
|
__exportStar(require("./internal-container-parameter.enum"), exports);
|
|
19
19
|
__exportStar(require("./metadata.enum"), exports);
|
|
20
20
|
__exportStar(require("./service-definition-tag.enum"), exports);
|
|
21
|
+
__exportStar(require("./span-keyname.enum"), exports);
|
|
21
22
|
//# sourceMappingURL=enums.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../src/enums/enums.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sEAAoD;AACpD,kDAAgC;AAChC,gEAA8C"}
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../src/enums/enums.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sEAAoD;AACpD,kDAAgC;AAChC,gEAA8C;AAC9C,sDAAoC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpanKeynameEnum = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This enum is for the different span names that are integrated in Pristine.
|
|
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 = {}));
|
|
34
|
+
//# sourceMappingURL=span-keyname.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span-keyname.enum.js","sourceRoot":"","sources":["../../../../src/enums/span-keyname.enum.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,eAyBX;AAzBD,WAAY,eAAe;IACzB,sEAAmD,CAAA;IACnD,8EAA2D,CAAA;IAC3D,+EAA4D,CAAA;IAC5D,4EAAyD,CAAA;IACzD,wEAAqD,CAAA;IACrD,qDAAkC,CAAA;IAClC,+DAA4C,CAAA;IAC5C,iFAA8D,CAAA;IAC9D,mFAAgE,CAAA;IAChE,kGAA+E,CAAA;IAC/E,oGAAiF,CAAA;IACjF,iDAA8B,CAAA;IAC9B,iEAA8C,CAAA;IAC9C,iEAA8C,CAAA;IAC9C,6FAA0E,CAAA;IAC1E,yDAAsC,CAAA;IACtC,+DAA4C,CAAA;IAC5C,iEAA8C,CAAA;IAC9C,mDAAgC,CAAA;IAChC,0EAAuD,CAAA;IACvD,gFAA6D,CAAA;IAC7D,gFAA6D,CAAA;IAC7D,sEAAmD,CAAA;IACnD,+CAA4B,CAAA;AAC9B,CAAC,EAzBW,eAAe,+BAAf,eAAe,QAyB1B"}
|
|
@@ -25,5 +25,6 @@ __exportStar(require("./module-scoped-registration.interface"), exports);
|
|
|
25
25
|
__exportStar(require("./resolver.interface"), exports);
|
|
26
26
|
__exportStar(require("./tagged-registration.interface"), exports);
|
|
27
27
|
__exportStar(require("./token-provider-registration.interface"), exports);
|
|
28
|
+
__exportStar(require("./tracing-manager.interface"), exports);
|
|
28
29
|
__exportStar(require("./value-provider-registration.interface"), exports);
|
|
29
30
|
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,0EAAwD;AACxD,4DAA0C;AAC1C,6EAA2D;AAC3D,4EAA0D;AAC1D,uDAAqC;AACrC,qDAAmC;AACnC,yEAAuD;AACvD,uDAAqC;AACrC,kEAAgD;AAChD,0EAAwD;AACxD,0EAAwD"}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,0EAAwD;AACxD,4DAA0C;AAC1C,6EAA2D;AAC3D,4EAA0D;AAC1D,uDAAqC;AACrC,qDAAmC;AACnC,yEAAuD;AACvD,uDAAqC;AACrC,kEAAgD;AAChD,0EAAwD;AACxD,8DAA4C;AAC5C,0EAAwD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing-manager.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/tracing-manager.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,107 @@
|
|
|
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 EventContextManager_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EventContextManager = void 0;
|
|
11
|
+
const async_hooks_1 = require("async_hooks");
|
|
12
|
+
const tsyringe_1 = require("tsyringe");
|
|
13
|
+
/**
|
|
14
|
+
* Owns the `AsyncLocalStorage` instance that propagates the active `EventContext`
|
|
15
|
+
* across `await` boundaries, `Promise.all`, `setImmediate`, and the rest of Node's
|
|
16
|
+
* async machinery. Provides:
|
|
17
|
+
*
|
|
18
|
+
* - `run(ctx, fn)` — install the context for the duration of `fn`. **Framework-only**;
|
|
19
|
+
* normal application code never calls this. Pristine's event pipeline calls it once
|
|
20
|
+
* per event.
|
|
21
|
+
* - Read accessors — `current()`, `eventId()`, `traceId()`, `container()`. Available
|
|
22
|
+
* as instance methods (DI-resolved) and as static convenience methods.
|
|
23
|
+
* - `bind(fn)` — escape hatch for background work that breaks the natural async
|
|
24
|
+
* chain (raw `setImmediate`, `EventEmitter`-based code, certain native modules).
|
|
25
|
+
* Captures the current context and returns a wrapped function that restores it
|
|
26
|
+
* on call.
|
|
27
|
+
*
|
|
28
|
+
* Why static state inside an `@injectable()` class: the `AsyncLocalStorage` instance
|
|
29
|
+
* itself must be a single process-wide singleton — multiple instances would each track
|
|
30
|
+
* their own propagation chain and contexts wouldn't be visible across them. Making the
|
|
31
|
+
* ALS `private static readonly` while keeping the class `@injectable()` lets DI consumers
|
|
32
|
+
* resolve it normally (and substitute fakes in tests) while the underlying state stays
|
|
33
|
+
* shared and consistent.
|
|
34
|
+
*/
|
|
35
|
+
let EventContextManager = EventContextManager_1 = class EventContextManager {
|
|
36
|
+
run(ctx, fn) {
|
|
37
|
+
return EventContextManager_1.als.run(ctx, fn);
|
|
38
|
+
}
|
|
39
|
+
/** Returns the active `EventContext`, or `undefined` if no context is installed
|
|
40
|
+
* (i.e. we're outside any `run()` call). */
|
|
41
|
+
current() {
|
|
42
|
+
return EventContextManager_1.als.getStore();
|
|
43
|
+
}
|
|
44
|
+
/** Convenience: the `eventId` of the active context, or `undefined`. */
|
|
45
|
+
eventId() {
|
|
46
|
+
var _a;
|
|
47
|
+
return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.eventId;
|
|
48
|
+
}
|
|
49
|
+
/** Convenience: the `traceId` of the active context, or `undefined`. */
|
|
50
|
+
traceId() {
|
|
51
|
+
var _a;
|
|
52
|
+
return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.traceId;
|
|
53
|
+
}
|
|
54
|
+
/** Convenience: the per-event DI child container, or `undefined`. */
|
|
55
|
+
container() {
|
|
56
|
+
var _a;
|
|
57
|
+
return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.container;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns a wrapped version of `fn` that restores the current context on call. Use
|
|
61
|
+
* when you need to spawn work that escapes the natural async chain (e.g. a callback
|
|
62
|
+
* registered with a third-party `EventEmitter`, or a `setImmediate` whose callback
|
|
63
|
+
* runs after the parent function returned). Without `bind`, that work would see no
|
|
64
|
+
* context.
|
|
65
|
+
*
|
|
66
|
+
* If no context is active when `bind` is called, returns `fn` unchanged.
|
|
67
|
+
*/
|
|
68
|
+
bind(fn) {
|
|
69
|
+
const ctx = this.current();
|
|
70
|
+
if (ctx === undefined)
|
|
71
|
+
return fn;
|
|
72
|
+
const als = EventContextManager_1.als;
|
|
73
|
+
return ((...args) => als.run(ctx, () => fn(...args)));
|
|
74
|
+
}
|
|
75
|
+
// ── Static convenience mirrors. ────────────────────────────────────────────────
|
|
76
|
+
// For callers that don't want DI noise (e.g. utility code, decorators, helpers
|
|
77
|
+
// that don't have a constructor to inject through). All forwarding to the same
|
|
78
|
+
// shared ALS instance.
|
|
79
|
+
static current() {
|
|
80
|
+
return EventContextManager_1.als.getStore();
|
|
81
|
+
}
|
|
82
|
+
static eventId() {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = EventContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.eventId;
|
|
85
|
+
}
|
|
86
|
+
static traceId() {
|
|
87
|
+
var _a;
|
|
88
|
+
return (_a = EventContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.traceId;
|
|
89
|
+
}
|
|
90
|
+
static container() {
|
|
91
|
+
var _a;
|
|
92
|
+
return (_a = EventContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.container;
|
|
93
|
+
}
|
|
94
|
+
static bind(fn) {
|
|
95
|
+
const ctx = EventContextManager_1.current();
|
|
96
|
+
if (ctx === undefined)
|
|
97
|
+
return fn;
|
|
98
|
+
const als = EventContextManager_1.als;
|
|
99
|
+
return ((...args) => als.run(ctx, () => fn(...args)));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.EventContextManager = EventContextManager;
|
|
103
|
+
EventContextManager.als = new async_hooks_1.AsyncLocalStorage();
|
|
104
|
+
exports.EventContextManager = EventContextManager = EventContextManager_1 = __decorate([
|
|
105
|
+
(0, tsyringe_1.injectable)()
|
|
106
|
+
], EventContextManager);
|
|
107
|
+
//# sourceMappingURL=event-context.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-context.manager.js","sourceRoot":"","sources":["../../../../src/managers/event-context.manager.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,6CAA8C;AAC9C,uCAAyD;AAGzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAU9B,GAAG,CAAI,GAAiB,EAAE,EAAwB;QAChD,OAAO,qBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;iDAC6C;IAC7C,OAAO;QACL,OAAO,qBAAmB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IAED,wEAAwE;IACxE,OAAO;;QACL,OAAO,MAAA,IAAI,CAAC,OAAO,EAAE,0CAAE,OAAO,CAAC;IACjC,CAAC;IAED,wEAAwE;IACxE,OAAO;;QACL,OAAO,MAAA,IAAI,CAAC,OAAO,EAAE,0CAAE,OAAO,CAAC;IACjC,CAAC;IAED,qEAAqE;IACrE,SAAS;;QACP,OAAO,MAAA,IAAI,CAAC,OAAO,EAAE,0CAAE,SAAS,CAAC;IACnC,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,CAAoC,EAAK;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,qBAAmB,CAAC,GAAG,CAAC;QACpC,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;IACpE,CAAC;IAED,kFAAkF;IAClF,+EAA+E;IAC/E,+EAA+E;IAC/E,uBAAuB;IAEvB,MAAM,CAAC,OAAO;QACZ,OAAO,qBAAmB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,OAAO;;QACZ,OAAO,MAAA,qBAAmB,CAAC,OAAO,EAAE,0CAAE,OAAO,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,OAAO;;QACZ,OAAO,MAAA,qBAAmB,CAAC,OAAO,EAAE,0CAAE,OAAO,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,SAAS;;QACd,OAAO,MAAA,qBAAmB,CAAC,OAAO,EAAE,0CAAE,SAAS,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,IAAI,CAAoC,EAAK;QAClD,MAAM,GAAG,GAAG,qBAAmB,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,qBAAmB,CAAC,GAAG,CAAC;QACpC,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;IACpE,CAAC;;AA7EU,kDAAmB;AACN,uBAAG,GAAG,IAAI,+BAAiB,EAAgB,AAAxC,CAAyC;8BADzD,mBAAmB;IAD/B,IAAA,qBAAU,GAAE;GACA,mBAAmB,CA8E/B"}
|
|
@@ -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("./event-context.manager"), exports);
|
|
18
|
+
//# sourceMappingURL=managers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managers.js","sourceRoot":"","sources":["../../../../src/managers/managers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
|
|
@@ -16,4 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./request"), exports);
|
|
18
18
|
__exportStar(require("./response"), exports);
|
|
19
|
+
__exportStar(require("./span-event.model"), exports);
|
|
20
|
+
__exportStar(require("./span.model"), exports);
|
|
21
|
+
__exportStar(require("./trace.model"), exports);
|
|
19
22
|
//# sourceMappingURL=models.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/models/models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B"}
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/models/models.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,qDAAmC;AACnC,+CAA6B;AAC7B,gDAA8B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpanEvent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A named, timestamped marker attached to a `Span`. Represents a noteworthy moment
|
|
6
|
+
* inside the span's lifetime that doesn't warrant a child span of its own — e.g.
|
|
7
|
+
* "validation passed", "rate limit check ok", "found 50 rows in DB".
|
|
8
|
+
*
|
|
9
|
+
* Modeled after OpenTelemetry's "span events" concept: a `Span` carries `events: SpanEvent[]`
|
|
10
|
+
* alongside its `children: Span[]`. Renderers (the console/file tracer output, etc.) interleave
|
|
11
|
+
* events with spans by timestamp to produce a chronological trail of what happened during the span.
|
|
12
|
+
*
|
|
13
|
+
* Use `TracingManager.addEventToCurrentSpan(message, attributes?)` to add one — it finds
|
|
14
|
+
* the most-recently-started in-progress span and attaches the event there.
|
|
15
|
+
*/
|
|
16
|
+
class SpanEvent {
|
|
17
|
+
constructor(message, attributes) {
|
|
18
|
+
this.message = message;
|
|
19
|
+
/**
|
|
20
|
+
* The timestamp in milliseconds at which the event was created. Used to interleave
|
|
21
|
+
* events with sibling spans when rendering a sorted trail.
|
|
22
|
+
*/
|
|
23
|
+
this.timestamp = Date.now();
|
|
24
|
+
this.attributes = attributes;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SpanEvent = SpanEvent;
|
|
28
|
+
//# 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;;;;;;;;;;;GAWG;AACH,MAAa,SAAS;IAapB,YAA4B,OAAe,EAAE,UAAsC;QAAvD,YAAO,GAAP,OAAO,CAAQ;QAZ3C;;;WAGG;QACa,cAAS,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAS7C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAhBD,8BAgBC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Span = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
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
|
+
* Named, timestamped markers attached to this span. Use these for noteworthy moments
|
|
27
|
+
* inside the span's lifetime that don't warrant their own child span — e.g.
|
|
28
|
+
* "validation passed", "found 50 rows in DB". Empty by default; populated by
|
|
29
|
+
* `TracingManager.addEventToCurrentSpan(...)`.
|
|
30
|
+
*/
|
|
31
|
+
this.events = [];
|
|
32
|
+
/**
|
|
33
|
+
* The context associated with the span.
|
|
34
|
+
*/
|
|
35
|
+
this.context = {};
|
|
36
|
+
/**
|
|
37
|
+
* Whether or not the span is in progress, meaning it has not ended.
|
|
38
|
+
*/
|
|
39
|
+
this.inProgress = true;
|
|
40
|
+
this.id = id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)();
|
|
41
|
+
this.context = context !== null && context !== void 0 ? context : {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This method returns the duration of the span in milliseconds.
|
|
45
|
+
*/
|
|
46
|
+
getDuration() {
|
|
47
|
+
var _a;
|
|
48
|
+
return ((_a = this.endDate) !== null && _a !== void 0 ? _a : Date.now()) - this.startDate;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This method ends the span.
|
|
52
|
+
*/
|
|
53
|
+
end() {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = this.tracingManager) === null || _a === void 0 ? void 0 : _a.endSpan(this);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This method sets the trace for the span and all of its children.
|
|
59
|
+
* @param trace The trace the span should be attached to.
|
|
60
|
+
*/
|
|
61
|
+
setTrace(trace) {
|
|
62
|
+
this.trace = trace;
|
|
63
|
+
this.children.forEach(childSpan => childSpan.setTrace(trace));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* This method adds a child span to the current span. It only adds it if it's not already part of the children.
|
|
67
|
+
* @param span The span to add as a child.
|
|
68
|
+
*/
|
|
69
|
+
addChild(span) {
|
|
70
|
+
const existingChildSpan = this.children.find(childSpan => childSpan.id === span.id);
|
|
71
|
+
if (existingChildSpan) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
span.parentSpan = this;
|
|
75
|
+
this.children.push(span);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.Span = Span;
|
|
79
|
+
//# sourceMappingURL=span.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span.model.js","sourceRoot":"","sources":["../../../../src/models/span.model.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAclC;;GAEG;AACH,MAAa,IAAI;IAuDf;;;;;OAKG;IACH,YAA0B,OAAe,EAAE,EAAW,EAAE,OAAmC;QAAjE,YAAO,GAAP,OAAO,CAAQ;QA5CzC;;WAEG;QACI,cAAS,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAYtC;;WAEG;QACI,aAAQ,GAAW,EAAE,CAAC;QAE7B;;;;;WAKG;QACI,WAAM,GAAgB,EAAE,CAAC;QAEhC;;WAEG;QACI,YAAO,GAA8B,EAAE,CAAC;QAE/C;;WAEG;QACI,eAAU,GAAG,IAAI,CAAC;QASvB,IAAI,CAAC,EAAE,GAAG,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,IAAA,mBAAU,GAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,WAAW;;QAChB,OAAO,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;IACvD,CAAC;IAED;;OAEG;IACI,GAAG;;QACR,MAAA,IAAI,CAAC,cAAc,0CAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,KAAY;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,IAAU;QACxB,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC;QAEpF,IAAI,iBAAiB,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF;AAxGD,oBAwGC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trace = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
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
|
+
* Index of all spans in this trace by keyname, populated by `TracingManager.addSpan`.
|
|
21
|
+
* Lives on the Trace (not on a particular TracingManager instance) so any TracingManager
|
|
22
|
+
* reading the active trace through `EventContext.trace` sees the same index — required
|
|
23
|
+
* for cross-container span lookup (kernel-resolved manager vs per-event resolved manager).
|
|
24
|
+
*/
|
|
25
|
+
this.spansByKeyname = {};
|
|
26
|
+
/**
|
|
27
|
+
* The context associated with the trace.
|
|
28
|
+
*/
|
|
29
|
+
this.context = {};
|
|
30
|
+
/**
|
|
31
|
+
* Whether or not the trace was ended.
|
|
32
|
+
*/
|
|
33
|
+
this.hasEnded = false;
|
|
34
|
+
this.id = id !== null && id !== void 0 ? id : (0, crypto_1.randomUUID)();
|
|
35
|
+
this.context = context !== null && context !== void 0 ? context : {};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* This returns the duration of the trace in miliseconds.
|
|
39
|
+
*/
|
|
40
|
+
getDuration() {
|
|
41
|
+
var _a;
|
|
42
|
+
return ((_a = this.endDate) !== null && _a !== void 0 ? _a : Date.now()) - this.startDate;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Trace = Trace;
|
|
46
|
+
//# sourceMappingURL=trace.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.model.js","sourceRoot":"","sources":["../../../../src/models/trace.model.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAGlC;;GAEG;AACH,MAAa,KAAK;IAuChB;;;;OAIG;IACH,YAAmB,EAAW,EAAE,OAAmC;QAtCnE;;WAEG;QACI,cAAS,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAYtC;;;;;WAKG;QACI,mBAAc,GAAkC,EAAE,CAAC;QAE1D;;WAEG;QACI,YAAO,GAA+B,EAAE,CAAC;QAEhD;;WAEG;QACI,aAAQ,GAAY,KAAK,CAAC;QAQ/B,IAAI,CAAC,EAAE,GAAG,EAAE,aAAF,EAAE,cAAF,EAAE,GAAI,IAAA,mBAAU,GAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,WAAW;;QAChB,OAAO,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;IACvD,CAAC;CACF;AAvDD,sBAuDC"}
|