@pristine-ts/telemetry 1.0.440 → 2.0.2
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/console-tracer-output-mode.enum.js +16 -0
- package/dist/lib/cjs/enums/console-tracer-output-mode.enum.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/managers/tracing.manager.js +41 -41
- package/dist/lib/cjs/managers/tracing.manager.js.map +1 -1
- package/dist/lib/cjs/telemetry.configuration-keys.js +26 -0
- package/dist/lib/cjs/telemetry.configuration-keys.js.map +1 -0
- package/dist/lib/cjs/telemetry.module.js +90 -0
- package/dist/lib/cjs/telemetry.module.js.map +1 -1
- package/dist/lib/cjs/tracers/console.tracer.js +106 -0
- package/dist/lib/cjs/tracers/console.tracer.js.map +1 -0
- package/dist/lib/cjs/tracers/file.tracer.js +161 -0
- package/dist/lib/cjs/tracers/file.tracer.js.map +1 -0
- package/dist/lib/cjs/tracers/tracers.js +2 -1
- package/dist/lib/cjs/tracers/tracers.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/lib/cjs/utils/span-runner.js +81 -0
- package/dist/lib/cjs/utils/span-runner.js.map +1 -0
- package/dist/lib/cjs/utils/trace-renderer.js +128 -0
- package/dist/lib/cjs/utils/trace-renderer.js.map +1 -0
- package/dist/lib/cjs/utils/utils.js +19 -0
- package/dist/lib/cjs/utils/utils.js.map +1 -0
- package/dist/lib/esm/enums/console-tracer-output-mode.enum.js +13 -0
- package/dist/lib/esm/enums/console-tracer-output-mode.enum.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/managers/tracing.manager.js +42 -42
- package/dist/lib/esm/managers/tracing.manager.js.map +1 -1
- package/dist/lib/esm/telemetry.configuration-keys.js +23 -0
- package/dist/lib/esm/telemetry.configuration-keys.js.map +1 -0
- package/dist/lib/esm/telemetry.module.js +91 -1
- package/dist/lib/esm/telemetry.module.js.map +1 -1
- package/dist/lib/esm/tracers/console.tracer.js +103 -0
- package/dist/lib/esm/tracers/console.tracer.js.map +1 -0
- package/dist/lib/esm/tracers/file.tracer.js +125 -0
- package/dist/lib/esm/tracers/file.tracer.js.map +1 -0
- package/dist/lib/esm/tracers/tracers.js +2 -1
- package/dist/lib/esm/tracers/tracers.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/lib/esm/utils/span-runner.js +77 -0
- package/dist/lib/esm/utils/span-runner.js.map +1 -0
- package/dist/lib/esm/utils/trace-renderer.js +124 -0
- package/dist/lib/esm/utils/trace-renderer.js.map +1 -0
- package/dist/lib/esm/utils/utils.js +3 -0
- package/dist/lib/esm/utils/utils.js.map +1 -0
- package/dist/types/enums/console-tracer-output-mode.enum.d.ts +11 -0
- package/dist/types/enums/enums.d.ts +1 -0
- package/dist/types/managers/tracing.manager.d.ts +3 -1
- package/dist/types/telemetry.configuration-keys.d.ts +48 -0
- package/dist/types/telemetry.module.d.ts +2 -0
- package/dist/types/tracers/console.tracer.d.ts +28 -0
- package/dist/types/tracers/file.tracer.d.ts +34 -0
- package/dist/types/tracers/tracers.d.ts +2 -1
- package/dist/types/utils/span-runner.d.ts +59 -0
- package/dist/types/utils/trace-renderer.d.ts +41 -0
- package/dist/types/utils/utils.d.ts +2 -0
- package/package.json +4 -4
- package/dist/lib/cjs/tracers/basic.tracer.js +0 -50
- package/dist/lib/cjs/tracers/basic.tracer.js.map +0 -1
- package/dist/lib/esm/tracers/basic.tracer.js +0 -47
- package/dist/lib/esm/tracers/basic.tracer.js.map +0 -1
- package/dist/types/tracers/basic.tracer.d.ts +0 -12
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* Replaces the manual `start → try → finally end()` boilerplate:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* // Before:
|
|
23
|
+
* const span = this.tracingManager.startSpan("payment.charge");
|
|
24
|
+
* try {
|
|
25
|
+
* return await this.client.charge(amount);
|
|
26
|
+
* } finally {
|
|
27
|
+
* span.end();
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // After:
|
|
31
|
+
* return spanRunner.runWithSpan(this.tracingManager, "payment.charge",
|
|
32
|
+
* () => this.client.charge(amount));
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Why pass `tracingManager` explicitly? The manager is registered per-container, and
|
|
36
|
+
* Pristine creates a child container per event. A "magic" lookup that finds the right
|
|
37
|
+
* one requires AsyncLocalStorage propagation — deferred until that infrastructure
|
|
38
|
+
* exists. For now, services inject `@inject("TracingManagerInterface") private readonly
|
|
39
|
+
* tracingManager: TracingManagerInterface` and pass it through.
|
|
40
|
+
*
|
|
41
|
+
* On thrown errors: the error's name/message is attached to the span's context (visible
|
|
42
|
+
* in the rendered tree/json output) and then re-thrown. The span is ended either way.
|
|
43
|
+
*
|
|
44
|
+
* Stateless — instantiate once and reuse, or use the exported singleton `spanRunner`.
|
|
45
|
+
*/
|
|
46
|
+
export declare class SpanRunner {
|
|
47
|
+
/**
|
|
48
|
+
* Runs `fn` inside a span. See class docs for full semantics.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam T The return type of `fn`. Always wrapped in `Promise<T>` because the
|
|
51
|
+
* helper awaits internally — a sync `fn` works fine, but the return type loses its
|
|
52
|
+
* sync-ness.
|
|
53
|
+
*/
|
|
54
|
+
runWithSpan<T>(tracingManager: TracingManagerInterface, spanKeyname: string, fn: () => Promise<T> | T, options?: SpanRunnerOptions): Promise<T>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Default singleton. Stateless so sharing is safe.
|
|
58
|
+
*/
|
|
59
|
+
export declare const spanRunner: SpanRunner;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Trace } from "../models/trace.model";
|
|
2
|
+
/**
|
|
3
|
+
* Pure-function renderers for `Trace` objects. Used by both `ConsoleTracer` (writes to
|
|
4
|
+
* stdout) and `FileTracer` (writes to disk) so the visual output is identical regardless
|
|
5
|
+
* of destination. All methods are stateless — instantiate once and reuse, or use the
|
|
6
|
+
* exported singleton `traceRenderer` if you don't care.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TraceRenderer {
|
|
9
|
+
/**
|
|
10
|
+
* Indented ASCII tree mirroring the span hierarchy. Right-aligned durations, slowest
|
|
11
|
+
* leaf span flagged as `← bottleneck`. Best for human readers.
|
|
12
|
+
*
|
|
13
|
+
* Internal/parent spans are skipped for bottleneck detection on purpose: a parent's
|
|
14
|
+
* duration is the sum of its children's work, so it would always dwarf any single
|
|
15
|
+
* leaf and the flag would never highlight where the actual time was spent.
|
|
16
|
+
*/
|
|
17
|
+
renderTree(trace: Trace): string;
|
|
18
|
+
/**
|
|
19
|
+
* One line per span sorted by start time, no indentation. Best for grep / log
|
|
20
|
+
* aggregation.
|
|
21
|
+
*/
|
|
22
|
+
renderFlat(trace: Trace): string;
|
|
23
|
+
/**
|
|
24
|
+
* Pretty-printed JSON dump of the trace + every span. Best for piping into a downstream
|
|
25
|
+
* tool that wants structured access.
|
|
26
|
+
*/
|
|
27
|
+
renderJson(trace: Trace): string;
|
|
28
|
+
/**
|
|
29
|
+
* Serializes a trace to a plain JSON-friendly object. Exposed for callers that want to
|
|
30
|
+
* embed the structured form in a larger payload (e.g. a NDJSON line).
|
|
31
|
+
*/
|
|
32
|
+
serialize(trace: Trace): Record<string, unknown>;
|
|
33
|
+
private serializeSpan;
|
|
34
|
+
/** Depth-first traversal helper. Visits the root and every descendant once. */
|
|
35
|
+
private walkSpans;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Default singleton. Use this from any caller that doesn't care to construct its own —
|
|
39
|
+
* the class is stateless so sharing is safe.
|
|
40
|
+
*/
|
|
41
|
+
export declare const traceRenderer: TraceRenderer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/telemetry",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
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": "^
|
|
16
|
-
"@pristine-ts/logging": "^
|
|
15
|
+
"@pristine-ts/common": "^2.0.2",
|
|
16
|
+
"@pristine-ts/logging": "^2.0.2",
|
|
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": "b0899c7eb6b34a99c6df0739507b1458549a0009",
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
|
67
67
|
"url": "https://github.com/magieno/pristine-ts.git",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.XrayTracer = void 0;
|
|
10
|
-
const tsyringe_1 = require("tsyringe");
|
|
11
|
-
const common_1 = require("@pristine-ts/common");
|
|
12
|
-
const stream_1 = require("stream");
|
|
13
|
-
/**
|
|
14
|
-
* We need this to have at least one tracer so the @injectAll(ServiceDefinitionTagEnum.Tracer) does not fail
|
|
15
|
-
* Until there's a fix for: https://github.com/microsoft/tsyringe/issues/63
|
|
16
|
-
*/
|
|
17
|
-
let XrayTracer = class XrayTracer {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.spanStartedStream = new stream_1.Readable({
|
|
20
|
-
objectMode: true,
|
|
21
|
-
read(size) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
this.spanEndedStream = new stream_1.Readable({
|
|
26
|
-
objectMode: true,
|
|
27
|
-
read(size) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
this.traceStartedStream = new stream_1.Readable({
|
|
32
|
-
objectMode: true,
|
|
33
|
-
read(size) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
this.traceEndedStream = new stream_1.Readable({
|
|
38
|
-
objectMode: true,
|
|
39
|
-
read(size) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
exports.XrayTracer = XrayTracer;
|
|
46
|
-
exports.XrayTracer = XrayTracer = __decorate([
|
|
47
|
-
(0, common_1.tag)(common_1.ServiceDefinitionTagEnum.Tracer),
|
|
48
|
-
(0, tsyringe_1.injectable)()
|
|
49
|
-
], XrayTracer);
|
|
50
|
-
//# sourceMappingURL=basic.tracer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basic.tracer.js","sourceRoot":"","sources":["../../../../src/tracers/basic.tracer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAoC;AACpC,gDAAkE;AAClE,mCAAgC;AAGhC;;;GAGG;AAGI,IAAM,UAAU,GAAhB,MAAM,UAAU;IAAhB;QACL,sBAAiB,GAAc,IAAI,iBAAQ,CAAC;YAC1C,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QACH,oBAAe,GAAc,IAAI,iBAAQ,CAAC;YACxC,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QACH,uBAAkB,GAAc,IAAI,iBAAQ,CAAC;YAC3C,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QACH,qBAAgB,GAAc,IAAI,iBAAQ,CAAC;YACzC,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CAAA,CAAA;AAzBY,gCAAU;qBAAV,UAAU;IAFtB,IAAA,YAAG,EAAC,iCAAwB,CAAC,MAAM,CAAC;IACpC,IAAA,qBAAU,GAAE;GACA,UAAU,CAyBtB"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
import { injectable } from "tsyringe";
|
|
8
|
-
import { ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
|
|
9
|
-
import { Readable } from "stream";
|
|
10
|
-
/**
|
|
11
|
-
* We need this to have at least one tracer so the @injectAll(ServiceDefinitionTagEnum.Tracer) does not fail
|
|
12
|
-
* Until there's a fix for: https://github.com/microsoft/tsyringe/issues/63
|
|
13
|
-
*/
|
|
14
|
-
let XrayTracer = class XrayTracer {
|
|
15
|
-
constructor() {
|
|
16
|
-
this.spanStartedStream = new Readable({
|
|
17
|
-
objectMode: true,
|
|
18
|
-
read(size) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
this.spanEndedStream = new Readable({
|
|
23
|
-
objectMode: true,
|
|
24
|
-
read(size) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
this.traceStartedStream = new Readable({
|
|
29
|
-
objectMode: true,
|
|
30
|
-
read(size) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
this.traceEndedStream = new Readable({
|
|
35
|
-
objectMode: true,
|
|
36
|
-
read(size) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
XrayTracer = __decorate([
|
|
43
|
-
tag(ServiceDefinitionTagEnum.Tracer),
|
|
44
|
-
injectable()
|
|
45
|
-
], XrayTracer);
|
|
46
|
-
export { XrayTracer };
|
|
47
|
-
//# sourceMappingURL=basic.tracer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basic.tracer.js","sourceRoot":"","sources":["../../../../src/tracers/basic.tracer.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAGhC;;;GAGG;AAGI,IAAM,UAAU,GAAhB,MAAM,UAAU;IAAhB;QACL,sBAAiB,GAAc,IAAI,QAAQ,CAAC;YAC1C,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QACH,oBAAe,GAAc,IAAI,QAAQ,CAAC;YACxC,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QACH,uBAAkB,GAAc,IAAI,QAAQ,CAAC;YAC3C,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QACH,qBAAgB,GAAc,IAAI,QAAQ,CAAC;YACzC,UAAU,EAAE,IAAI;YAChB,IAAI,CAAC,IAAY;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CAAA,CAAA;AAzBY,UAAU;IAFtB,GAAG,CAAC,wBAAwB,CAAC,MAAM,CAAC;IACpC,UAAU,EAAE;GACA,UAAU,CAyBtB"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Readable } from "stream";
|
|
2
|
-
import { TracerInterface } from "../interfaces/tracer.interface";
|
|
3
|
-
/**
|
|
4
|
-
* We need this to have at least one tracer so the @injectAll(ServiceDefinitionTagEnum.Tracer) does not fail
|
|
5
|
-
* Until there's a fix for: https://github.com/microsoft/tsyringe/issues/63
|
|
6
|
-
*/
|
|
7
|
-
export declare class XrayTracer implements TracerInterface {
|
|
8
|
-
spanStartedStream?: Readable;
|
|
9
|
-
spanEndedStream?: Readable;
|
|
10
|
-
traceStartedStream?: Readable;
|
|
11
|
-
traceEndedStream?: Readable;
|
|
12
|
-
}
|