@pristine-ts/common 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/contexts/event-context.js +5 -5
- package/dist/lib/cjs/contexts/event-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/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/contexts/event-context.js +5 -5
- package/dist/lib/esm/contexts/event-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/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/contexts/event-context.d.ts +13 -6
- 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/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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-context.js","sourceRoot":"","sources":["../../../../src/contexts/event-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-context.js","sourceRoot":"","sources":["../../../../src/contexts/event-context.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,YAAY;CAmBxB"}
|
|
@@ -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"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"tracing-manager.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/tracing-manager.interface.ts"],"names":[],"mappings":""}
|
|
@@ -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"}
|