@raymondfox/ts-toolbox 1.0.0 → 1.1.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.
Files changed (74) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/tracer/core/IdGenerator.d.ts +12 -0
  6. package/dist/tracer/core/IdGenerator.d.ts.map +1 -0
  7. package/dist/tracer/core/IdGenerator.js +38 -0
  8. package/dist/tracer/core/IdGenerator.js.map +1 -0
  9. package/dist/tracer/core/SpanImpl.d.ts +29 -0
  10. package/dist/tracer/core/SpanImpl.d.ts.map +1 -0
  11. package/dist/tracer/core/SpanImpl.js +107 -0
  12. package/dist/tracer/core/SpanImpl.js.map +1 -0
  13. package/dist/tracer/core/TraceContextManager.d.ts +14 -0
  14. package/dist/tracer/core/TraceContextManager.d.ts.map +1 -0
  15. package/dist/tracer/core/TraceContextManager.js +22 -0
  16. package/dist/tracer/core/TraceContextManager.js.map +1 -0
  17. package/dist/tracer/core/Tracer.d.ts +32 -0
  18. package/dist/tracer/core/Tracer.d.ts.map +1 -0
  19. package/dist/tracer/core/Tracer.js +85 -0
  20. package/dist/tracer/core/Tracer.js.map +1 -0
  21. package/dist/tracer/decorators/Trace.d.ts +23 -0
  22. package/dist/tracer/decorators/Trace.d.ts.map +1 -0
  23. package/dist/tracer/decorators/Trace.js +110 -0
  24. package/dist/tracer/decorators/Trace.js.map +1 -0
  25. package/dist/tracer/exporters/BatchSpanProcessor.d.ts +38 -0
  26. package/dist/tracer/exporters/BatchSpanProcessor.d.ts.map +1 -0
  27. package/dist/tracer/exporters/BatchSpanProcessor.js +93 -0
  28. package/dist/tracer/exporters/BatchSpanProcessor.js.map +1 -0
  29. package/dist/tracer/exporters/ConsoleSpanExporter.d.ts +6 -0
  30. package/dist/tracer/exporters/ConsoleSpanExporter.d.ts.map +1 -0
  31. package/dist/tracer/exporters/ConsoleSpanExporter.js +17 -0
  32. package/dist/tracer/exporters/ConsoleSpanExporter.js.map +1 -0
  33. package/dist/tracer/exporters/MonitorExporter.d.ts +30 -0
  34. package/dist/tracer/exporters/MonitorExporter.d.ts.map +1 -0
  35. package/dist/tracer/exporters/MonitorExporter.js +53 -0
  36. package/dist/tracer/exporters/MonitorExporter.js.map +1 -0
  37. package/dist/tracer/exporters/TraceExporter.d.ts +12 -0
  38. package/dist/tracer/exporters/TraceExporter.d.ts.map +1 -0
  39. package/dist/tracer/exporters/TraceExporter.js +3 -0
  40. package/dist/tracer/exporters/TraceExporter.js.map +1 -0
  41. package/dist/tracer/index.d.ts +22 -0
  42. package/dist/tracer/index.d.ts.map +1 -0
  43. package/dist/tracer/index.js +41 -0
  44. package/dist/tracer/index.js.map +1 -0
  45. package/dist/tracer/instrumentations/HttpTracer.d.ts +33 -0
  46. package/dist/tracer/instrumentations/HttpTracer.d.ts.map +1 -0
  47. package/dist/tracer/instrumentations/HttpTracer.js +123 -0
  48. package/dist/tracer/instrumentations/HttpTracer.js.map +1 -0
  49. package/dist/tracer/types/Span.d.ts +24 -0
  50. package/dist/tracer/types/Span.d.ts.map +1 -0
  51. package/dist/tracer/types/Span.js +3 -0
  52. package/dist/tracer/types/Span.js.map +1 -0
  53. package/dist/tracer/types/SpanContext.d.ts +11 -0
  54. package/dist/tracer/types/SpanContext.d.ts.map +1 -0
  55. package/dist/tracer/types/SpanContext.js +3 -0
  56. package/dist/tracer/types/SpanContext.js.map +1 -0
  57. package/dist/tracer/types/SpanData.d.ts +28 -0
  58. package/dist/tracer/types/SpanData.d.ts.map +1 -0
  59. package/dist/tracer/types/SpanData.js +3 -0
  60. package/dist/tracer/types/SpanData.js.map +1 -0
  61. package/dist/tracer/types/SpanKind.d.ts +2 -0
  62. package/dist/tracer/types/SpanKind.d.ts.map +1 -0
  63. package/dist/tracer/types/SpanKind.js +3 -0
  64. package/dist/tracer/types/SpanKind.js.map +1 -0
  65. package/dist/tracer/types/SpanStatus.d.ts +2 -0
  66. package/dist/tracer/types/SpanStatus.d.ts.map +1 -0
  67. package/dist/tracer/types/SpanStatus.js +3 -0
  68. package/dist/tracer/types/SpanStatus.js.map +1 -0
  69. package/dist/tracer/types/TracerOptions.d.ts +16 -0
  70. package/dist/tracer/types/TracerOptions.d.ts.map +1 -0
  71. package/dist/tracer/types/TracerOptions.js +3 -0
  72. package/dist/tracer/types/TracerOptions.js.map +1 -0
  73. package/package.json +5 -1
  74. package/readme.md +13 -127
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=TracerOptions.js.map
@@ -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.0.0",
3
+ "version": "1.1.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": "",
@@ -46,6 +46,10 @@
46
46
  "./http": {
47
47
  "require": "./dist/http/index.js",
48
48
  "types": "./dist/http/index.d.ts"
49
+ },
50
+ "./tracer": {
51
+ "require": "./dist/tracer/index.js",
52
+ "types": "./dist/tracer/index.d.ts"
49
53
  }
50
54
  },
51
55
  "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
- The resulting trace can then be visualized by the Monitor:
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
- ### Nested Tracing
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
- The decorator automatically creates a span around the method execution.
632
+ This produces a trace tree like:
734
633
 
735
- Decorators are an optional API. The tracer can also be used without decorators through `run()` or explicit spans.
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
- → records information
832
-
833
- Tracer
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 can integrate with the Logger, but it should remain independent from the logging implementation.
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