@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.
Files changed (93) hide show
  1. package/dist/lib/cjs/common.module.js +1 -0
  2. package/dist/lib/cjs/common.module.js.map +1 -1
  3. package/dist/lib/cjs/contexts/contexts.js +1 -0
  4. package/dist/lib/cjs/contexts/contexts.js.map +1 -1
  5. package/dist/lib/cjs/contexts/event-context.js +23 -0
  6. package/dist/lib/cjs/contexts/event-context.js.map +1 -0
  7. package/dist/lib/cjs/contexts/tracing.context.js +14 -0
  8. package/dist/lib/cjs/contexts/tracing.context.js.map +1 -1
  9. package/dist/lib/cjs/decorators/decorators.js +1 -0
  10. package/dist/lib/cjs/decorators/decorators.js.map +1 -1
  11. package/dist/lib/cjs/decorators/traced.decorator.js +65 -0
  12. package/dist/lib/cjs/decorators/traced.decorator.js.map +1 -0
  13. package/dist/lib/cjs/enums/enums.js +1 -0
  14. package/dist/lib/cjs/enums/enums.js.map +1 -1
  15. package/dist/lib/cjs/enums/span-keyname.enum.js +34 -0
  16. package/dist/lib/cjs/enums/span-keyname.enum.js.map +1 -0
  17. package/dist/lib/cjs/interfaces/interfaces.js +1 -0
  18. package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
  19. package/dist/lib/cjs/interfaces/tracing-manager.interface.js +3 -0
  20. package/dist/lib/cjs/interfaces/tracing-manager.interface.js.map +1 -0
  21. package/dist/lib/cjs/managers/event-context.manager.js +107 -0
  22. package/dist/lib/cjs/managers/event-context.manager.js.map +1 -0
  23. package/dist/lib/cjs/managers/managers.js +18 -0
  24. package/dist/lib/cjs/managers/managers.js.map +1 -0
  25. package/dist/lib/cjs/models/models.js +3 -0
  26. package/dist/lib/cjs/models/models.js.map +1 -1
  27. package/dist/lib/cjs/models/span-event.model.js +28 -0
  28. package/dist/lib/cjs/models/span-event.model.js.map +1 -0
  29. package/dist/lib/cjs/models/span.model.js +79 -0
  30. package/dist/lib/cjs/models/span.model.js.map +1 -0
  31. package/dist/lib/cjs/models/trace.model.js +46 -0
  32. package/dist/lib/cjs/models/trace.model.js.map +1 -0
  33. package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  34. package/dist/lib/cjs/utils/span-runner.js +117 -0
  35. package/dist/lib/cjs/utils/span-runner.js.map +1 -0
  36. package/dist/lib/cjs/utils/utils.js +1 -0
  37. package/dist/lib/cjs/utils/utils.js.map +1 -1
  38. package/dist/lib/esm/common.module.js +1 -0
  39. package/dist/lib/esm/common.module.js.map +1 -1
  40. package/dist/lib/esm/contexts/contexts.js +1 -0
  41. package/dist/lib/esm/contexts/contexts.js.map +1 -1
  42. package/dist/lib/esm/contexts/event-context.js +19 -0
  43. package/dist/lib/esm/contexts/event-context.js.map +1 -0
  44. package/dist/lib/esm/contexts/tracing.context.js +14 -0
  45. package/dist/lib/esm/contexts/tracing.context.js.map +1 -1
  46. package/dist/lib/esm/decorators/decorators.js +1 -0
  47. package/dist/lib/esm/decorators/decorators.js.map +1 -1
  48. package/dist/lib/esm/decorators/traced.decorator.js +62 -0
  49. package/dist/lib/esm/decorators/traced.decorator.js.map +1 -0
  50. package/dist/lib/esm/enums/enums.js +1 -0
  51. package/dist/lib/esm/enums/enums.js.map +1 -1
  52. package/dist/lib/esm/enums/span-keyname.enum.js +31 -0
  53. package/dist/lib/esm/enums/span-keyname.enum.js.map +1 -0
  54. package/dist/lib/esm/interfaces/interfaces.js +1 -0
  55. package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
  56. package/dist/lib/esm/interfaces/tracing-manager.interface.js +2 -0
  57. package/dist/lib/esm/interfaces/tracing-manager.interface.js.map +1 -0
  58. package/dist/lib/esm/managers/event-context.manager.js +104 -0
  59. package/dist/lib/esm/managers/event-context.manager.js.map +1 -0
  60. package/dist/lib/esm/managers/managers.js +2 -0
  61. package/dist/lib/esm/managers/managers.js.map +1 -0
  62. package/dist/lib/esm/models/models.js +3 -0
  63. package/dist/lib/esm/models/models.js.map +1 -1
  64. package/dist/lib/esm/models/span-event.model.js +24 -0
  65. package/dist/lib/esm/models/span-event.model.js.map +1 -0
  66. package/dist/lib/esm/models/span.model.js +75 -0
  67. package/dist/lib/esm/models/span.model.js.map +1 -0
  68. package/dist/lib/esm/models/trace.model.js +42 -0
  69. package/dist/lib/esm/models/trace.model.js.map +1 -0
  70. package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
  71. package/dist/lib/esm/utils/span-runner.js +113 -0
  72. package/dist/lib/esm/utils/span-runner.js.map +1 -0
  73. package/dist/lib/esm/utils/utils.js +1 -0
  74. package/dist/lib/esm/utils/utils.js.map +1 -1
  75. package/dist/types/common.module.d.ts +1 -0
  76. package/dist/types/contexts/contexts.d.ts +1 -0
  77. package/dist/types/contexts/event-context.d.ts +35 -0
  78. package/dist/types/contexts/tracing.context.d.ts +14 -0
  79. package/dist/types/decorators/decorators.d.ts +1 -0
  80. package/dist/types/decorators/traced.decorator.d.ts +40 -0
  81. package/dist/types/enums/enums.d.ts +1 -0
  82. package/dist/types/enums/span-keyname.enum.d.ts +29 -0
  83. package/dist/types/interfaces/interfaces.d.ts +1 -0
  84. package/dist/types/interfaces/tracing-manager.interface.d.ts +78 -0
  85. package/dist/types/managers/event-context.manager.d.ts +58 -0
  86. package/dist/types/managers/managers.d.ts +1 -0
  87. package/dist/types/models/models.d.ts +3 -0
  88. package/dist/types/models/span-event.model.d.ts +30 -0
  89. package/dist/types/models/span.model.d.ts +90 -0
  90. package/dist/types/models/trace.model.d.ts +53 -0
  91. package/dist/types/utils/span-runner.d.ts +55 -0
  92. package/dist/types/utils/utils.d.ts +1 -0
  93. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../../../src/contexts/contexts.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../../../src/contexts/contexts.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Per-event runtime state — the framework's correlation primitives plus a handle to
3
+ * the per-event DI child container and the active trace. Propagated implicitly via
4
+ * `AsyncLocalStorage` (managed by `EventContextManager`) so downstream code doesn't
5
+ * have to thread these fields through every method signature.
6
+ *
7
+ * **Not to be confused with `ExecutionContextInterface` (in `@pristine-ts/core`):**
8
+ * - `ExecutionContext` describes *where* the framework is running (AWS Lambda, CLI,
9
+ * Express, etc.) — set once per `kernel.handle()` call, immutable, host-shaped.
10
+ * - `EventContext` describes *which specific event* is being handled — set per event
11
+ * in the pipeline, mutable (`traceId` / `trace` fill in once tracing starts),
12
+ * correlation-shaped.
13
+ *
14
+ * One `kernel.handle()` call can produce multiple events (each event mapper can return
15
+ * a list); each event gets its own `EventContext` instance.
16
+ */
17
+ export class EventContext {
18
+ }
19
+ //# 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,MAAM,OAAO,YAAY;CAmBxB"}
@@ -6,6 +6,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import "reflect-metadata";
8
8
  import { injectable, Lifecycle, scoped } from "tsyringe";
9
+ /**
10
+ * @deprecated Read the trace id from the active `EventContext` instead:
11
+ *
12
+ * ```ts
13
+ * import {EventContextManager} from "@pristine-ts/common";
14
+ *
15
+ * const traceId = EventContextManager.traceId();
16
+ * ```
17
+ *
18
+ * `TracingContext` predates the `AsyncLocalStorage`-backed `EventContext` and survives
19
+ * only as a back-compat shim. `TracingManager.startTracing()` still mirrors the trace id
20
+ * into this class so existing consumers keep working, but new code should read from
21
+ * `EventContextManager`. This class will be removed in a future major.
22
+ */
9
23
  let TracingContext = class TracingContext {
10
24
  };
11
25
  TracingContext = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"tracing.context.js","sourceRoot":"","sources":["../../../../src/contexts/tracing.context.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAIhD,IAAM,cAAc,GAApB,MAAM,cAAc;CAE1B,CAAA;AAFY,cAAc;IAF1B,UAAU,EAAE;IACZ,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;GACrB,cAAc,CAE1B"}
1
+ {"version":3,"file":"tracing.context.js","sourceRoot":"","sources":["../../../../src/contexts/tracing.context.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AAGI,IAAM,cAAc,GAApB,MAAM,cAAc;CAE1B,CAAA;AAFY,cAAc;IAF1B,UAAU,EAAE;IACZ,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;GACrB,cAAc,CAE1B"}
@@ -1,4 +1,5 @@
1
1
  export * from './inject-config.decorator';
2
2
  export * from './module-scoped.decorator';
3
3
  export * from './tag.decorator';
4
+ export * from './traced.decorator';
4
5
  //# sourceMappingURL=decorators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { spanRunner } from "../utils/span-runner";
2
+ /**
3
+ * Method decorator that wraps the decorated method in a span. The span is automatically
4
+ * ended when the method returns or throws, and the `TracingManager` is auto-resolved
5
+ * from the active `EventContext` — no need to inject it manually.
6
+ *
7
+ * ```ts
8
+ * class PaymentService {
9
+ * @traced() // span name = "PaymentService.charge"
10
+ * async charge(amount: number) { ... }
11
+ *
12
+ * @traced("payment.refund.action") // explicit name
13
+ * async refund(chargeId: string) { ... }
14
+ * }
15
+ * ```
16
+ *
17
+ * **Behavior outside an event context.** When the decorated method runs without an
18
+ * active `EventContext` (e.g. a unit test calling the method directly, or background
19
+ * work that escaped the event lifecycle), the decorator is a no-op — the original
20
+ * method runs unchanged. Tracing must never throw or alter semantics.
21
+ *
22
+ * **Sync methods become async.** The decorator awaits the wrapped method internally,
23
+ * so any decorated method returns a `Promise`. Decorating a sync method changes its
24
+ * signature visible to callers — apply `@traced` to methods you'd already be awaiting
25
+ * (DB calls, HTTP, expensive computations), not to tight sync helpers.
26
+ *
27
+ * **Type-level caveat.** TypeScript's parameter and method decorator types don't carry
28
+ * enough information for the compiler to verify that the wrapped method's return type
29
+ * is compatible with `Promise<T>`. The wrapper is type-safe at runtime; the call site's
30
+ * static types are unchanged. Pair with explicit `: Promise<T>` annotations on the
31
+ * method when you want the static type to match what's actually returned.
32
+ *
33
+ * **Lives in `@pristine-ts/common`** so any package can use it without taking a direct
34
+ * dep on `@pristine-ts/telemetry`. The actual `TracingManager` implementation still
35
+ * lives in telemetry; this decorator only reads the active manager from the
36
+ * EventContext when one is present.
37
+ *
38
+ * @param spanName Optional explicit name for the span. Defaults to
39
+ * `${ClassName}.${methodName}`.
40
+ */
41
+ export function traced(spanName) {
42
+ return (target, propertyKey, descriptor) => {
43
+ var _a, _b, _c;
44
+ const original = descriptor.value;
45
+ if (typeof original !== "function") {
46
+ // Decorator was applied to something other than a method (a getter, a property
47
+ // with no initial value, etc.). Leave it alone — silently no-op rather than
48
+ // throw at decoration time.
49
+ return descriptor;
50
+ }
51
+ // Resolve a stable default name at decoration time. `target.constructor.name` is
52
+ // the class name for instance methods; for static methods, `target.name` is the
53
+ // class. We cover both via the fallback chain.
54
+ 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";
55
+ const resolvedName = spanName !== null && spanName !== void 0 ? spanName : `${className}.${String(propertyKey)}`;
56
+ descriptor.value = function (...args) {
57
+ return spanRunner.runWithSpan(resolvedName, () => original.apply(this, args));
58
+ };
59
+ return descriptor;
60
+ };
61
+ }
62
+ //# sourceMappingURL=traced.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/traced.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,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,UAAU,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"}
@@ -2,4 +2,5 @@ export * from "./http-method.enum";
2
2
  export * from "./internal-container-parameter.enum";
3
3
  export * from "./metadata.enum";
4
4
  export * from "./service-definition-tag.enum";
5
+ export * from "./span-keyname.enum";
5
6
  //# sourceMappingURL=enums.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../src/enums/enums.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../src/enums/enums.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * This enum is for the different span names that are integrated in Pristine.
3
+ */
4
+ export var SpanKeynameEnum;
5
+ (function (SpanKeynameEnum) {
6
+ SpanKeynameEnum["ChildContainerCreation"] = "child.container.creation";
7
+ SpanKeynameEnum["ChildContainerRegistration"] = "child.container.registration";
8
+ SpanKeynameEnum["ConfigurationInitialization"] = "configuration.initialization";
9
+ SpanKeynameEnum["ErrorResponseInterceptors"] = "error.response.interceptors";
10
+ SpanKeynameEnum["EventDispatcherResolver"] = "event.dispatcher.resolver";
11
+ SpanKeynameEnum["EventExecution"] = "event.execution";
12
+ SpanKeynameEnum["EventInitialization"] = "event.initialization";
13
+ SpanKeynameEnum["EventPreMappingInterception"] = "event.pre-mapping.interception";
14
+ SpanKeynameEnum["EventPostMappingInterception"] = "event.post-mapping.interception";
15
+ SpanKeynameEnum["EventPreResponseMappingInterception"] = "event.pre-response-mapping.interception";
16
+ SpanKeynameEnum["EventPostResponseMappingInterception"] = "event.post-response-mapping.interception";
17
+ SpanKeynameEnum["EventMapping"] = "event.mapping";
18
+ SpanKeynameEnum["KernelInitialization"] = "kernel.initialization";
19
+ SpanKeynameEnum["ModuleInitialization"] = "module.initialization";
20
+ SpanKeynameEnum["ModuleInitializationImportModules"] = "module.initialization.import.modules";
21
+ SpanKeynameEnum["RequestExecution"] = "request.execution";
22
+ SpanKeynameEnum["RequestInterceptors"] = "request.interceptors";
23
+ SpanKeynameEnum["ResponseInterceptors"] = "response.interceptors";
24
+ SpanKeynameEnum["RootExecution"] = "root.execution";
25
+ SpanKeynameEnum["RouterControllerResolver"] = "router.controller.resolver";
26
+ SpanKeynameEnum["RouterFindMethodRouterNode"] = "router.find.method.router.node";
27
+ SpanKeynameEnum["RouterRequestAuthentication"] = "router.request.authentication";
28
+ SpanKeynameEnum["RouterRequestExecution"] = "router.request.execution";
29
+ SpanKeynameEnum["RouterSetup"] = "router.setup";
30
+ })(SpanKeynameEnum || (SpanKeynameEnum = {}));
31
+ //# 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,MAAM,CAAN,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,KAAf,eAAe,QAyB1B"}
@@ -9,5 +9,6 @@ export * from "./module-scoped-registration.interface";
9
9
  export * from "./resolver.interface";
10
10
  export * from "./tagged-registration.interface";
11
11
  export * from "./token-provider-registration.interface";
12
+ export * from "./tracing-manager.interface";
12
13
  export * from "./value-provider-registration.interface";
13
14
  //# sourceMappingURL=interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wCAAwC,CAAC;AACvD,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,yCAAyC,CAAC"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wCAAwC,CAAC;AACvD,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tracing-manager.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-manager.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/tracing-manager.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,104 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var EventContextManager_1;
8
+ import { AsyncLocalStorage } from "async_hooks";
9
+ import { injectable } from "tsyringe";
10
+ /**
11
+ * Owns the `AsyncLocalStorage` instance that propagates the active `EventContext`
12
+ * across `await` boundaries, `Promise.all`, `setImmediate`, and the rest of Node's
13
+ * async machinery. Provides:
14
+ *
15
+ * - `run(ctx, fn)` — install the context for the duration of `fn`. **Framework-only**;
16
+ * normal application code never calls this. Pristine's event pipeline calls it once
17
+ * per event.
18
+ * - Read accessors — `current()`, `eventId()`, `traceId()`, `container()`. Available
19
+ * as instance methods (DI-resolved) and as static convenience methods.
20
+ * - `bind(fn)` — escape hatch for background work that breaks the natural async
21
+ * chain (raw `setImmediate`, `EventEmitter`-based code, certain native modules).
22
+ * Captures the current context and returns a wrapped function that restores it
23
+ * on call.
24
+ *
25
+ * Why static state inside an `@injectable()` class: the `AsyncLocalStorage` instance
26
+ * itself must be a single process-wide singleton — multiple instances would each track
27
+ * their own propagation chain and contexts wouldn't be visible across them. Making the
28
+ * ALS `private static readonly` while keeping the class `@injectable()` lets DI consumers
29
+ * resolve it normally (and substitute fakes in tests) while the underlying state stays
30
+ * shared and consistent.
31
+ */
32
+ let EventContextManager = EventContextManager_1 = class EventContextManager {
33
+ run(ctx, fn) {
34
+ return EventContextManager_1.als.run(ctx, fn);
35
+ }
36
+ /** Returns the active `EventContext`, or `undefined` if no context is installed
37
+ * (i.e. we're outside any `run()` call). */
38
+ current() {
39
+ return EventContextManager_1.als.getStore();
40
+ }
41
+ /** Convenience: the `eventId` of the active context, or `undefined`. */
42
+ eventId() {
43
+ var _a;
44
+ return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.eventId;
45
+ }
46
+ /** Convenience: the `traceId` of the active context, or `undefined`. */
47
+ traceId() {
48
+ var _a;
49
+ return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.traceId;
50
+ }
51
+ /** Convenience: the per-event DI child container, or `undefined`. */
52
+ container() {
53
+ var _a;
54
+ return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.container;
55
+ }
56
+ /**
57
+ * Returns a wrapped version of `fn` that restores the current context on call. Use
58
+ * when you need to spawn work that escapes the natural async chain (e.g. a callback
59
+ * registered with a third-party `EventEmitter`, or a `setImmediate` whose callback
60
+ * runs after the parent function returned). Without `bind`, that work would see no
61
+ * context.
62
+ *
63
+ * If no context is active when `bind` is called, returns `fn` unchanged.
64
+ */
65
+ bind(fn) {
66
+ const ctx = this.current();
67
+ if (ctx === undefined)
68
+ return fn;
69
+ const als = EventContextManager_1.als;
70
+ return ((...args) => als.run(ctx, () => fn(...args)));
71
+ }
72
+ // ── Static convenience mirrors. ────────────────────────────────────────────────
73
+ // For callers that don't want DI noise (e.g. utility code, decorators, helpers
74
+ // that don't have a constructor to inject through). All forwarding to the same
75
+ // shared ALS instance.
76
+ static current() {
77
+ return EventContextManager_1.als.getStore();
78
+ }
79
+ static eventId() {
80
+ var _a;
81
+ return (_a = EventContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.eventId;
82
+ }
83
+ static traceId() {
84
+ var _a;
85
+ return (_a = EventContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.traceId;
86
+ }
87
+ static container() {
88
+ var _a;
89
+ return (_a = EventContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.container;
90
+ }
91
+ static bind(fn) {
92
+ const ctx = EventContextManager_1.current();
93
+ if (ctx === undefined)
94
+ return fn;
95
+ const als = EventContextManager_1.als;
96
+ return ((...args) => als.run(ctx, () => fn(...args)));
97
+ }
98
+ };
99
+ EventContextManager.als = new AsyncLocalStorage();
100
+ EventContextManager = EventContextManager_1 = __decorate([
101
+ injectable()
102
+ ], EventContextManager);
103
+ export { EventContextManager };
104
+ //# 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,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAsB,UAAU,EAAC,MAAM,UAAU,CAAC;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;;AA5EuB,uBAAG,GAAG,IAAI,iBAAiB,EAAgB,AAAxC,CAAyC;AADzD,mBAAmB;IAD/B,UAAU,EAAE;GACA,mBAAmB,CA8E/B"}
@@ -0,0 +1,2 @@
1
+ export * from "./event-context.manager";
2
+ //# sourceMappingURL=managers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managers.js","sourceRoot":"","sources":["../../../../src/managers/managers.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -1,3 +1,6 @@
1
1
  export * from "./request";
2
2
  export * from "./response";
3
+ export * from "./span-event.model";
4
+ export * from "./span.model";
5
+ export * from "./trace.model";
3
6
  //# sourceMappingURL=models.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/models/models.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/models/models.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A named, timestamped marker attached to a `Span`. Represents a noteworthy moment
3
+ * inside the span's lifetime that doesn't warrant a child span of its own — e.g.
4
+ * "validation passed", "rate limit check ok", "found 50 rows in DB".
5
+ *
6
+ * Modeled after OpenTelemetry's "span events" concept: a `Span` carries `events: SpanEvent[]`
7
+ * alongside its `children: Span[]`. Renderers (the console/file tracer output, etc.) interleave
8
+ * events with spans by timestamp to produce a chronological trail of what happened during the span.
9
+ *
10
+ * Use `TracingManager.addEventToCurrentSpan(message, attributes?)` to add one — it finds
11
+ * the most-recently-started in-progress span and attaches the event there.
12
+ */
13
+ export class SpanEvent {
14
+ constructor(message, attributes) {
15
+ this.message = message;
16
+ /**
17
+ * The timestamp in milliseconds at which the event was created. Used to interleave
18
+ * events with sibling spans when rendering a sorted trail.
19
+ */
20
+ this.timestamp = Date.now();
21
+ this.attributes = attributes;
22
+ }
23
+ }
24
+ //# 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,MAAM,OAAO,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"}
@@ -0,0 +1,75 @@
1
+ import { randomUUID } from "crypto";
2
+ /**
3
+ * This model represents a span.
4
+ */
5
+ export class Span {
6
+ /**
7
+ * This model represents a span.
8
+ * @param keyname The keyname of the span.
9
+ * @param id The unique id of the span.
10
+ * @param context The context to associate with the span.
11
+ */
12
+ constructor(keyname, id, context) {
13
+ this.keyname = keyname;
14
+ /**
15
+ * The timestamp in milliseconds at which the span was started.
16
+ */
17
+ this.startDate = Date.now();
18
+ /**
19
+ * The children spans.
20
+ */
21
+ this.children = [];
22
+ /**
23
+ * Named, timestamped markers attached to this span. Use these for noteworthy moments
24
+ * inside the span's lifetime that don't warrant their own child span — e.g.
25
+ * "validation passed", "found 50 rows in DB". Empty by default; populated by
26
+ * `TracingManager.addEventToCurrentSpan(...)`.
27
+ */
28
+ this.events = [];
29
+ /**
30
+ * The context associated with the span.
31
+ */
32
+ this.context = {};
33
+ /**
34
+ * Whether or not the span is in progress, meaning it has not ended.
35
+ */
36
+ this.inProgress = true;
37
+ this.id = id !== null && id !== void 0 ? id : randomUUID();
38
+ this.context = context !== null && context !== void 0 ? context : {};
39
+ }
40
+ /**
41
+ * This method returns the duration of the span in milliseconds.
42
+ */
43
+ getDuration() {
44
+ var _a;
45
+ return ((_a = this.endDate) !== null && _a !== void 0 ? _a : Date.now()) - this.startDate;
46
+ }
47
+ /**
48
+ * This method ends the span.
49
+ */
50
+ end() {
51
+ var _a;
52
+ (_a = this.tracingManager) === null || _a === void 0 ? void 0 : _a.endSpan(this);
53
+ }
54
+ /**
55
+ * This method sets the trace for the span and all of its children.
56
+ * @param trace The trace the span should be attached to.
57
+ */
58
+ setTrace(trace) {
59
+ this.trace = trace;
60
+ this.children.forEach(childSpan => childSpan.setTrace(trace));
61
+ }
62
+ /**
63
+ * This method adds a child span to the current span. It only adds it if it's not already part of the children.
64
+ * @param span The span to add as a child.
65
+ */
66
+ addChild(span) {
67
+ const existingChildSpan = this.children.find(childSpan => childSpan.id === span.id);
68
+ if (existingChildSpan) {
69
+ return;
70
+ }
71
+ span.parentSpan = this;
72
+ this.children.push(span);
73
+ }
74
+ }
75
+ //# 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,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAC;AAclC;;GAEG;AACH,MAAM,OAAO,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,UAAU,EAAE,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"}
@@ -0,0 +1,42 @@
1
+ import { randomUUID } from "crypto";
2
+ /**
3
+ * This model represents a trace.
4
+ */
5
+ export class Trace {
6
+ /**
7
+ * This model represents a trace.
8
+ * @param id The unique id of the trace.
9
+ * @param context The context associated with the trace.
10
+ */
11
+ constructor(id, context) {
12
+ /**
13
+ * The timestamp in milliseconds at which the trace was started.
14
+ */
15
+ this.startDate = Date.now();
16
+ /**
17
+ * Index of all spans in this trace by keyname, populated by `TracingManager.addSpan`.
18
+ * Lives on the Trace (not on a particular TracingManager instance) so any TracingManager
19
+ * reading the active trace through `EventContext.trace` sees the same index — required
20
+ * for cross-container span lookup (kernel-resolved manager vs per-event resolved manager).
21
+ */
22
+ this.spansByKeyname = {};
23
+ /**
24
+ * The context associated with the trace.
25
+ */
26
+ this.context = {};
27
+ /**
28
+ * Whether or not the trace was ended.
29
+ */
30
+ this.hasEnded = false;
31
+ this.id = id !== null && id !== void 0 ? id : randomUUID();
32
+ this.context = context !== null && context !== void 0 ? context : {};
33
+ }
34
+ /**
35
+ * This returns the duration of the trace in miliseconds.
36
+ */
37
+ getDuration() {
38
+ var _a;
39
+ return ((_a = this.endDate) !== null && _a !== void 0 ? _a : Date.now()) - this.startDate;
40
+ }
41
+ }
42
+ //# 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,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAC;AAGlC;;GAEG;AACH,MAAM,OAAO,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,UAAU,EAAE,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"}