@oas-tools/oas-telemetry 0.7.0-alpha.2 → 0.7.0-alpha.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.
Files changed (158) hide show
  1. package/.env.example +50 -17
  2. package/README.md +244 -239
  3. package/dist/cjs/config/bootConfig.cjs +18 -0
  4. package/dist/cjs/config/config.cjs +145 -0
  5. package/dist/cjs/config/config.types.cjs +5 -0
  6. package/dist/cjs/index.cjs +19 -25
  7. package/dist/cjs/{tlmRoutes.cjs → routesManager.cjs} +28 -21
  8. package/dist/cjs/{exporters/InMemoryLogRecordExporter.cjs → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.cjs} +42 -19
  9. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.cjs +97 -0
  10. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.cjs +118 -0
  11. package/dist/cjs/telemetry/custom-implementations/exporters/PluginLogExporter.cjs +45 -0
  12. package/dist/cjs/telemetry/custom-implementations/exporters/PluginMetricExporter.cjs +46 -0
  13. package/dist/cjs/telemetry/custom-implementations/exporters/PluginSpanExporter.cjs +61 -0
  14. package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.cjs +70 -0
  15. package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.cjs +70 -0
  16. package/dist/cjs/{utils → telemetry/custom-implementations/utils}/circular.cjs +39 -49
  17. package/dist/cjs/telemetry/custom-implementations/wrappers.cjs +175 -0
  18. package/dist/cjs/telemetry/initializeTelemetry.cjs +74 -0
  19. package/dist/cjs/telemetry/telemetryConfigurator.cjs +84 -0
  20. package/dist/cjs/telemetry/telemetryRegistry.cjs +40 -0
  21. package/dist/cjs/tlm-ai/agent.cjs +82 -63
  22. package/dist/cjs/tlm-ai/aiController.cjs +5 -4
  23. package/dist/cjs/tlm-ai/aiRoutes.cjs +9 -6
  24. package/dist/cjs/tlm-ai/tools.cjs +16 -9
  25. package/dist/cjs/tlm-auth/authController.cjs +14 -15
  26. package/dist/cjs/tlm-auth/authMiddleware.cjs +11 -10
  27. package/dist/cjs/tlm-auth/authRoutes.cjs +9 -7
  28. package/dist/cjs/tlm-log/logController.cjs +45 -18
  29. package/dist/cjs/tlm-log/logRoutes.cjs +16 -11
  30. package/dist/cjs/tlm-metric/metricsController.cjs +37 -12
  31. package/dist/cjs/tlm-metric/metricsRoutes.cjs +16 -11
  32. package/dist/cjs/tlm-plugin/pluginController.cjs +114 -75
  33. package/dist/cjs/tlm-plugin/pluginProcess.cjs +108 -0
  34. package/dist/cjs/tlm-plugin/pluginRoutes.cjs +11 -6
  35. package/dist/cjs/tlm-plugin/pluginService.cjs +79 -0
  36. package/dist/cjs/tlm-trace/traceController.cjs +54 -45
  37. package/dist/cjs/tlm-trace/traceRoutes.cjs +16 -11
  38. package/dist/cjs/tlm-ui/uiRoutes.cjs +26 -20
  39. package/dist/cjs/tlm-util/utilController.cjs +8 -9
  40. package/dist/cjs/tlm-util/utilRoutes.cjs +22 -19
  41. package/dist/cjs/types/index.cjs +0 -1
  42. package/dist/cjs/utils/logger.cjs +3 -5
  43. package/dist/cjs/utils/regexUtils.cjs +27 -0
  44. package/dist/esm/config/bootConfig.js +11 -0
  45. package/dist/esm/config/config.js +126 -0
  46. package/dist/esm/index.js +18 -29
  47. package/dist/esm/{tlmRoutes.js → routesManager.js} +27 -22
  48. package/dist/esm/{exporters/InMemoryLogRecordExporter.js → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.js} +31 -17
  49. package/dist/esm/{exporters/InMemoryDBMetricsExporter.js → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.js} +31 -17
  50. package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.js +105 -0
  51. package/dist/esm/telemetry/custom-implementations/exporters/PluginLogExporter.js +36 -0
  52. package/dist/esm/telemetry/custom-implementations/exporters/PluginMetricExporter.js +35 -0
  53. package/dist/esm/telemetry/custom-implementations/exporters/PluginSpanExporter.js +52 -0
  54. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.js +64 -0
  55. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.js +64 -0
  56. package/dist/esm/telemetry/custom-implementations/utils/circular.js +76 -0
  57. package/dist/esm/telemetry/custom-implementations/wrappers.js +163 -0
  58. package/dist/esm/telemetry/initializeTelemetry.js +71 -0
  59. package/dist/esm/telemetry/telemetryConfigurator.js +74 -0
  60. package/dist/esm/telemetry/telemetryRegistry.js +34 -0
  61. package/dist/esm/tlm-ai/agent.js +77 -59
  62. package/dist/esm/tlm-ai/aiController.js +5 -4
  63. package/dist/esm/tlm-ai/aiRoutes.js +7 -5
  64. package/dist/esm/tlm-ai/tools.js +18 -9
  65. package/dist/esm/tlm-auth/authController.js +9 -10
  66. package/dist/esm/tlm-auth/authMiddleware.js +10 -9
  67. package/dist/esm/tlm-auth/authRoutes.js +8 -6
  68. package/dist/esm/tlm-log/logController.js +36 -16
  69. package/dist/esm/tlm-log/logRoutes.js +15 -11
  70. package/dist/esm/tlm-metric/metricsController.js +29 -10
  71. package/dist/esm/tlm-metric/metricsRoutes.js +15 -11
  72. package/dist/esm/tlm-plugin/pluginController.js +112 -77
  73. package/dist/esm/tlm-plugin/pluginProcess.js +101 -0
  74. package/dist/esm/tlm-plugin/pluginRoutes.js +10 -6
  75. package/dist/esm/tlm-plugin/pluginService.js +73 -0
  76. package/dist/esm/tlm-trace/traceController.js +40 -35
  77. package/dist/esm/tlm-trace/traceRoutes.js +15 -11
  78. package/dist/esm/tlm-ui/uiRoutes.js +24 -19
  79. package/dist/esm/tlm-util/utilController.js +8 -9
  80. package/dist/esm/tlm-util/utilRoutes.js +17 -15
  81. package/dist/esm/types/index.js +0 -1
  82. package/dist/esm/utils/logger.js +3 -4
  83. package/dist/esm/utils/regexUtils.js +23 -0
  84. package/dist/types/config/bootConfig.d.ts +5 -0
  85. package/dist/types/config/config.d.ts +858 -0
  86. package/dist/types/config/config.types.d.ts +34 -0
  87. package/dist/types/index.d.ts +5 -4
  88. package/dist/types/routesManager.d.ts +3 -0
  89. package/dist/types/{exporters/InMemoryLogRecordExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.d.ts} +6 -6
  90. package/dist/types/{exporters/InMemoryDBMetricsExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.d.ts} +7 -7
  91. package/dist/types/{exporters/InMemoryDbExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.d.ts} +9 -9
  92. package/dist/types/telemetry/custom-implementations/exporters/PluginLogExporter.d.ts +8 -0
  93. package/dist/types/telemetry/custom-implementations/exporters/PluginMetricExporter.d.ts +12 -0
  94. package/dist/types/telemetry/custom-implementations/exporters/PluginSpanExporter.d.ts +14 -0
  95. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.d.ts +32 -0
  96. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.d.ts +34 -0
  97. package/dist/types/telemetry/custom-implementations/utils/circular.d.ts +27 -0
  98. package/dist/types/telemetry/custom-implementations/wrappers.d.ts +52 -0
  99. package/dist/types/telemetry/initializeTelemetry.d.ts +1 -0
  100. package/dist/types/telemetry/telemetryConfigurator.d.ts +2 -0
  101. package/dist/types/telemetry/telemetryRegistry.d.ts +20 -0
  102. package/dist/types/tlm-ai/agent.d.ts +2 -1
  103. package/dist/types/tlm-ai/aiController.d.ts +4 -3
  104. package/dist/types/tlm-ai/aiRoutes.d.ts +2 -2
  105. package/dist/types/tlm-ai/tools.d.ts +3 -1
  106. package/dist/types/tlm-auth/authController.d.ts +4 -3
  107. package/dist/types/tlm-auth/authMiddleware.d.ts +2 -1
  108. package/dist/types/tlm-auth/authRoutes.d.ts +2 -2
  109. package/dist/types/tlm-log/logController.d.ts +1 -0
  110. package/dist/types/tlm-log/logRoutes.d.ts +2 -2
  111. package/dist/types/tlm-metric/metricsController.d.ts +1 -0
  112. package/dist/types/tlm-metric/metricsRoutes.d.ts +2 -2
  113. package/dist/types/tlm-plugin/pluginController.d.ts +4 -1
  114. package/dist/types/tlm-plugin/pluginProcess.d.ts +1 -0
  115. package/dist/types/tlm-plugin/pluginRoutes.d.ts +1 -2
  116. package/dist/types/tlm-plugin/pluginService.d.ts +24 -0
  117. package/dist/types/tlm-trace/traceController.d.ts +7 -6
  118. package/dist/types/tlm-trace/traceRoutes.d.ts +2 -2
  119. package/dist/types/tlm-ui/uiRoutes.d.ts +1 -2
  120. package/dist/types/tlm-util/utilController.d.ts +2 -1
  121. package/dist/types/tlm-util/utilRoutes.d.ts +2 -2
  122. package/dist/types/types/index.d.ts +17 -47
  123. package/dist/types/utils/regexUtils.d.ts +1 -0
  124. package/dist/ui/assets/index-BzIdRox6.js +1733 -0
  125. package/dist/ui/assets/index-CkoHzrrt.css +1 -0
  126. package/dist/ui/index.html +3 -3
  127. package/dist/ui/oas-tlm.svg +185 -0
  128. package/package.json +12 -7
  129. package/dist/cjs/config.cjs +0 -31
  130. package/dist/cjs/exporters/InMemoryDBMetricsExporter.cjs +0 -74
  131. package/dist/cjs/exporters/InMemoryDbExporter.cjs +0 -102
  132. package/dist/cjs/exporters/consoleExporter.cjs +0 -47
  133. package/dist/cjs/exporters/dynamicExporter.cjs +0 -57
  134. package/dist/cjs/instrumentation/index.cjs +0 -28
  135. package/dist/cjs/instrumentation/logs.cjs +0 -46
  136. package/dist/cjs/instrumentation/metrics.cjs +0 -27
  137. package/dist/cjs/instrumentation/traces.cjs +0 -19
  138. package/dist/esm/config.js +0 -20
  139. package/dist/esm/exporters/InMemoryDbExporter.js +0 -102
  140. package/dist/esm/exporters/consoleExporter.js +0 -38
  141. package/dist/esm/exporters/dynamicExporter.js +0 -50
  142. package/dist/esm/instrumentation/index.js +0 -26
  143. package/dist/esm/instrumentation/logs.js +0 -34
  144. package/dist/esm/instrumentation/metrics.js +0 -18
  145. package/dist/esm/instrumentation/traces.js +0 -12
  146. package/dist/esm/utils/circular.js +0 -84
  147. package/dist/types/config.d.ts +0 -6
  148. package/dist/types/exporters/consoleExporter.d.ts +0 -13
  149. package/dist/types/exporters/dynamicExporter.d.ts +0 -25
  150. package/dist/types/instrumentation/logs.d.ts +0 -1
  151. package/dist/types/instrumentation/metrics.d.ts +0 -1
  152. package/dist/types/instrumentation/traces.d.ts +0 -1
  153. package/dist/types/tlmRoutes.d.ts +0 -2
  154. package/dist/types/utils/circular.d.ts +0 -31
  155. package/dist/ui/assets/index-BNhZBPi2.css +0 -1
  156. package/dist/ui/assets/index-DxGAMrAl.js +0 -401
  157. package/dist/ui/vite.svg +0 -1
  158. /package/dist/{types/instrumentation/index.d.ts → esm/config/config.types.js} +0 -0
package/README.md CHANGED
@@ -1,24 +1,21 @@
1
1
  # OAS TELEMETRY
2
2
 
3
- **OAS Telemetry** offers an express middleware designed for collecting telemetry data using **Open Telemetry** in applications built using the **OpenAPI Specification (OAS)**. This middleware allows developers to easily incorporate telemetry functionality into their APIs.
4
3
 
5
- **OAS Telemetry** provides a set of endpoints that can be accessed to perform various actions related to telemetry data, such as starting and stopping data collection, resetting telemetry data, listing collected data, and searching for specific telemetry records. These endpoints can be easily integrated into an **Express.js** application, providing developers with a convenient way to manage and analyze telemetry data.
4
+ **OAS Telemetry** is a library that automatically configures telemetry in your Express application based on OpenAPI, with no extra code required. Simply use the middleware to instantly access endpoints for viewing recent requests, system logs, and metrics—all stored in memory. This allows you to analyze your API’s behavior and debug issues easily, without manual setup or complex integration. OpenTelemetry is used under the hood to collect traces, metrics, and logs.
6
5
 
7
- Additionally, **OAS Telemetry** offers customization options, allowing developers to configure the telemetry middleware according to their specific requirements.
8
-
9
- Overall, **OAS Telemetry** will serve as a valuable tool for developers looking to gain insights into the operation and performance of their **OAS-based APIs**, enabling them to monitor, debug, and optimize their applications effectively.
10
-
11
- The package now supports both **ES Module (ESM)** and **CommonJS (CJS)** formats, making it compatible with a wide range of applications. The ESM build targets the **ES2020** standard. Furthermore, **OAS Telemetry** provides a range of plugins to extend its functionality. See the [Telemetry Plugins](#telemetry-plugins) section for more information.
6
+ The middleware is highly configurable and supports both **ES Module (ESM)** and **CommonJS (CJS)** formats (ESM targeting **ES2020**). Its functionality can be extended via plugins; see [Telemetry Plugins](#telemetry-plugins) for details.
12
7
 
13
8
  > ⚠️ **Warning: Early Development Notice**
14
9
  >
15
10
  > **OAS Telemetry** is a functional and working package, but it is currently at version 0 and remains under active development. Features, APIs, and behavior are subject to change at any time. Please review the following current status before use:
16
11
  >
17
- > - **UI:** Migration to React is in progress. Most views are placeholders except for the AI agent, which is fully functional and can answer questions about metrics, traces, and logs.
18
- > - **Traces:** Semi-stable. Currently supports HTTP instrumentation; future updates will add propagators.
12
+ > - **Traces:** Semi-stable. Currently supports HTTP instrumentation. We are studying switching to auto-instrumentation, but we need to test memory usage and performance first.
19
13
  > - **Logs:** Semi-stable. Supports fast search by message content and Mongo-like search (similar to traces).
20
- > - **Metrics:** Not stable. Currently uses OpenTelemetry host metrics. This area is subject to significant change to improve memory usage and data handling.
21
- > - **Configuration:** Not stable. All configuration options will be available as parameters at initialization and via environment variables (see the `.env.example` file). The configuration system is under active development and will change significantly in future releases.
14
+ > - **Metrics:** Not stable. Currently uses OpenTelemetry host metrics. This area is subject to change to improve memory usage and data handling.
15
+ > - **Configuration:** Semi-stable. All configuration options will be available as parameters at initialization and via environment variables (see the `.env.example` file). The configuration system is under active development and will change significantly in future releases.
16
+ > - **UI:** Not stable. Migration to React is in progress. Most views are placeholders except for the AI agent, which is fully functional and can answer questions about traces, and logs (Not yet for metrics). Plugin management page is also functional. Next steps include logs page (almost done) and traces page (subject to change based on instrumentation approach). Metrics page will be the last to be implemented, as we want to support custom metrics in the future.
17
+ >
18
+ > Please if you want to use this package contact us via motero6@us.es
22
19
 
23
20
  ## Usage
24
21
 
@@ -30,7 +27,7 @@ First, install the package using npm:
30
27
  npm install @oas-tools/oas-telemetry
31
28
  ```
32
29
 
33
- Then add the .env file to your project root directory. This file contains the environment variables used by the telemetry middleware. You can find an example of the .env file in the [`.env.example`](.env.example) file in the root of the repository. The `.env` file is optional, but it is needed for the ai chat.
30
+ Then add the `.env` file to your project root directory. This file contains the environment variables used by the telemetry middleware. You can find an example of the `.env` file in the [`.env.example`](.env.example) file in the root of the repository. The `.env` file is optional, but it is needed for the AI chat.
34
31
 
35
32
  You can integrate the middleware into your Express application. The `spec` option is the OpenAPI Specification (OAS) content in JSON or YAML format. While this configuration is optional, it is recommended for the UI to function correctly.
36
33
 
@@ -41,14 +38,12 @@ Add the following lines to your `index.js` file:
41
38
  ```js
42
39
  // This import MUST be at the top of the file
43
40
  import oasTelemetry from '@oas-tools/oas-telemetry';
44
- import { readFileSync } from 'fs';
45
41
 
46
- // ...rest of your code here creating an express app
42
+ // ...rest of your code here creating an express app and importing the OpenAPI spec
47
43
  // NOTE: Do not add express.json() before oasTelemetry, or set its limit to at least "10mb" to avoid issues with large files.
48
44
 
49
- app.use(oasTelemetry({
50
- spec: readFileSync('./spec/oas.yaml', { encoding: 'utf8', flag: 'r' })
51
- }));
45
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
46
+
52
47
  ```
53
48
 
54
49
  ### Using CommonJS
@@ -58,14 +53,12 @@ Add the following lines to your `index.js` file:
58
53
  ```js
59
54
  // This require MUST be at the top of the file
60
55
  const oasTelemetry = require('@oas-tools/oas-telemetry');
61
- const { readFileSync } = require('fs');
62
56
 
63
- // ...rest of your code here creating an express app
57
+ // ...rest of your code here creating an express app and importing the OpenAPI spec
64
58
  // NOTE: Do not add express.json() before oasTelemetry, or set its limit to at least "10mb" to avoid issues with large files.
65
59
 
66
- app.use(oasTelemetry({
67
- spec: readFileSync('./spec/oas.yaml', { encoding: 'utf8', flag: 'r' })
68
- }));
60
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
61
+
69
62
  ```
70
63
 
71
64
  For complete examples of a working API with OAS Telemetry enabled, refer to the [Full Examples](#full-examples) section at the end of this document.
@@ -74,26 +67,82 @@ For complete examples of a working API with OAS Telemetry enabled, refer to the
74
67
 
75
68
  You can also customize the telemetry configuration by passing options to the middleware function. For example:
76
69
 
70
+ > **Note:** Although you can set configuration options programmatically, it is recommended to use the provided `.env.example` file as a template for your environment variables. Values set in the `.env` file will override any options passed directly to the middleware.
71
+
77
72
  ```js
78
- const customTelemetryConfig = {
79
- spec: /* OAS content in json or yaml */, // Highly recommended
80
- baseURL: "/custom-telemetry", //default is "/telemetry"
81
- autoActivate: false, //default is true, whether to start telemetry data collection automatically
82
- authEnabled: true, //default is false
73
+ export const customTelemetryConfig = {
74
+ general: {
75
+ baseUrl: "/custom-telemetry",
76
+ specFileName: "oas.json",
77
+ spec: null,
78
+ },
79
+
80
+ auth: {
81
+ enabled: true,
83
82
  apiKeyMaxAge: 1000 * 60 * 30, // 30 minutes
84
- password: "custom-password", //default is "oas-telemetry-password"
85
- jwtSecret: "custom-secret", //default is "oas-telemetry-secret"
86
- exporter: myCustomExporter, // Experimental, just for devs
83
+ password: "my-custom-password",
84
+ jwtSecret: "my-super-secret",
85
+ },
86
+
87
+ ai: {
88
+ openAIKey: process.env.YOUR_OPENAI_API_KEY, // Seteable via environment variable
89
+ openAIModel: "gpt-4o",
90
+ extraContextPrompts: [
91
+ "Provide clear, concise answers",
92
+ "Use professional tone",
93
+ ],
94
+ },
95
+
96
+ traces: {
97
+ extraExporters: [],
98
+ extraProcessors: [],
99
+ mainProcessorOptions: {
100
+ config: undefined,
101
+ },
102
+ memoryExporter: {
103
+ enabled: true,
104
+ retentionTime: 1000 * 60 * 120, // 2 hours
105
+ },
106
+ filters: [],
107
+ },
108
+
109
+ metrics: {
110
+ mainMetricReaderOptions: {
111
+ exportIntervalMillis: 1000 * 60,
112
+ metricProducers: [],
113
+ },
114
+ extraReaders: [],
115
+ memoryExporter: {
116
+ enabled: true,
117
+ retentionTime: 1000 * 60 * 120, // 2 hours
118
+ },
119
+ filters: [],
120
+ },
121
+
122
+ logs: {
123
+ extraExporters: [],
124
+ extraProcessors: [],
125
+ memoryExporter: {
126
+ enabled: true,
127
+ retentionTime: 1000 * 60 * 120, // 2 hours
128
+ },
129
+ filters: [],
130
+ },
131
+
132
+ plugins: {
133
+ enabled: true,
134
+ extraPlugins: [],
135
+ },
87
136
  };
88
137
 
89
138
  app.use(oasTelemetry(customTelemetryConfig));
90
139
  ```
91
140
 
92
- **Note:** To disable the module, set the environment variable `OASTLM_MODULE_DISABLED` to `'true'`.
141
+ **Note:** To disable the module, set the environment variable `OASTLM_BOOT_MODULE_DISABLED` to `'true'`.
93
142
 
94
143
  ## Telemetry UI
95
144
 
96
- You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-telemetry` if you set the `baseURL` option). This UI provides a user-friendly interface to interact with the telemetry data collected by the middleware.
145
+ You can access the telemetry UI at the endpoint `/telemetry` (or `/custom-telemetry` if you set the `baseURL` option). This UI provides a user-friendly interface to interact with the telemetry data collected by the middleware.
97
146
 
98
147
  ## Rest API Endpoints Overview
99
148
 
@@ -108,30 +157,30 @@ You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-teleme
108
157
  - `GET /metrics`: List all metrics.
109
158
  - `POST /metrics`: Insert metrics into the database.
110
159
  - `POST /metrics/find`: Search metrics.
111
- - `GET /metrics/start`: Start metrics data collection.
112
- - `GET /metrics/stop`: Stop metrics data collection.
160
+ - `POST /metrics/start`: Start metrics data collection.
161
+ - `POST /metrics/stop`: Stop metrics data collection.
113
162
  - `GET /metrics/status`: Get metrics status.
114
- - `GET /metrics/reset`: Reset metrics data.
163
+ - `POST /metrics/reset`: Reset metrics data.
115
164
 
116
165
  ### Logs Endpoints
117
166
 
118
167
  - `GET /logs`: List all logs.
119
168
  - `POST /logs`: Insert logs into the database.
120
169
  - `POST /logs/find`: Search logs.
121
- - `GET /logs/start`: Start logs data collection.
122
- - `GET /logs/stop`: Stop logs data collection.
170
+ - `POST /logs/start`: Start logs data collection.
171
+ - `POST /logs/stop`: Stop logs data collection.
123
172
  - `GET /logs/status`: Get logs status.
124
- - `GET /logs/reset`: Reset logs data.
173
+ - `POST /logs/reset`: Reset logs data.
125
174
 
126
175
  ### Traces Endpoints
127
176
 
128
177
  - `GET /traces`: List all traces.
129
178
  - `POST /traces`: Insert traces into the database.
130
179
  - `POST /traces/find`: Search traces.
131
- - `GET /traces/start`: Start traces data collection.
132
- - `GET /traces/stop`: Stop traces data collection.
180
+ - `POST /traces/start`: Start traces data collection.
181
+ - `POST /traces/stop`: Stop traces data collection.
133
182
  - `GET /traces/status`: Get traces status.
134
- - `GET /traces/reset`: Reset traces data.
183
+ - `POST /traces/reset`: Reset traces data.
135
184
 
136
185
  ### AI Endpoints
137
186
 
@@ -139,9 +188,10 @@ You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-teleme
139
188
  - `POST /ai/microservices`: Configure known microservices.
140
189
  - `GET /ai/microservices`: Retrieve the list of known microservices.
141
190
 
142
- ### UI Endpoints
191
+ ### Plugins Endpoints
143
192
 
144
- - `GET *`: Serve the telemetry UI.
193
+ - `GET /plugins/list`: List all registered plugins.
194
+ - `POST /plugins/register`: Register a new plugin.
145
195
 
146
196
  ### Utility Endpoints
147
197
 
@@ -149,59 +199,12 @@ You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-teleme
149
199
  - `GET /utils/heapStats`: Show v8 heap statistics.
150
200
  - `GET /utils/generateLog`: Generate a log message.
151
201
  - `GET /utils/wait/:seconds?`: Wait for a specified number of seconds.
152
-
153
- ## Metrics Development (Temporary)
154
-
155
- This feature is currently in development. The following endpoints are available under \<baseURL>/metrics (e.g., /telemetry/metrics):
156
-
157
- - GET /
158
- - POST /find
159
- - GET /reset
160
-
161
- Expect an array of metrics objects. Each object includes data like a timestamp, cpuUsageData, processCpuUsageData, memoryData, and processMemoryData. Example snippet for one CPU core (followed by others in the array):
162
-
163
- > **Warning**
164
- > Stored metrics data now uses `@opentelemetry/host-metrics`, which is still in development. The data structure may change in future releases.
165
-
166
- ```json
167
- {
168
- "timestamp": 1741717005911,
169
- "cpuUsageData": [
170
- {
171
- "cpuNumber": "0",
172
- "idle": 60486.234000000004,
173
- "user": 1364.515,
174
- "system": 1246.796,
175
- "interrupt": 167,
176
- "nice": 0,
177
- "userP": 0.009375623379214043,
178
- "systemP": 0.002992220227408737,
179
- "idleP": 0.9850388988629563,
180
- "interruptP": 0,
181
- "niceP": 0
182
- }
183
- ],
184
- "processCpuUsageData": {
185
- "user": 0.968,
186
- "system": 0.32799999999999996,
187
- "userP": 0,
188
- "systemP": 0
189
- },
190
- "memoryData": {
191
- "used": 15726522368,
192
- "free": 18437427200,
193
- "usedP": 0.4603250668280579,
194
- "freeP": 0.539674933171942
195
- },
196
- "processMemoryData": 75988992,
197
- "_id": "6mXKM8uK7xSOqJVT"
198
- }
199
- ```
200
-
201
- The shape of these objects may change as development continues.
202
+ - `GET /utils/health`: Perform a health check.
202
203
 
203
204
  ## Telemetry Plugins
204
205
 
206
+ > **Note:** Plugins are currently only supported for traces. Support for logs and metrics plugins will be added in future releases.
207
+
205
208
  OAS Telemetry supports a range of plugins to extend its functionality, allowing developers to tailor telemetry data collection, alerting, and reporting to meet specific requirements. Plugins enable additional features, such as integration with alerting systems, custom data exporters, and data visualization tools.
206
209
 
207
210
  One example plugin is the **Outlier Alert Over Messaging** plugin, which can be configured to send anomaly alerts to messaging platforms like Telegram. This plugin is especially useful for monitoring abnormal response times in your API, notifying selected channels to allow rapid responses to potential issues. For setup details, refer to its [README documentation](https://github.com/oas-tools/oas-telemetry-plugin-outlier-messaging/blob/main/README.md).
@@ -225,7 +228,7 @@ To perform a simple search, send a POST request to the `/telemetry/traces/find`
225
228
 
226
229
  ```json
227
230
  {
228
- "search": {
231
+ "query": {
229
232
  "attributes.http.target": "/api/v1/pets",
230
233
  "attributes.http.method": "GET",
231
234
  "$or": [
@@ -242,18 +245,17 @@ For more complex searches using regex, additional parsing on the server and extr
242
245
 
243
246
  ```json
244
247
  {
245
- "flags": {
246
- "containsRegex": true
247
- },
248
- "config": {
249
- "regexIds": ["attributes.http.target"]
250
- },
251
- "search": {
252
- "attributes.http.target": "^/api/v1/pets.*$",
248
+ "query": {
249
+ "attributes.http.target": {
250
+ "$regex": "^\/api\/v1\/pets.*$"
251
+ },
253
252
  "attributes.http.method": "GET",
254
253
  "$or": [
255
- {"attributes.http.status_code": 200},
256
- {"attributes.http.status_code": 304}
254
+ {
255
+ "attributes.http.status_code": {
256
+ "$lte": 400
257
+ }
258
+ }
257
259
  ]
258
260
  }
259
261
  }
@@ -263,6 +265,7 @@ For more complex searches using regex, additional parsing on the server and extr
263
265
 
264
266
  To run these examples, follow these steps:
265
267
 
268
+ 0. You will need Node.js >= v18 and npm. You can install them using [nvm](https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/)
266
269
  1. Create a new folder for your project.
267
270
  2. Navigate to the folder and initialize a new Node.js project:
268
271
 
@@ -270,18 +273,19 @@ To run these examples, follow these steps:
270
273
  npm init -y
271
274
  ```
272
275
 
273
- 3. Install the **OAS Telemetry** package:
276
+ 3. Install the **OAS Telemetry** package and other dependencies:
274
277
 
275
278
  ```sh
276
- npm install @oas-tools/oas-telemetry
279
+ npm install @oas-tools/oas-telemetry@alpha express dotenv
277
280
  ```
278
281
 
279
- 4. Save the example code as `index.js` in the project folder.
282
+ 4. Save the example cjs code as `index.js` in the project folder. You can add in the .env necessary variables like your openAI api key. (see .env.example)
280
283
  5. Run the application:
281
284
 
282
285
  ```sh
283
286
  node index.js
284
287
  ```
288
+ 6. Go to `/telemetry` (currently UI, is a placeholder except for the AI chat, we are migrating to a component based UI, but you can use the API like GET: `/telemetry/logs` `/telemetry/traces` `/telemetry/traces`)
285
289
 
286
290
  Your project folder should now contain the necessary files to run the example with **OAS Telemetry** integrated.
287
291
 
@@ -290,100 +294,99 @@ Your project folder should now contain the necessary files to run the example wi
290
294
  ```js index.mjs
291
295
  import oasTelemetry from '@oas-tools/oas-telemetry';
292
296
  import express from 'express';
293
-
297
+ import dotenv from 'dotenv';
298
+ if (process.env.NODE_ENV !== 'test') {
299
+ dotenv.config();
300
+ }
294
301
  const app = express();
295
- const port = 3000;
296
-
297
- const spec = { "paths": {
298
- "/api/v1/pets": {
299
- "get": {
300
- "summary": "Get pets",
301
- "responses":{
302
- "200": {
303
- "description": "Success"
304
- }
305
- }
306
- },
307
- "post": {
308
- "summary": "Insert a pet",
309
- "responses":{
310
- "201": {
311
- "description": "Pet Created"
312
- },
313
- "400": {
314
- "description": "Bad Request"
315
- }
316
- }
317
- }
302
+ const port = process.env.PORT || 3000;
303
+
304
+ const spec = {
305
+ "paths": {
306
+ "/api/v1/pets": {
307
+ "get": {
308
+ "summary": "Get pets",
309
+ "responses": {
310
+ "200": {
311
+ "description": "Success"
312
+ }
313
+ }
314
+ },
315
+ "post": {
316
+ "summary": "Insert a pet",
317
+ "responses": {
318
+ "201": {
319
+ "description": "Pet Created"
318
320
  },
319
- "/api/v1/pets/{petName}": {
320
- "get": {
321
- "summary": "Get a pet",
322
- "parameters": [
323
- {
324
- "name": "petName",
325
- "in": "path",
326
- "required": true,
327
- "description": "The name of the pet to retrieve",
328
- "schema": {
329
- "type": "string"
330
- }
331
- }
332
- ],
333
- "responses":{
334
- "200": {
335
- "description": "Success"
336
- },
337
- "404": {
338
- "description": "Not Found"
339
- }
340
- }
321
+ "400": {
322
+ "description": "Bad Request"
323
+ }
324
+ }
325
+ }
326
+ },
327
+ "/api/v1/pets/{petName}": {
328
+ "get": {
329
+ "summary": "Get a pet",
330
+ "parameters": [
331
+ {
332
+ "name": "petName",
333
+ "in": "path",
334
+ "required": true,
335
+ "description": "The name of the pet to retrieve",
336
+ "schema": {
337
+ "type": "string"
341
338
  }
339
+ }
340
+ ],
341
+ "responses": {
342
+ "200": {
343
+ "description": "Success"
342
344
  },
343
- "/api/v1/clinics": {
344
- "get": {
345
- "summary": "Get pets",
346
- "responses":{
347
- "200": {
348
- "description": "Success"
349
- }
350
- }
351
- }
345
+ "404": {
346
+ "description": "Not Found"
352
347
  }
353
348
  }
354
349
  }
355
-
356
- const oasTlmConfig = {
357
- spec : JSON.stringify(spec),
358
- baseURL: "/telemetry",
350
+ },
351
+ "/api/v1/clinics": {
352
+ "get": {
353
+ "summary": "Get pets",
354
+ "responses": {
355
+ "200": {
356
+ "description": "Success"
357
+ }
358
+ }
359
+ }
360
+ }
361
+ }
359
362
  }
360
- app.use(oasTelemetry(oasTlmConfig));
363
+
364
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
361
365
 
362
366
  app.use(express.json());
363
367
 
364
368
  app.listen(port, () => {
365
369
  console.log(`Example app listening at http://localhost:${port}`);
366
- console.log(`Telemetry portal available at http://localhost:${port}${oasTlmConfig.baseURL}`);
367
370
  });
368
371
 
369
- let pets =[{ name: "rocky"},{ name: "pikachu"}];
370
- let clinics =[{ name: "Pet Heaven"},{ name: "Pet Care"}];
372
+ let pets = [{ name: "rocky" }, { name: "pikachu" }];
373
+ let clinics = [{ name: "Pet Heaven" }, { name: "Pet Care" }];
371
374
 
372
375
  app.get("/api/v1/pets", (req, res) => {
373
376
  res.send(pets);
374
377
  });
375
378
  app.post("/api/v1/pets", (req, res) => {
376
- if(req.body && req.body.name){
379
+ if (req.body && req.body.name) {
377
380
  pets.push(req.body);
378
381
  res.sendStatus(201);
379
- }else{
382
+ } else {
380
383
  res.sendStatus(400);
381
384
  }
382
385
  });
383
386
  app.get("/api/v1/pets/:name", (req, res) => {
384
387
  let name = req.params.name;
385
- let filterdPets = pets.filter((p)=>(p.name==name));
386
- if(filterdPets.length > 0)
388
+ let filterdPets = pets.filter((p) => (p.name == name));
389
+ if (filterdPets.length > 0)
387
390
  return res.send(filterdPets[0]);
388
391
  else
389
392
  return res.sendStatus(404);
@@ -398,98 +401,100 @@ app.get("/api/v1/clinics", (req, res) => {
398
401
  ```js index.cjs
399
402
  let oasTelemetry = require('@oas-tools/oas-telemetry');
400
403
  let express = require('express');
401
-
404
+ let dotenv = require('dotenv');
405
+ if (process.env.NODE_ENV !== 'test') {
406
+ dotenv.config();
407
+ }
402
408
  const app = express();
403
- const port = 3000;
404
-
405
- const spec = { "paths": {
406
- "/api/v1/pets": {
407
- "get": {
408
- "summary": "Get pets",
409
- "responses":{
410
- "200": {
411
- "description": "Success"
412
- }
413
- }
414
- },
415
- "post": {
416
- "summary": "Insert a pet",
417
- "responses":{
418
- "201": {
419
- "description": "Pet Created"
420
- },
421
- "400": {
422
- "description": "Bad Request"
423
- }
424
- }
425
- }
409
+ const port = process.env.PORT || 3000;
410
+
411
+ const spec = {
412
+ "paths": {
413
+ "/api/v1/pets": {
414
+ "get": {
415
+ "summary": "Get pets",
416
+ "responses": {
417
+ "200": {
418
+ "description": "Success"
419
+ }
420
+ }
421
+ },
422
+ "post": {
423
+ "summary": "Insert a pet",
424
+ "responses": {
425
+ "201": {
426
+ "description": "Pet Created"
426
427
  },
427
- "/api/v1/pets/{petName}": {
428
- "get": {
429
- "summary": "Get a pet",
430
- "parameters": [
431
- {
432
- "name": "petName",
433
- "in": "path",
434
- "required": true,
435
- "description": "The name of the pet to retrieve",
436
- "schema": {
437
- "type": "string"
438
- }
439
- }
440
- ],
441
- "responses":{
442
- "200": {
443
- "description": "Success"
444
- },
445
- "404": {
446
- "description": "Not Found"
447
- }
448
- }
428
+ "400": {
429
+ "description": "Bad Request"
430
+ }
431
+ }
432
+ }
433
+ },
434
+ "/api/v1/pets/{petName}": {
435
+ "get": {
436
+ "summary": "Get a pet",
437
+ "parameters": [
438
+ {
439
+ "name": "petName",
440
+ "in": "path",
441
+ "required": true,
442
+ "description": "The name of the pet to retrieve",
443
+ "schema": {
444
+ "type": "string"
449
445
  }
446
+ }
447
+ ],
448
+ "responses": {
449
+ "200": {
450
+ "description": "Success"
450
451
  },
451
- "/api/v1/clinics": {
452
- "get": {
453
- "summary": "Get pets",
454
- "responses":{
455
- "200": {
456
- "description": "Success"
457
- }
458
- }
459
- }
452
+ "404": {
453
+ "description": "Not Found"
454
+ }
455
+ }
456
+ }
457
+ },
458
+ "/api/v1/clinics": {
459
+ "get": {
460
+ "summary": "Get pets",
461
+ "responses": {
462
+ "200": {
463
+ "description": "Success"
460
464
  }
461
465
  }
462
466
  }
467
+ }
468
+ }
469
+ }
470
+
463
471
 
464
- app.use(oasTelemetry({
465
- spec : JSON.stringify(spec)
466
- }))
472
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
467
473
 
468
474
  app.use(express.json());
469
475
 
470
476
  app.listen(port, () => {
471
477
  console.log(`Example app listening at http://localhost:${port}`);
472
- console.log(`Telemetry portal available at http://localhost:${port}/telemetry`);
473
478
  });
474
479
 
475
- let pets =[{ name: "rocky"},{ name: "pikachu"}];
476
- let clinics =[{ name: "Pet Heaven"},{ name: "Pet Care"}];
480
+ let pets = [{ name: "rocky" }, { name: "pikachu" }];
481
+ let clinics = [{ name: "Pet Heaven" }, { name: "Pet Care" }];
477
482
 
478
483
  app.get("/api/v1/pets", (req, res) => {
479
484
  res.send(pets);
480
485
  });
481
486
  app.post("/api/v1/pets", (req, res) => {
482
- if(req.body && req.body.name){
487
+ if (req.body && req.body.name) {
483
488
  pets.push(req.body);
484
489
  res.sendStatus(201);
485
- }else{
490
+ } else {
486
491
  res.sendStatus(400);
487
492
  }
488
493
  });
489
494
  app.get("/api/v1/pets/:name", (req, res) => {
490
495
  let name = req.params.name;
491
- let filterdPets = pets.filter((p)=>(p.name==name));
492
- if(filterdPets.length > 0)
496
+ let filterdPets = pets.filter((p) => (p.name == name));
497
+ if (filterdPets.length > 0)
493
498
  return res.send(filterdPets[0]);
494
499
  else
495
500
  return res.sendStatus(404);