@pristine-ts/telemetry 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/lib/cjs/enums/span-keyname.enum.js +2 -30
  2. package/dist/lib/cjs/enums/span-keyname.enum.js.map +1 -1
  3. package/dist/lib/cjs/managers/tracing.manager.js +171 -42
  4. package/dist/lib/cjs/managers/tracing.manager.js.map +1 -1
  5. package/dist/lib/cjs/models/models.js +1 -0
  6. package/dist/lib/cjs/models/models.js.map +1 -1
  7. package/dist/lib/cjs/models/span-event.model.js +6 -0
  8. package/dist/lib/cjs/models/span-event.model.js.map +1 -0
  9. package/dist/lib/cjs/models/span.model.js +2 -68
  10. package/dist/lib/cjs/models/span.model.js.map +1 -1
  11. package/dist/lib/cjs/models/trace.model.js +2 -35
  12. package/dist/lib/cjs/models/trace.model.js.map +1 -1
  13. package/dist/lib/cjs/telemetry.module.js +0 -1
  14. package/dist/lib/cjs/telemetry.module.js.map +1 -1
  15. package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  16. package/dist/lib/cjs/utils/utils.js +0 -1
  17. package/dist/lib/cjs/utils/utils.js.map +1 -1
  18. package/dist/lib/esm/enums/span-keyname.enum.js +1 -30
  19. package/dist/lib/esm/enums/span-keyname.enum.js.map +1 -1
  20. package/dist/lib/esm/managers/tracing.manager.js +171 -42
  21. package/dist/lib/esm/managers/tracing.manager.js.map +1 -1
  22. package/dist/lib/esm/models/models.js +1 -0
  23. package/dist/lib/esm/models/models.js.map +1 -1
  24. package/dist/lib/esm/models/span-event.model.js +2 -0
  25. package/dist/lib/esm/models/span-event.model.js.map +1 -0
  26. package/dist/lib/esm/models/span.model.js +1 -67
  27. package/dist/lib/esm/models/span.model.js.map +1 -1
  28. package/dist/lib/esm/models/trace.model.js +1 -34
  29. package/dist/lib/esm/models/trace.model.js.map +1 -1
  30. package/dist/lib/esm/telemetry.module.js +0 -1
  31. package/dist/lib/esm/telemetry.module.js.map +1 -1
  32. package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
  33. package/dist/lib/esm/utils/utils.js +0 -1
  34. package/dist/lib/esm/utils/utils.js.map +1 -1
  35. package/dist/types/enums/span-keyname.enum.d.ts +1 -29
  36. package/dist/types/interfaces/tracing-manager.interface.d.ts +1 -50
  37. package/dist/types/managers/tracing.manager.d.ts +71 -13
  38. package/dist/types/models/models.d.ts +1 -0
  39. package/dist/types/models/span-event.model.d.ts +1 -0
  40. package/dist/types/models/span.model.d.ts +1 -73
  41. package/dist/types/models/trace.model.d.ts +1 -44
  42. package/dist/types/telemetry.module.d.ts +0 -1
  43. package/dist/types/utils/utils.d.ts +0 -1
  44. package/package.json +4 -4
  45. package/dist/lib/cjs/decorators/decorators.js +0 -18
  46. package/dist/lib/cjs/decorators/decorators.js.map +0 -1
  47. package/dist/lib/cjs/decorators/traced.decorator.js +0 -60
  48. package/dist/lib/cjs/decorators/traced.decorator.js.map +0 -1
  49. package/dist/lib/cjs/utils/span-runner.js +0 -112
  50. package/dist/lib/cjs/utils/span-runner.js.map +0 -1
  51. package/dist/lib/esm/decorators/decorators.js +0 -2
  52. package/dist/lib/esm/decorators/decorators.js.map +0 -1
  53. package/dist/lib/esm/decorators/traced.decorator.js +0 -57
  54. package/dist/lib/esm/decorators/traced.decorator.js.map +0 -1
  55. package/dist/lib/esm/utils/span-runner.js +0 -108
  56. package/dist/lib/esm/utils/span-runner.js.map +0 -1
  57. package/dist/types/decorators/decorators.d.ts +0 -1
  58. package/dist/types/decorators/traced.decorator.d.ts +0 -35
  59. package/dist/types/utils/span-runner.d.ts +0 -55
@@ -1,108 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { EventContextManager } from "@pristine-ts/common";
11
- /**
12
- * Runs a function inside a span that is automatically ended when the function returns
13
- * or throws.
14
- *
15
- * Two call shapes are supported:
16
- *
17
- * **Explicit form** (`runWithSpan(tracingManager, name, fn)`) — pass the manager you've
18
- * already injected. Works anywhere, including outside an event context. Use this when
19
- * you have a `TracingManager` reference in hand:
20
- *
21
- * ```ts
22
- * return spanRunner.runWithSpan(this.tracingManager, "payment.charge",
23
- * () => this.client.charge(amount));
24
- * ```
25
- *
26
- * **ALS form** (`runWithSpan(name, fn)`) — auto-resolves the `TracingManager` from the
27
- * active `EventContext`'s container. Concise; works when called from anywhere inside
28
- * a Pristine event (controller, service, etc.) without needing the manager threaded
29
- * through:
30
- *
31
- * ```ts
32
- * return spanRunner.runWithSpan("payment.charge", () => this.client.charge(amount));
33
- * ```
34
- *
35
- * If the ALS form is used outside any `EventContext` (e.g. a unit test that doesn't
36
- * boot a kernel), no span is created and `fn` runs unchanged — same no-throw contract
37
- * as the rest of the tracing layer.
38
- *
39
- * On thrown errors: the error's name/message is attached to the span's context (visible
40
- * in the rendered tree/JSON output) and then re-thrown. The span is ended either way.
41
- *
42
- * Stateless — instantiate once and reuse, or use the exported singleton `spanRunner`.
43
- */
44
- export class SpanRunner {
45
- runWithSpan(tracingManagerOrSpanKeyname, spanKeynameOrFn, fnOrOptions, maybeOptions) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- // Disambiguate by the first argument's shape. A string means "ALS form"; an object
48
- // with `startSpan` means the explicit-manager form.
49
- let tracingManager;
50
- let spanKeyname;
51
- let fn;
52
- let options;
53
- if (typeof tracingManagerOrSpanKeyname === "string") {
54
- spanKeyname = tracingManagerOrSpanKeyname;
55
- fn = spanKeynameOrFn;
56
- options = fnOrOptions;
57
- // Resolve the manager from the active event context. If there isn't one (e.g. a
58
- // unit test calling this directly), fall back to running the function without a
59
- // span — tracing must never throw or change semantics.
60
- const container = EventContextManager.container();
61
- if (container !== undefined) {
62
- try {
63
- tracingManager = container.resolve("TracingManagerInterface");
64
- }
65
- catch (_a) {
66
- tracingManager = undefined;
67
- }
68
- }
69
- }
70
- else {
71
- tracingManager = tracingManagerOrSpanKeyname;
72
- spanKeyname = spanKeynameOrFn;
73
- fn = fnOrOptions;
74
- options = maybeOptions;
75
- }
76
- if (tracingManager === undefined) {
77
- // No manager available: ALS form called outside any event context, or no
78
- // TracingManager registered in the container. Run the function unchanged so
79
- // callers get the same behavior they'd see without `runWithSpan` wrapping at all.
80
- return yield fn();
81
- }
82
- const span = tracingManager.startSpan(spanKeyname, options === null || options === void 0 ? void 0 : options.parentKeyname, options === null || options === void 0 ? void 0 : options.parentId, options === null || options === void 0 ? void 0 : options.context);
83
- try {
84
- return yield fn();
85
- }
86
- catch (error) {
87
- // Annotate the span with error info so it surfaces in the rendered output without
88
- // forcing the caller to remember to add it themselves. Span.context is string-typed
89
- // by design (cheap to serialize), so we coerce.
90
- if (error instanceof Error) {
91
- span.context = Object.assign(Object.assign({}, span.context), { error: "true", errorName: error.name, errorMessage: error.message });
92
- }
93
- else {
94
- span.context = Object.assign(Object.assign({}, span.context), { error: "true", errorName: "non-error-throw", errorMessage: String(error) });
95
- }
96
- throw error;
97
- }
98
- finally {
99
- span.end();
100
- }
101
- });
102
- }
103
- }
104
- /**
105
- * Default singleton. Stateless so sharing is safe.
106
- */
107
- export const spanRunner = new SpanRunner();
108
- //# sourceMappingURL=span-runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"span-runner.js","sourceRoot":"","sources":["../../../../src/utils/span-runner.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,qBAAqB,CAAC;AAexD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,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O,MAAM,EAAE,EAAE,CAAC;YACpB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,kFAAkF;gBAClF,oFAAoF;gBACpF,gDAAgD;gBAChD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,IAAI,CAAC,OAAO,mCACP,IAAI,CAAC,OAAO,KACf,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,KAAK,CAAC,IAAI,EACrB,YAAY,EAAE,KAAK,CAAC,OAAO,GAC5B,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,OAAO,mCACP,IAAI,CAAC,OAAO,KACf,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,iBAAiB,EAC5B,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,GAC5B,CAAC;gBACJ,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;QACH,CAAC;KAAA;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- export * from "./traced.decorator";
@@ -1,35 +0,0 @@
1
- /**
2
- * Method decorator that wraps the decorated method in a span. The span is automatically
3
- * ended when the method returns or throws, and the `TracingManager` is auto-resolved
4
- * from the active `EventContext` — no need to inject it manually.
5
- *
6
- * ```ts
7
- * class PaymentService {
8
- * @traced() // span name = "PaymentService.charge"
9
- * async charge(amount: number) { ... }
10
- *
11
- * @traced("payment.refund.action") // explicit name
12
- * async refund(chargeId: string) { ... }
13
- * }
14
- * ```
15
- *
16
- * **Behavior outside an event context.** When the decorated method runs without an
17
- * active `EventContext` (e.g. a unit test calling the method directly, or background
18
- * work that escaped the event lifecycle), the decorator is a no-op — the original
19
- * method runs unchanged. Tracing must never throw or alter semantics.
20
- *
21
- * **Sync methods become async.** The decorator awaits the wrapped method internally,
22
- * so any decorated method returns a `Promise`. Decorating a sync method changes its
23
- * signature visible to callers — apply `@traced` to methods you'd already be awaiting
24
- * (DB calls, HTTP, expensive computations), not to tight sync helpers.
25
- *
26
- * **Type-level caveat.** TypeScript's parameter and method decorator types don't carry
27
- * enough information for the compiler to verify that the wrapped method's return type
28
- * is compatible with `Promise<T>`. The wrapper is type-safe at runtime; the call site's
29
- * static types are unchanged. Pair with explicit `: Promise<T>` annotations on the
30
- * method when you want the static type to match what's actually returned.
31
- *
32
- * @param spanName Optional explicit name for the span. Defaults to
33
- * `${ClassName}.${methodName}`.
34
- */
35
- export declare function traced(spanName?: string): MethodDecorator;
@@ -1,55 +0,0 @@
1
- import { TracingManagerInterface } from "../interfaces/tracing-manager.interface";
2
- /**
3
- * Options to scope a `runWithSpan` call beyond just naming the span.
4
- */
5
- export interface SpanRunnerOptions {
6
- /** When set, attach the new span as a child of the most recent span with this keyname. */
7
- parentKeyname?: string;
8
- /** Disambiguates parents when multiple spans share the same `parentKeyname`. */
9
- parentId?: string;
10
- /** Free-form context recorded on the span and surfaced in the rendered output. */
11
- context?: {
12
- [key: string]: string;
13
- };
14
- }
15
- /**
16
- * Runs a function inside a span that is automatically ended when the function returns
17
- * or throws.
18
- *
19
- * Two call shapes are supported:
20
- *
21
- * **Explicit form** (`runWithSpan(tracingManager, name, fn)`) — pass the manager you've
22
- * already injected. Works anywhere, including outside an event context. Use this when
23
- * you have a `TracingManager` reference in hand:
24
- *
25
- * ```ts
26
- * return spanRunner.runWithSpan(this.tracingManager, "payment.charge",
27
- * () => this.client.charge(amount));
28
- * ```
29
- *
30
- * **ALS form** (`runWithSpan(name, fn)`) — auto-resolves the `TracingManager` from the
31
- * active `EventContext`'s container. Concise; works when called from anywhere inside
32
- * a Pristine event (controller, service, etc.) without needing the manager threaded
33
- * through:
34
- *
35
- * ```ts
36
- * return spanRunner.runWithSpan("payment.charge", () => this.client.charge(amount));
37
- * ```
38
- *
39
- * If the ALS form is used outside any `EventContext` (e.g. a unit test that doesn't
40
- * boot a kernel), no span is created and `fn` runs unchanged — same no-throw contract
41
- * as the rest of the tracing layer.
42
- *
43
- * On thrown errors: the error's name/message is attached to the span's context (visible
44
- * in the rendered tree/JSON output) and then re-thrown. The span is ended either way.
45
- *
46
- * Stateless — instantiate once and reuse, or use the exported singleton `spanRunner`.
47
- */
48
- export declare class SpanRunner {
49
- runWithSpan<T>(tracingManager: TracingManagerInterface, spanKeyname: string, fn: () => Promise<T> | T, options?: SpanRunnerOptions): Promise<T>;
50
- runWithSpan<T>(spanKeyname: string, fn: () => Promise<T> | T, options?: SpanRunnerOptions): Promise<T>;
51
- }
52
- /**
53
- * Default singleton. Stateless so sharing is safe.
54
- */
55
- export declare const spanRunner: SpanRunner;