@pristine-ts/telemetry 2.0.3 → 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 +171 -42
- package/dist/lib/cjs/managers/tracing.manager.js.map +1 -1
- package/dist/lib/cjs/models/models.js +1 -0
- package/dist/lib/cjs/models/models.js.map +1 -1
- package/dist/lib/cjs/models/span-event.model.js +6 -0
- package/dist/lib/cjs/models/span-event.model.js.map +1 -0
- package/dist/lib/cjs/models/span.model.js +2 -68
- package/dist/lib/cjs/models/span.model.js.map +1 -1
- package/dist/lib/cjs/models/trace.model.js +2 -35
- package/dist/lib/cjs/models/trace.model.js.map +1 -1
- package/dist/lib/cjs/telemetry.module.js +0 -1
- package/dist/lib/cjs/telemetry.module.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/cjs/utils/span-runner.js +3 -108
- 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 +171 -42
- package/dist/lib/esm/managers/tracing.manager.js.map +1 -1
- package/dist/lib/esm/models/models.js +1 -0
- package/dist/lib/esm/models/models.js.map +1 -1
- package/dist/lib/esm/models/span-event.model.js +2 -0
- package/dist/lib/esm/models/span-event.model.js.map +1 -0
- package/dist/lib/esm/models/span.model.js +1 -67
- package/dist/lib/esm/models/span.model.js.map +1 -1
- package/dist/lib/esm/models/trace.model.js +1 -34
- package/dist/lib/esm/models/trace.model.js.map +1 -1
- package/dist/lib/esm/telemetry.module.js +0 -1
- package/dist/lib/esm/telemetry.module.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/lib/esm/utils/span-runner.js +1 -107
- 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 +71 -13
- package/dist/types/models/models.d.ts +1 -0
- package/dist/types/models/span-event.model.d.ts +1 -0
- package/dist/types/models/span.model.d.ts +1 -73
- package/dist/types/models/trace.model.d.ts +1 -44
- package/dist/types/telemetry.module.d.ts +0 -1
- package/dist/types/utils/span-runner.d.ts +1 -55
- package/package.json +4 -4
- package/dist/lib/cjs/decorators/decorators.js +0 -18
- package/dist/lib/cjs/decorators/decorators.js.map +0 -1
- package/dist/lib/cjs/decorators/traced.decorator.js +0 -60
- package/dist/lib/cjs/decorators/traced.decorator.js.map +0 -1
- package/dist/lib/esm/decorators/decorators.js +0 -2
- package/dist/lib/esm/decorators/decorators.js.map +0 -1
- package/dist/lib/esm/decorators/traced.decorator.js +0 -57
- package/dist/lib/esm/decorators/traced.decorator.js.map +0 -1
- package/dist/types/decorators/decorators.d.ts +0 -1
- package/dist/types/decorators/traced.decorator.d.ts +0 -35
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* This enum is for the different span names that are integrated in Pristine.
|
|
3
|
-
*/
|
|
4
|
-
export declare enum SpanKeynameEnum {
|
|
5
|
-
ChildContainerCreation = "child.container.creation",
|
|
6
|
-
ChildContainerRegistration = "child.container.registration",
|
|
7
|
-
ConfigurationInitialization = "configuration.initialization",
|
|
8
|
-
ErrorResponseInterceptors = "error.response.interceptors",
|
|
9
|
-
EventDispatcherResolver = "event.dispatcher.resolver",
|
|
10
|
-
EventExecution = "event.execution",
|
|
11
|
-
EventInitialization = "event.initialization",
|
|
12
|
-
EventPreMappingInterception = "event.pre-mapping.interception",
|
|
13
|
-
EventPostMappingInterception = "event.post-mapping.interception",
|
|
14
|
-
EventPreResponseMappingInterception = "event.pre-response-mapping.interception",
|
|
15
|
-
EventPostResponseMappingInterception = "event.post-response-mapping.interception",
|
|
16
|
-
EventMapping = "event.mapping",
|
|
17
|
-
KernelInitialization = "kernel.initialization",
|
|
18
|
-
ModuleInitialization = "module.initialization",
|
|
19
|
-
ModuleInitializationImportModules = "module.initialization.import.modules",
|
|
20
|
-
RequestExecution = "request.execution",
|
|
21
|
-
RequestInterceptors = "request.interceptors",
|
|
22
|
-
ResponseInterceptors = "response.interceptors",
|
|
23
|
-
RootExecution = "root.execution",
|
|
24
|
-
RouterControllerResolver = "router.controller.resolver",
|
|
25
|
-
RouterFindMethodRouterNode = "router.find.method.router.node",
|
|
26
|
-
RouterRequestAuthentication = "router.request.authentication",
|
|
27
|
-
RouterRequestExecution = "router.request.execution",
|
|
28
|
-
RouterSetup = "router.setup"
|
|
29
|
-
}
|
|
1
|
+
export { SpanKeynameEnum } from "@pristine-ts/common";
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Trace } from "../models/trace.model";
|
|
3
|
-
/**
|
|
4
|
-
* This interface specifies what a tracing manager should implement.
|
|
5
|
-
*/
|
|
6
|
-
export interface TracingManagerInterface {
|
|
7
|
-
/**
|
|
8
|
-
* This property contains a reference to the active trace.
|
|
9
|
-
*/
|
|
10
|
-
trace?: Trace;
|
|
11
|
-
/**
|
|
12
|
-
* This methods starts the Tracing. This should be the first method called before doing anything else.
|
|
13
|
-
* @param spanRootKeyname The keyname of the span at the root.
|
|
14
|
-
* @param traceId The trace id if there is one.
|
|
15
|
-
* @param context The context if there is one.
|
|
16
|
-
*/
|
|
17
|
-
startTracing(spanRootKeyname?: string, traceId?: string, context?: {
|
|
18
|
-
[key: string]: string;
|
|
19
|
-
}): Span;
|
|
20
|
-
/**
|
|
21
|
-
* This method ends the trace entirely.
|
|
22
|
-
*/
|
|
23
|
-
endTrace(): void;
|
|
24
|
-
/**
|
|
25
|
-
* This method starts a new span.
|
|
26
|
-
* @param keyname The keyname for this new span.
|
|
27
|
-
* @param parentKeyname The keyname of the parent span.
|
|
28
|
-
* @param parentId The id of the parent span.
|
|
29
|
-
* @param context The context if there is one.
|
|
30
|
-
*/
|
|
31
|
-
startSpan(keyname: string, parentKeyname?: string, parentId?: string, context?: {
|
|
32
|
-
[key: string]: string;
|
|
33
|
-
}): Span;
|
|
34
|
-
/**
|
|
35
|
-
* This methods adds an already created Span to the trace. It assumes that it its hierarchy is correct.
|
|
36
|
-
* @param span The span to add.
|
|
37
|
-
*/
|
|
38
|
-
addSpan(span: Span): Span;
|
|
39
|
-
/**
|
|
40
|
-
* This methods ends the span by setting the end date and by calling the tracers.
|
|
41
|
-
* It will also end the trace if the rootspan is being ended.
|
|
42
|
-
* @param span The span to end.
|
|
43
|
-
*/
|
|
44
|
-
endSpan(span: Span): void;
|
|
45
|
-
/**
|
|
46
|
-
* This method ends the span using a keyname.
|
|
47
|
-
* @param keyname The keyname of the span to end.
|
|
48
|
-
*/
|
|
49
|
-
endSpanKeyname(keyname: string): void;
|
|
50
|
-
}
|
|
1
|
+
export { TracingManagerInterface } from "@pristine-ts/common";
|
|
@@ -9,13 +9,23 @@ import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
|
9
9
|
* It is tagged and can be injected using TracingManagerInterface which facilitates mocking.
|
|
10
10
|
* It is module scoped to the TelemetryModuleKeyname.
|
|
11
11
|
*
|
|
12
|
+
* **Where the active `Trace` lives.** The active trace is stored on `EventContext.trace`,
|
|
13
|
+
* propagated via `AsyncLocalStorage`. Every `TracingManager` instance — whether resolved
|
|
14
|
+
* from the root container (kernel boot) or from a per-event child container — reads and
|
|
15
|
+
* writes spans through the same `EventContext.trace` reference, so a span started in the
|
|
16
|
+
* kernel and an event added in a controller belong to the same trace tree.
|
|
17
|
+
*
|
|
18
|
+
* **Fallback `this.trace`.** During kernel boot (`Kernel.start()` and friends), there is
|
|
19
|
+
* no `EventContext` yet — the framework hasn't started handling an event. In that window
|
|
20
|
+
* the manager falls back to `this.trace`. This is the only time `this.trace` is touched.
|
|
21
|
+
*
|
|
12
22
|
* **Lifecycle: container-scoped, not singleton.** Each per-event DI child container gets
|
|
13
|
-
* its own `TracingManager` instance
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
23
|
+
* its own `TracingManager` instance. The per-instance `this.trace` fallback is what keeps
|
|
24
|
+
* parallel events isolated *if* tracing is somehow started outside an EventContext.
|
|
25
|
+
* Resolving `TracingManager` from the root container returns the root instance (used for
|
|
26
|
+
* kernel-initialization spans); resolving from a child container returns the per-event
|
|
27
|
+
* instance — both will agree on what trace is active inside an event because they read
|
|
28
|
+
* from EventContext.
|
|
19
29
|
*/
|
|
20
30
|
export declare class TracingManager implements TracingManagerInterface {
|
|
21
31
|
private readonly tracers;
|
|
@@ -24,15 +34,10 @@ export declare class TracingManager implements TracingManagerInterface {
|
|
|
24
34
|
private readonly debug;
|
|
25
35
|
private readonly tracingContext;
|
|
26
36
|
/**
|
|
27
|
-
*
|
|
37
|
+
* Fallback trace used only during kernel boot when no `EventContext` is active.
|
|
38
|
+
* Inside an event, the active trace lives on `EventContext.trace` instead.
|
|
28
39
|
*/
|
|
29
40
|
trace?: Trace;
|
|
30
|
-
/**
|
|
31
|
-
* This object contains a map of all the spans sorted by their keyname.
|
|
32
|
-
*/
|
|
33
|
-
spans: {
|
|
34
|
-
[keyname: string]: Span[];
|
|
35
|
-
};
|
|
36
41
|
/**
|
|
37
42
|
* The Tracing Manager provides methods to help with tracing.
|
|
38
43
|
* It is tagged and can be injected using TracingManagerInterface which facilitates mocking.
|
|
@@ -45,6 +50,16 @@ export declare class TracingManager implements TracingManagerInterface {
|
|
|
45
50
|
* @param tracingContext The tracing context.
|
|
46
51
|
*/
|
|
47
52
|
constructor(tracers: TracerInterface[], loghandler: LogHandlerInterface, isActive: boolean, debug: boolean, tracingContext: TracingContext);
|
|
53
|
+
/**
|
|
54
|
+
* Returns the currently active trace from the EventContext, falling back to the
|
|
55
|
+
* per-instance `this.trace` when no EventContext is active (kernel boot).
|
|
56
|
+
*/
|
|
57
|
+
private getActiveTrace;
|
|
58
|
+
/**
|
|
59
|
+
* Stores `trace` as the active trace — on `EventContext.trace` when an event is active,
|
|
60
|
+
* otherwise on the instance fallback `this.trace`.
|
|
61
|
+
*/
|
|
62
|
+
private setActiveTrace;
|
|
48
63
|
/**
|
|
49
64
|
* This methods starts the Tracing. This should be the first method called before doing anything else.
|
|
50
65
|
* @param spanRootKeyname The keyname of the span at the root.
|
|
@@ -84,4 +99,47 @@ export declare class TracingManager implements TracingManagerInterface {
|
|
|
84
99
|
* This method ends the trace entirely.
|
|
85
100
|
*/
|
|
86
101
|
endTrace(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Attaches a named, timestamped event to the most-recently-started in-progress span.
|
|
104
|
+
* Use for noteworthy moments that don't warrant a child span — "validation passed",
|
|
105
|
+
* "found 50 rows", "rate limit ok". Cheap (just pushes onto an array); shows up in
|
|
106
|
+
* the trace rendered by tracers (ConsoleTracer, FileTracer, X-Ray, etc.).
|
|
107
|
+
*
|
|
108
|
+
* If no span is currently active (no trace started, or every span has already ended),
|
|
109
|
+
* a warning is logged and the marker is dropped. The warning is the explicit signal
|
|
110
|
+
* that "this marker call had nowhere to go" — usually the sign of a missing
|
|
111
|
+
* `startTracing()` call earlier in the flow.
|
|
112
|
+
*/
|
|
113
|
+
addEventToCurrentSpan(message: string, attributes?: {
|
|
114
|
+
[key: string]: string;
|
|
115
|
+
}): void;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the active trace's spans + their events as a flat, timestamp-sorted list of
|
|
118
|
+
* `{kind, name, date, attributes}` entries. Public utility for custom tracers, debug
|
|
119
|
+
* endpoints, test helpers, or anyone who wants "the active trace as a flat list."
|
|
120
|
+
* Returns an empty array when no active trace exists.
|
|
121
|
+
*/
|
|
122
|
+
getCurrentTrail(): Array<{
|
|
123
|
+
kind: "span" | "event";
|
|
124
|
+
name: string;
|
|
125
|
+
date: Date;
|
|
126
|
+
attributes: {
|
|
127
|
+
[key: string]: string;
|
|
128
|
+
};
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Finds the deepest in-progress span — the leaf of the still-open subtree. Used as
|
|
132
|
+
* the target for `addEventToCurrentSpan`. Intuition: events attach to whatever is
|
|
133
|
+
* currently open at the bottom of the call stack.
|
|
134
|
+
*
|
|
135
|
+
* Walking the in-progress subtree (rather than ranking all spans by start date)
|
|
136
|
+
* avoids the edge case where a parent and child have the same `Date.now()` value —
|
|
137
|
+
* picking the "latest started" by raw timestamp would incorrectly attach to the
|
|
138
|
+
* parent. Depth-first traversal of in-progress children naturally lands on the
|
|
139
|
+
* deepest leaf. Tie-broken by latest start date when multiple leaves exist.
|
|
140
|
+
*
|
|
141
|
+
* Returns undefined when nothing is in progress (no trace, or every span has ended).
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
private findActiveLeafSpan;
|
|
87
145
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SpanEvent } from "@pristine-ts/common";
|
|
@@ -1,73 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { TracingManagerInterface } from "../interfaces/tracing-manager.interface";
|
|
3
|
-
/**
|
|
4
|
-
* This model represents a span.
|
|
5
|
-
*/
|
|
6
|
-
export declare class Span {
|
|
7
|
-
keyname: string;
|
|
8
|
-
/**
|
|
9
|
-
* The unique id of the span.
|
|
10
|
-
*/
|
|
11
|
-
id: string;
|
|
12
|
-
/**
|
|
13
|
-
* The tracing manager.
|
|
14
|
-
*/
|
|
15
|
-
tracingManager?: TracingManagerInterface;
|
|
16
|
-
/**
|
|
17
|
-
* The trace the span is attached to.
|
|
18
|
-
*/
|
|
19
|
-
trace?: Trace;
|
|
20
|
-
/**
|
|
21
|
-
* The timestamp in milliseconds at which the span was started.
|
|
22
|
-
*/
|
|
23
|
-
startDate: number;
|
|
24
|
-
/**
|
|
25
|
-
* The timestamp in milliseconds at which the span was ended.
|
|
26
|
-
*/
|
|
27
|
-
endDate?: number;
|
|
28
|
-
/**
|
|
29
|
-
* The parent span.
|
|
30
|
-
*/
|
|
31
|
-
parentSpan?: Span;
|
|
32
|
-
/**
|
|
33
|
-
* The children spans.
|
|
34
|
-
*/
|
|
35
|
-
children: Span[];
|
|
36
|
-
/**
|
|
37
|
-
* The context associated with the span.
|
|
38
|
-
*/
|
|
39
|
-
context: {
|
|
40
|
-
[key: string]: string;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Whether or not the span is in progress, meaning it has not ended.
|
|
44
|
-
*/
|
|
45
|
-
inProgress: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* This model represents a span.
|
|
48
|
-
* @param keyname The keyname of the span.
|
|
49
|
-
* @param id The unique id of the span.
|
|
50
|
-
* @param context The context to associate with the span.
|
|
51
|
-
*/
|
|
52
|
-
constructor(keyname: string, id?: string, context?: {
|
|
53
|
-
[key: string]: string;
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* This method returns the duration of the span in milliseconds.
|
|
57
|
-
*/
|
|
58
|
-
getDuration(): number;
|
|
59
|
-
/**
|
|
60
|
-
* This method ends the span.
|
|
61
|
-
*/
|
|
62
|
-
end(): void;
|
|
63
|
-
/**
|
|
64
|
-
* This method sets the trace for the span and all of its children.
|
|
65
|
-
* @param trace The trace the span should be attached to.
|
|
66
|
-
*/
|
|
67
|
-
setTrace(trace: Trace): void;
|
|
68
|
-
/**
|
|
69
|
-
* This method adds a child span to the current span. It only adds it if it's not already part of the children.
|
|
70
|
-
* @param span The span to add as a child.
|
|
71
|
-
*/
|
|
72
|
-
addChild(span: Span): void;
|
|
73
|
-
}
|
|
1
|
+
export { Span, SpanLifecycleOwnerInterface } from "@pristine-ts/common";
|
|
@@ -1,44 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* This model represents a trace.
|
|
4
|
-
*/
|
|
5
|
-
export declare class Trace {
|
|
6
|
-
/**
|
|
7
|
-
* The unique id of the trace.
|
|
8
|
-
*/
|
|
9
|
-
id: string;
|
|
10
|
-
/**
|
|
11
|
-
* The timestamp in milliseconds at which the trace was started.
|
|
12
|
-
*/
|
|
13
|
-
startDate: number;
|
|
14
|
-
/**
|
|
15
|
-
* The timestamp in milliseconds at which the trace was ended.
|
|
16
|
-
*/
|
|
17
|
-
endDate?: number;
|
|
18
|
-
/**
|
|
19
|
-
* The span that is at the root.
|
|
20
|
-
*/
|
|
21
|
-
rootSpan?: Span;
|
|
22
|
-
/**
|
|
23
|
-
* The context associated with the trace.
|
|
24
|
-
*/
|
|
25
|
-
context?: {
|
|
26
|
-
[key: string]: string;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Whether or not the trace was ended.
|
|
30
|
-
*/
|
|
31
|
-
hasEnded: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* This model represents a trace.
|
|
34
|
-
* @param id The unique id of the trace.
|
|
35
|
-
* @param context The context associated with the trace.
|
|
36
|
-
*/
|
|
37
|
-
constructor(id?: string, context?: {
|
|
38
|
-
[key: string]: string;
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* This returns the duration of the trace in miliseconds.
|
|
42
|
-
*/
|
|
43
|
-
getDuration(): number;
|
|
44
|
-
}
|
|
1
|
+
export { Trace } from "@pristine-ts/common";
|
|
@@ -1,55 +1 @@
|
|
|
1
|
-
|
|
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;
|
|
1
|
+
export { SpanRunner, SpanRunnerOptions, spanRunner } from "@pristine-ts/common";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/telemetry",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/telemetry.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/telemetry.module.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"test:cov": "jest --coverage"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@pristine-ts/common": "^2.0.
|
|
16
|
-
"@pristine-ts/logging": "^2.0.
|
|
15
|
+
"@pristine-ts/common": "^2.0.4",
|
|
16
|
+
"@pristine-ts/logging": "^2.0.4",
|
|
17
17
|
"uuid": "^9.0.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"src/*.{js,ts}"
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "f376d34e13c1b17b7764c0b47708148e4e51390b",
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
|
67
67
|
"url": "https://github.com/magieno/pristine-ts.git",
|
|
@@ -1,18 +0,0 @@
|
|
|
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("./traced.decorator"), exports);
|
|
18
|
-
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
* @param spanName Optional explicit name for the span. Defaults to
|
|
37
|
-
* `${ClassName}.${methodName}`.
|
|
38
|
-
*/
|
|
39
|
-
function traced(spanName) {
|
|
40
|
-
return (target, propertyKey, descriptor) => {
|
|
41
|
-
var _a, _b, _c;
|
|
42
|
-
const original = descriptor.value;
|
|
43
|
-
if (typeof original !== "function") {
|
|
44
|
-
// Decorator was applied to something other than a method (a getter, a property
|
|
45
|
-
// with no initial value, etc.). Leave it alone — silently no-op rather than
|
|
46
|
-
// throw at decoration time.
|
|
47
|
-
return descriptor;
|
|
48
|
-
}
|
|
49
|
-
// Resolve a stable default name at decoration time. `target.constructor.name` is
|
|
50
|
-
// the class name for instance methods; for static methods, `target.name` is the
|
|
51
|
-
// class. We cover both via the fallback chain.
|
|
52
|
-
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";
|
|
53
|
-
const resolvedName = spanName !== null && spanName !== void 0 ? spanName : `${className}.${String(propertyKey)}`;
|
|
54
|
-
descriptor.value = function (...args) {
|
|
55
|
-
return span_runner_1.spanRunner.runWithSpan(resolvedName, () => original.apply(this, args));
|
|
56
|
-
};
|
|
57
|
-
return descriptor;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=traced.decorator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"traced.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/traced.decorator.ts"],"names":[],"mappings":";;AAoCA,wBAsBC;AA1DD,sDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
* @param spanName Optional explicit name for the span. Defaults to
|
|
34
|
-
* `${ClassName}.${methodName}`.
|
|
35
|
-
*/
|
|
36
|
-
export function traced(spanName) {
|
|
37
|
-
return (target, propertyKey, descriptor) => {
|
|
38
|
-
var _a, _b, _c;
|
|
39
|
-
const original = descriptor.value;
|
|
40
|
-
if (typeof original !== "function") {
|
|
41
|
-
// Decorator was applied to something other than a method (a getter, a property
|
|
42
|
-
// with no initial value, etc.). Leave it alone — silently no-op rather than
|
|
43
|
-
// throw at decoration time.
|
|
44
|
-
return descriptor;
|
|
45
|
-
}
|
|
46
|
-
// Resolve a stable default name at decoration time. `target.constructor.name` is
|
|
47
|
-
// the class name for instance methods; for static methods, `target.name` is the
|
|
48
|
-
// class. We cover both via the fallback chain.
|
|
49
|
-
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";
|
|
50
|
-
const resolvedName = spanName !== null && spanName !== void 0 ? spanName : `${className}.${String(propertyKey)}`;
|
|
51
|
-
descriptor.value = function (...args) {
|
|
52
|
-
return spanRunner.runWithSpan(resolvedName, () => original.apply(this, args));
|
|
53
|
-
};
|
|
54
|
-
return descriptor;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=traced.decorator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;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"}
|
|
@@ -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;
|