@raymondfox/ts-toolbox 1.0.0 → 1.2.0
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/socket/browser.d.ts +4 -0
- package/dist/socket/browser.d.ts.map +1 -0
- package/dist/socket/browser.js +12 -0
- package/dist/socket/browser.js.map +1 -0
- package/dist/socket/node.d.ts +5 -0
- package/dist/socket/node.d.ts.map +1 -0
- package/dist/socket/node.js +12 -0
- package/dist/socket/node.js.map +1 -0
- package/dist/tracer/core/IdGenerator.d.ts +12 -0
- package/dist/tracer/core/IdGenerator.d.ts.map +1 -0
- package/dist/tracer/core/IdGenerator.js +38 -0
- package/dist/tracer/core/IdGenerator.js.map +1 -0
- package/dist/tracer/core/SpanImpl.d.ts +29 -0
- package/dist/tracer/core/SpanImpl.d.ts.map +1 -0
- package/dist/tracer/core/SpanImpl.js +107 -0
- package/dist/tracer/core/SpanImpl.js.map +1 -0
- package/dist/tracer/core/TraceContextManager.d.ts +14 -0
- package/dist/tracer/core/TraceContextManager.d.ts.map +1 -0
- package/dist/tracer/core/TraceContextManager.js +22 -0
- package/dist/tracer/core/TraceContextManager.js.map +1 -0
- package/dist/tracer/core/Tracer.d.ts +32 -0
- package/dist/tracer/core/Tracer.d.ts.map +1 -0
- package/dist/tracer/core/Tracer.js +85 -0
- package/dist/tracer/core/Tracer.js.map +1 -0
- package/dist/tracer/decorators/Trace.d.ts +23 -0
- package/dist/tracer/decorators/Trace.d.ts.map +1 -0
- package/dist/tracer/decorators/Trace.js +110 -0
- package/dist/tracer/decorators/Trace.js.map +1 -0
- package/dist/tracer/exporters/BatchSpanProcessor.d.ts +38 -0
- package/dist/tracer/exporters/BatchSpanProcessor.d.ts.map +1 -0
- package/dist/tracer/exporters/BatchSpanProcessor.js +93 -0
- package/dist/tracer/exporters/BatchSpanProcessor.js.map +1 -0
- package/dist/tracer/exporters/ConsoleSpanExporter.d.ts +6 -0
- package/dist/tracer/exporters/ConsoleSpanExporter.d.ts.map +1 -0
- package/dist/tracer/exporters/ConsoleSpanExporter.js +17 -0
- package/dist/tracer/exporters/ConsoleSpanExporter.js.map +1 -0
- package/dist/tracer/exporters/MonitorExporter.d.ts +30 -0
- package/dist/tracer/exporters/MonitorExporter.d.ts.map +1 -0
- package/dist/tracer/exporters/MonitorExporter.js +53 -0
- package/dist/tracer/exporters/MonitorExporter.js.map +1 -0
- package/dist/tracer/exporters/TraceExporter.d.ts +12 -0
- package/dist/tracer/exporters/TraceExporter.d.ts.map +1 -0
- package/dist/tracer/exporters/TraceExporter.js +3 -0
- package/dist/tracer/exporters/TraceExporter.js.map +1 -0
- package/dist/tracer/index.d.ts +22 -0
- package/dist/tracer/index.d.ts.map +1 -0
- package/dist/tracer/index.js +41 -0
- package/dist/tracer/index.js.map +1 -0
- package/dist/tracer/instrumentations/HttpTracer.d.ts +33 -0
- package/dist/tracer/instrumentations/HttpTracer.d.ts.map +1 -0
- package/dist/tracer/instrumentations/HttpTracer.js +123 -0
- package/dist/tracer/instrumentations/HttpTracer.js.map +1 -0
- package/dist/tracer/types/Span.d.ts +24 -0
- package/dist/tracer/types/Span.d.ts.map +1 -0
- package/dist/tracer/types/Span.js +3 -0
- package/dist/tracer/types/Span.js.map +1 -0
- package/dist/tracer/types/SpanContext.d.ts +11 -0
- package/dist/tracer/types/SpanContext.d.ts.map +1 -0
- package/dist/tracer/types/SpanContext.js +3 -0
- package/dist/tracer/types/SpanContext.js.map +1 -0
- package/dist/tracer/types/SpanData.d.ts +28 -0
- package/dist/tracer/types/SpanData.d.ts.map +1 -0
- package/dist/tracer/types/SpanData.js +3 -0
- package/dist/tracer/types/SpanData.js.map +1 -0
- package/dist/tracer/types/SpanKind.d.ts +2 -0
- package/dist/tracer/types/SpanKind.d.ts.map +1 -0
- package/dist/tracer/types/SpanKind.js +3 -0
- package/dist/tracer/types/SpanKind.js.map +1 -0
- package/dist/tracer/types/SpanStatus.d.ts +2 -0
- package/dist/tracer/types/SpanStatus.d.ts.map +1 -0
- package/dist/tracer/types/SpanStatus.js +3 -0
- package/dist/tracer/types/SpanStatus.js.map +1 -0
- package/dist/tracer/types/TracerOptions.d.ts +16 -0
- package/dist/tracer/types/TracerOptions.d.ts.map +1 -0
- package/dist/tracer/types/TracerOptions.js +3 -0
- package/dist/tracer/types/TracerOptions.js.map +1 -0
- package/package.json +31 -7
- package/readme.md +13 -127
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpanData.js","sourceRoot":"","sources":["../../../src/tracer/types/SpanData.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpanKind.d.ts","sourceRoot":"","sources":["../../../src/tracer/types/SpanKind.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpanKind.js","sourceRoot":"","sources":["../../../src/tracer/types/SpanKind.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpanStatus.d.ts","sourceRoot":"","sources":["../../../src/tracer/types/SpanStatus.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpanStatus.js","sourceRoot":"","sources":["../../../src/tracer/types/SpanStatus.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TraceExporter } from '../exporters/TraceExporter';
|
|
2
|
+
export interface TracerOptions {
|
|
3
|
+
/** Name of the application/service emitting traces (e.g., 'TanamaoPDV'). */
|
|
4
|
+
serviceName?: string;
|
|
5
|
+
/** Array of exporters to deliver completed spans to. */
|
|
6
|
+
exporters?: TraceExporter[];
|
|
7
|
+
/** Whether tracing is enabled. Defaults to true. */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** Maximum queue size for batching spans in memory. Defaults to 5000. */
|
|
10
|
+
maxQueueSize?: number;
|
|
11
|
+
/** Flush interval in milliseconds for exporting spans. Defaults to 1000ms. */
|
|
12
|
+
flushIntervalMs?: number;
|
|
13
|
+
/** Maximum batch size per export call. Defaults to 100. */
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=TracerOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TracerOptions.d.ts","sourceRoot":"","sources":["../../../src/tracer/types/TracerOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,WAAW,aAAa;IAC1B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;IAC5B,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TracerOptions.js","sourceRoot":"","sources":["../../../src/tracer/types/TracerOptions.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raymondfox/ts-toolbox",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A strongly-typed TypeScript utility toolkit for Node.js — Logger, Socket, HTTP, Retry and Timeout",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -24,28 +24,52 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
27
28
|
"require": "./dist/index.js",
|
|
28
|
-
"
|
|
29
|
+
"import": "./dist/index.js"
|
|
29
30
|
},
|
|
30
31
|
"./logger": {
|
|
32
|
+
"types": "./dist/logger/index.d.ts",
|
|
31
33
|
"require": "./dist/logger/index.js",
|
|
32
|
-
"
|
|
34
|
+
"import": "./dist/logger/index.js"
|
|
33
35
|
},
|
|
34
36
|
"./socket": {
|
|
37
|
+
"types": "./dist/socket/index.d.ts",
|
|
38
|
+
"browser": "./dist/socket/browser.js",
|
|
35
39
|
"require": "./dist/socket/index.js",
|
|
36
|
-
"
|
|
40
|
+
"import": "./dist/socket/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./socket/browser": {
|
|
43
|
+
"types": "./dist/socket/browser.d.ts",
|
|
44
|
+
"require": "./dist/socket/browser.js",
|
|
45
|
+
"import": "./dist/socket/browser.js",
|
|
46
|
+
"default": "./dist/socket/browser.js"
|
|
47
|
+
},
|
|
48
|
+
"./socket/node": {
|
|
49
|
+
"types": "./dist/socket/node.d.ts",
|
|
50
|
+
"require": "./dist/socket/node.js",
|
|
51
|
+
"import": "./dist/socket/node.js",
|
|
52
|
+
"default": "./dist/socket/node.js"
|
|
37
53
|
},
|
|
38
54
|
"./retry": {
|
|
55
|
+
"types": "./dist/retry/index.d.ts",
|
|
39
56
|
"require": "./dist/retry/index.js",
|
|
40
|
-
"
|
|
57
|
+
"import": "./dist/retry/index.js"
|
|
41
58
|
},
|
|
42
59
|
"./timeout": {
|
|
60
|
+
"types": "./dist/timeout/index.d.ts",
|
|
43
61
|
"require": "./dist/timeout/index.js",
|
|
44
|
-
"
|
|
62
|
+
"import": "./dist/timeout/index.js"
|
|
45
63
|
},
|
|
46
64
|
"./http": {
|
|
65
|
+
"types": "./dist/http/index.d.ts",
|
|
47
66
|
"require": "./dist/http/index.js",
|
|
48
|
-
"
|
|
67
|
+
"import": "./dist/http/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./tracer": {
|
|
70
|
+
"types": "./dist/tracer/index.d.ts",
|
|
71
|
+
"require": "./dist/tracer/index.js",
|
|
72
|
+
"import": "./dist/tracer/index.js"
|
|
49
73
|
}
|
|
50
74
|
},
|
|
51
75
|
"files": [
|
package/readme.md
CHANGED
|
@@ -590,34 +590,8 @@ Trace
|
|
|
590
590
|
|
|
591
591
|
Unlike a `Transport`, which defines **where** data is sent, or a `Formatter`, which defines **how** data is represented, instrumentation is responsible for describing **what happened during an operation**.
|
|
592
592
|
|
|
593
|
-
```text
|
|
594
|
-
Tracer
|
|
595
|
-
│
|
|
596
|
-
│ creates and tracks
|
|
597
|
-
▼
|
|
598
|
-
Trace / Span
|
|
599
|
-
│
|
|
600
|
-
▼
|
|
601
|
-
Logger
|
|
602
|
-
│
|
|
603
|
-
├── ConsoleTransport
|
|
604
|
-
├── FileTransport
|
|
605
|
-
└── MonitorTransport
|
|
606
|
-
```
|
|
607
|
-
|
|
608
593
|
### Traces and Spans
|
|
609
594
|
|
|
610
|
-
A trace can contain multiple nested spans.
|
|
611
|
-
|
|
612
|
-
For example, processing an order might consist of:
|
|
613
|
-
|
|
614
|
-
```text
|
|
615
|
-
enviar-pedido
|
|
616
|
-
├── montar-payload
|
|
617
|
-
├── consultar-estoque
|
|
618
|
-
└── enviar-api
|
|
619
|
-
```
|
|
620
|
-
|
|
621
595
|
Each span can contain information such as:
|
|
622
596
|
|
|
623
597
|
* operation name
|
|
@@ -630,83 +604,9 @@ Each span can contain information such as:
|
|
|
630
604
|
* custom attributes
|
|
631
605
|
* metadata
|
|
632
606
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
```text
|
|
636
|
-
enviar-pedido 184ms
|
|
637
|
-
├── montar-payload 12ms
|
|
638
|
-
├── consultar-estoque 31ms
|
|
639
|
-
└── enviar-api ERROR
|
|
640
|
-
```
|
|
641
|
-
|
|
642
|
-
### Simple Tracing
|
|
643
|
-
|
|
644
|
-
For small operations, the `run()` API can be used:
|
|
645
|
-
|
|
646
|
-
```ts
|
|
647
|
-
await tracer.run('montar-payload', () => {
|
|
648
|
-
return buildPayload(order);
|
|
649
|
-
});
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
The tracer automatically measures the operation and records its success or failure.
|
|
607
|
+
### Usage
|
|
653
608
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
Traces can be nested without manually passing parent information.
|
|
657
|
-
|
|
658
|
-
```ts
|
|
659
|
-
await tracer.run('enviar-pedido', async () => {
|
|
660
|
-
|
|
661
|
-
const payload = await tracer.run(
|
|
662
|
-
'montar-payload',
|
|
663
|
-
() => buildPayload(order)
|
|
664
|
-
);
|
|
665
|
-
|
|
666
|
-
return tracer.run(
|
|
667
|
-
'enviar-api',
|
|
668
|
-
() => api.send(payload)
|
|
669
|
-
);
|
|
670
|
-
});
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
The tracer can automatically associate nested operations with their parent:
|
|
674
|
-
|
|
675
|
-
```text
|
|
676
|
-
enviar-pedido
|
|
677
|
-
├── montar-payload
|
|
678
|
-
└── enviar-api
|
|
679
|
-
```
|
|
680
|
-
|
|
681
|
-
In Node.js, execution context can be maintained automatically so that nested operations do not need to explicitly receive a parent span.
|
|
682
|
-
|
|
683
|
-
### Manual Spans
|
|
684
|
-
|
|
685
|
-
For operations that require more control, a span can be created explicitly:
|
|
686
|
-
|
|
687
|
-
```ts
|
|
688
|
-
const span = tracer.start('enviar-pedido');
|
|
689
|
-
|
|
690
|
-
try {
|
|
691
|
-
const payload = await span.run(
|
|
692
|
-
'montar-payload',
|
|
693
|
-
() => buildPayload(order)
|
|
694
|
-
);
|
|
695
|
-
|
|
696
|
-
return await span.run(
|
|
697
|
-
'enviar-api',
|
|
698
|
-
() => api.send(payload)
|
|
699
|
-
);
|
|
700
|
-
} finally {
|
|
701
|
-
span.end();
|
|
702
|
-
}
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
This allows applications to control the lifetime of long-running operations while still preserving nested spans.
|
|
706
|
-
|
|
707
|
-
### Decorators
|
|
708
|
-
|
|
709
|
-
For class methods, tracing can optionally be applied through decorators:
|
|
609
|
+
Tracing is applied through the `@Trace()` decorator on class methods. The decorator automatically creates a span around the method and associates nested calls with their parent via async context (`AsyncLocalStorage`) — no manual wiring needed.
|
|
710
610
|
|
|
711
611
|
```ts
|
|
712
612
|
class OrderService {
|
|
@@ -714,7 +614,6 @@ class OrderService {
|
|
|
714
614
|
@Trace()
|
|
715
615
|
async enviarPedido(order: Order) {
|
|
716
616
|
const payload = await this.montarPayload(order);
|
|
717
|
-
|
|
718
617
|
return this.enviarApi(payload);
|
|
719
618
|
}
|
|
720
619
|
|
|
@@ -730,9 +629,13 @@ class OrderService {
|
|
|
730
629
|
}
|
|
731
630
|
```
|
|
732
631
|
|
|
733
|
-
|
|
632
|
+
This produces a trace tree like:
|
|
734
633
|
|
|
735
|
-
|
|
634
|
+
```text
|
|
635
|
+
enviar-pedido 184ms
|
|
636
|
+
├── montar-payload 12ms
|
|
637
|
+
└── enviar-api 141ms ERROR
|
|
638
|
+
```
|
|
736
639
|
|
|
737
640
|
### HTTP Tracing
|
|
738
641
|
|
|
@@ -824,31 +727,14 @@ This makes it possible to identify not only **that an operation failed**, but al
|
|
|
824
727
|
|
|
825
728
|
### Instrumentation vs Logger
|
|
826
729
|
|
|
827
|
-
Tracing and logging have different responsibilities:
|
|
828
|
-
|
|
829
730
|
```text
|
|
830
|
-
Logger
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
→ records execution flow
|
|
835
|
-
|
|
836
|
-
Trace
|
|
837
|
-
→ represents a complete operation
|
|
838
|
-
|
|
839
|
-
Span
|
|
840
|
-
→ represents one operation within a trace
|
|
841
|
-
|
|
842
|
-
Formatter
|
|
843
|
-
→ formats information
|
|
844
|
-
|
|
845
|
-
Transport
|
|
846
|
-
→ sends information
|
|
731
|
+
Logger → records information
|
|
732
|
+
Tracer → records execution flow
|
|
733
|
+
Trace → represents a complete operation
|
|
734
|
+
Span → represents one step within a trace
|
|
847
735
|
```
|
|
848
736
|
|
|
849
|
-
A tracer
|
|
850
|
-
|
|
851
|
-
This allows the same instrumentation data to be consumed by the Console, File, Monitor, or other integrations without coupling the core tracer to a specific destination.
|
|
737
|
+
A tracer integrates with the Logger but remains independent from the logging implementation, allowing the same instrumentation data to be consumed by Console, File, Monitor or any other transport.
|
|
852
738
|
|
|
853
739
|
### Future Instrumentation
|
|
854
740
|
|