@oas-tools/oas-telemetry 0.7.0-alpha.2 → 0.7.0-alpha.3

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 (154) hide show
  1. package/.env.example +50 -17
  2. package/README.md +242 -240
  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 +52 -0
  12. package/dist/cjs/telemetry/custom-implementations/exporters/PluginMetricExporter.cjs +53 -0
  13. package/dist/cjs/telemetry/custom-implementations/exporters/PluginSpanExporter.cjs +69 -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 +40 -19
  33. package/dist/cjs/tlm-plugin/pluginRoutes.cjs +8 -6
  34. package/dist/cjs/tlm-plugin/pluginService.cjs +25 -0
  35. package/dist/cjs/tlm-trace/traceController.cjs +54 -45
  36. package/dist/cjs/tlm-trace/traceRoutes.cjs +16 -11
  37. package/dist/cjs/tlm-ui/uiRoutes.cjs +26 -20
  38. package/dist/cjs/tlm-util/utilController.cjs +8 -9
  39. package/dist/cjs/tlm-util/utilRoutes.cjs +22 -19
  40. package/dist/cjs/types/index.cjs +0 -1
  41. package/dist/cjs/utils/logger.cjs +3 -5
  42. package/dist/cjs/utils/regexUtils.cjs +27 -0
  43. package/dist/esm/config/bootConfig.js +11 -0
  44. package/dist/esm/config/config.js +126 -0
  45. package/dist/esm/index.js +18 -29
  46. package/dist/esm/{tlmRoutes.js → routesManager.js} +27 -22
  47. package/dist/esm/{exporters/InMemoryLogRecordExporter.js → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.js} +31 -17
  48. package/dist/esm/{exporters/InMemoryDBMetricsExporter.js → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.js} +31 -17
  49. package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.js +105 -0
  50. package/dist/esm/telemetry/custom-implementations/exporters/PluginLogExporter.js +44 -0
  51. package/dist/esm/telemetry/custom-implementations/exporters/PluginMetricExporter.js +43 -0
  52. package/dist/esm/telemetry/custom-implementations/exporters/PluginSpanExporter.js +61 -0
  53. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.js +64 -0
  54. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.js +64 -0
  55. package/dist/esm/telemetry/custom-implementations/utils/circular.js +76 -0
  56. package/dist/esm/telemetry/custom-implementations/wrappers.js +163 -0
  57. package/dist/esm/telemetry/initializeTelemetry.js +71 -0
  58. package/dist/esm/telemetry/telemetryConfigurator.js +74 -0
  59. package/dist/esm/telemetry/telemetryRegistry.js +34 -0
  60. package/dist/esm/tlm-ai/agent.js +77 -59
  61. package/dist/esm/tlm-ai/aiController.js +5 -4
  62. package/dist/esm/tlm-ai/aiRoutes.js +7 -5
  63. package/dist/esm/tlm-ai/tools.js +18 -9
  64. package/dist/esm/tlm-auth/authController.js +9 -10
  65. package/dist/esm/tlm-auth/authMiddleware.js +10 -9
  66. package/dist/esm/tlm-auth/authRoutes.js +8 -6
  67. package/dist/esm/tlm-log/logController.js +36 -16
  68. package/dist/esm/tlm-log/logRoutes.js +15 -11
  69. package/dist/esm/tlm-metric/metricsController.js +29 -10
  70. package/dist/esm/tlm-metric/metricsRoutes.js +15 -11
  71. package/dist/esm/tlm-plugin/pluginController.js +40 -19
  72. package/dist/esm/tlm-plugin/pluginRoutes.js +6 -5
  73. package/dist/esm/tlm-plugin/pluginService.js +19 -0
  74. package/dist/esm/tlm-trace/traceController.js +40 -35
  75. package/dist/esm/tlm-trace/traceRoutes.js +15 -11
  76. package/dist/esm/tlm-ui/uiRoutes.js +24 -19
  77. package/dist/esm/tlm-util/utilController.js +8 -9
  78. package/dist/esm/tlm-util/utilRoutes.js +17 -15
  79. package/dist/esm/types/index.js +0 -1
  80. package/dist/esm/utils/logger.js +3 -4
  81. package/dist/esm/utils/regexUtils.js +23 -0
  82. package/dist/types/config/bootConfig.d.ts +5 -0
  83. package/dist/types/config/config.d.ts +253 -0
  84. package/dist/types/config/config.types.d.ts +34 -0
  85. package/dist/types/index.d.ts +5 -4
  86. package/dist/types/routesManager.d.ts +3 -0
  87. package/dist/types/{exporters/InMemoryLogRecordExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.d.ts} +6 -6
  88. package/dist/types/{exporters/InMemoryDBMetricsExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.d.ts} +7 -7
  89. package/dist/types/{exporters/InMemoryDbExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.d.ts} +9 -9
  90. package/dist/types/telemetry/custom-implementations/exporters/PluginLogExporter.d.ts +8 -0
  91. package/dist/types/telemetry/custom-implementations/exporters/PluginMetricExporter.d.ts +12 -0
  92. package/dist/types/telemetry/custom-implementations/exporters/PluginSpanExporter.d.ts +14 -0
  93. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.d.ts +32 -0
  94. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.d.ts +34 -0
  95. package/dist/types/telemetry/custom-implementations/utils/circular.d.ts +27 -0
  96. package/dist/types/telemetry/custom-implementations/wrappers.d.ts +52 -0
  97. package/dist/types/telemetry/initializeTelemetry.d.ts +1 -0
  98. package/dist/types/telemetry/telemetryConfigurator.d.ts +2 -0
  99. package/dist/types/telemetry/telemetryRegistry.d.ts +20 -0
  100. package/dist/types/tlm-ai/agent.d.ts +2 -1
  101. package/dist/types/tlm-ai/aiController.d.ts +4 -3
  102. package/dist/types/tlm-ai/aiRoutes.d.ts +2 -2
  103. package/dist/types/tlm-ai/tools.d.ts +3 -1
  104. package/dist/types/tlm-auth/authController.d.ts +4 -3
  105. package/dist/types/tlm-auth/authMiddleware.d.ts +2 -1
  106. package/dist/types/tlm-auth/authRoutes.d.ts +2 -2
  107. package/dist/types/tlm-log/logController.d.ts +1 -0
  108. package/dist/types/tlm-log/logRoutes.d.ts +2 -2
  109. package/dist/types/tlm-metric/metricsController.d.ts +1 -0
  110. package/dist/types/tlm-metric/metricsRoutes.d.ts +2 -2
  111. package/dist/types/tlm-plugin/pluginRoutes.d.ts +1 -2
  112. package/dist/types/tlm-plugin/pluginService.d.ts +9 -0
  113. package/dist/types/tlm-trace/traceController.d.ts +7 -6
  114. package/dist/types/tlm-trace/traceRoutes.d.ts +2 -2
  115. package/dist/types/tlm-ui/uiRoutes.d.ts +1 -2
  116. package/dist/types/tlm-util/utilController.d.ts +2 -1
  117. package/dist/types/tlm-util/utilRoutes.d.ts +2 -2
  118. package/dist/types/types/index.d.ts +7 -46
  119. package/dist/types/utils/regexUtils.d.ts +1 -0
  120. package/dist/ui/assets/index-D9HsRlaQ.js +437 -0
  121. package/dist/ui/assets/index-DEyIcKBi.css +1 -0
  122. package/dist/ui/index.html +3 -3
  123. package/dist/ui/oas-tlm.svg +185 -0
  124. package/package.json +12 -7
  125. package/dist/cjs/config.cjs +0 -31
  126. package/dist/cjs/exporters/InMemoryDBMetricsExporter.cjs +0 -74
  127. package/dist/cjs/exporters/InMemoryDbExporter.cjs +0 -102
  128. package/dist/cjs/exporters/consoleExporter.cjs +0 -47
  129. package/dist/cjs/exporters/dynamicExporter.cjs +0 -57
  130. package/dist/cjs/instrumentation/index.cjs +0 -28
  131. package/dist/cjs/instrumentation/logs.cjs +0 -46
  132. package/dist/cjs/instrumentation/metrics.cjs +0 -27
  133. package/dist/cjs/instrumentation/traces.cjs +0 -19
  134. package/dist/esm/config.js +0 -20
  135. package/dist/esm/exporters/InMemoryDbExporter.js +0 -102
  136. package/dist/esm/exporters/consoleExporter.js +0 -38
  137. package/dist/esm/exporters/dynamicExporter.js +0 -50
  138. package/dist/esm/instrumentation/index.js +0 -26
  139. package/dist/esm/instrumentation/logs.js +0 -34
  140. package/dist/esm/instrumentation/metrics.js +0 -18
  141. package/dist/esm/instrumentation/traces.js +0 -12
  142. package/dist/esm/utils/circular.js +0 -84
  143. package/dist/types/config.d.ts +0 -6
  144. package/dist/types/exporters/consoleExporter.d.ts +0 -13
  145. package/dist/types/exporters/dynamicExporter.d.ts +0 -25
  146. package/dist/types/instrumentation/logs.d.ts +0 -1
  147. package/dist/types/instrumentation/metrics.d.ts +0 -1
  148. package/dist/types/instrumentation/traces.d.ts +0 -1
  149. package/dist/types/tlmRoutes.d.ts +0 -2
  150. package/dist/types/utils/circular.d.ts +0 -31
  151. package/dist/ui/assets/index-BNhZBPi2.css +0 -1
  152. package/dist/ui/assets/index-DxGAMrAl.js +0 -401
  153. package/dist/ui/vite.svg +0 -1
  154. /package/dist/{types/instrumentation/index.d.ts → esm/config/config.types.js} +0 -0
package/README.md CHANGED
@@ -1,24 +1,18 @@
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.
3
+ **OAS Telemetry** is an Express middleware for collecting telemetry data using **OpenTelemetry** in **OpenAPI Specification (OAS)**-based applications. It exposes endpoints for managing and analyzing telemetry data—such as starting/stopping collection, resetting, listing, and searching records—making integration with **Express.js** straightforward.
4
4
 
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.
6
-
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.
5
+ 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
6
 
13
7
  > ⚠️ **Warning: Early Development Notice**
14
8
  >
15
9
  > **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
10
  >
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.
11
+ > - **Traces:** Semi-stable. Currently supports HTTP instrumentation.
19
12
  > - **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.
13
+ > - **Metrics:** Semi=stable. Currently uses OpenTelemetry host metrics. This area is subject to change to improve memory usage and data handling.
14
+ > - **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.
15
+ > - **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 metrics, traces, and logs.
22
16
 
23
17
  ## Usage
24
18
 
@@ -30,7 +24,7 @@ First, install the package using npm:
30
24
  npm install @oas-tools/oas-telemetry
31
25
  ```
32
26
 
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.
27
+ 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
28
 
35
29
  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
30
 
@@ -41,14 +35,12 @@ Add the following lines to your `index.js` file:
41
35
  ```js
42
36
  // This import MUST be at the top of the file
43
37
  import oasTelemetry from '@oas-tools/oas-telemetry';
44
- import { readFileSync } from 'fs';
45
38
 
46
- // ...rest of your code here creating an express app
39
+ // ...rest of your code here creating an express app and importing the OpenAPI spec
47
40
  // NOTE: Do not add express.json() before oasTelemetry, or set its limit to at least "10mb" to avoid issues with large files.
48
41
 
49
- app.use(oasTelemetry({
50
- spec: readFileSync('./spec/oas.yaml', { encoding: 'utf8', flag: 'r' })
51
- }));
42
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
43
+
52
44
  ```
53
45
 
54
46
  ### Using CommonJS
@@ -58,14 +50,12 @@ Add the following lines to your `index.js` file:
58
50
  ```js
59
51
  // This require MUST be at the top of the file
60
52
  const oasTelemetry = require('@oas-tools/oas-telemetry');
61
- const { readFileSync } = require('fs');
62
53
 
63
- // ...rest of your code here creating an express app
54
+ // ...rest of your code here creating an express app and importing the OpenAPI spec
64
55
  // NOTE: Do not add express.json() before oasTelemetry, or set its limit to at least "10mb" to avoid issues with large files.
65
56
 
66
- app.use(oasTelemetry({
67
- spec: readFileSync('./spec/oas.yaml', { encoding: 'utf8', flag: 'r' })
68
- }));
57
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
58
+
69
59
  ```
70
60
 
71
61
  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 +64,82 @@ For complete examples of a working API with OAS Telemetry enabled, refer to the
74
64
 
75
65
  You can also customize the telemetry configuration by passing options to the middleware function. For example:
76
66
 
67
+ > **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.
68
+
77
69
  ```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
70
+ export const customTelemetryConfig = {
71
+ general: {
72
+ baseUrl: "/custom-telemetry",
73
+ specFileName: "oas.json",
74
+ spec: null,
75
+ },
76
+
77
+ auth: {
78
+ enabled: true,
83
79
  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
80
+ password: "my-custom-password",
81
+ jwtSecret: "my-super-secret",
82
+ },
83
+
84
+ ai: {
85
+ openAIKey: process.env.YOUR_OPENAI_API_KEY, // Seteable via environment variable
86
+ openAIModel: "gpt-4o",
87
+ extraContextPrompts: [
88
+ "Provide clear, concise answers",
89
+ "Use professional tone",
90
+ ],
91
+ },
92
+
93
+ traces: {
94
+ extraExporters: [],
95
+ extraProcessors: [],
96
+ mainProcessorOptions: {
97
+ config: undefined,
98
+ },
99
+ memoryExporter: {
100
+ enabled: true,
101
+ retentionTime: 1000 * 60 * 120, // 2 hours
102
+ },
103
+ filters: [],
104
+ },
105
+
106
+ metrics: {
107
+ mainMetricReaderOptions: {
108
+ exportIntervalMillis: 1000 * 60,
109
+ metricProducers: [],
110
+ },
111
+ extraReaders: [],
112
+ memoryExporter: {
113
+ enabled: true,
114
+ retentionTime: 1000 * 60 * 120, // 2 hours
115
+ },
116
+ filters: [],
117
+ },
118
+
119
+ logs: {
120
+ extraExporters: [],
121
+ extraProcessors: [],
122
+ memoryExporter: {
123
+ enabled: true,
124
+ retentionTime: 1000 * 60 * 120, // 2 hours
125
+ },
126
+ filters: [],
127
+ },
128
+
129
+ plugins: {
130
+ enabled: true,
131
+ extraPlugins: [],
132
+ },
87
133
  };
88
134
 
89
135
  app.use(oasTelemetry(customTelemetryConfig));
90
136
  ```
91
137
 
92
- **Note:** To disable the module, set the environment variable `OASTLM_MODULE_DISABLED` to `'true'`.
138
+ **Note:** To disable the module, set the environment variable `OASTLM_BOOT_MODULE_DISABLED` to `'true'`.
93
139
 
94
140
  ## Telemetry UI
95
141
 
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.
142
+ 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
143
 
98
144
  ## Rest API Endpoints Overview
99
145
 
@@ -108,30 +154,30 @@ You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-teleme
108
154
  - `GET /metrics`: List all metrics.
109
155
  - `POST /metrics`: Insert metrics into the database.
110
156
  - `POST /metrics/find`: Search metrics.
111
- - `GET /metrics/start`: Start metrics data collection.
112
- - `GET /metrics/stop`: Stop metrics data collection.
157
+ - `POST /metrics/start`: Start metrics data collection.
158
+ - `POST /metrics/stop`: Stop metrics data collection.
113
159
  - `GET /metrics/status`: Get metrics status.
114
- - `GET /metrics/reset`: Reset metrics data.
160
+ - `POST /metrics/reset`: Reset metrics data.
115
161
 
116
162
  ### Logs Endpoints
117
163
 
118
164
  - `GET /logs`: List all logs.
119
165
  - `POST /logs`: Insert logs into the database.
120
166
  - `POST /logs/find`: Search logs.
121
- - `GET /logs/start`: Start logs data collection.
122
- - `GET /logs/stop`: Stop logs data collection.
167
+ - `POST /logs/start`: Start logs data collection.
168
+ - `POST /logs/stop`: Stop logs data collection.
123
169
  - `GET /logs/status`: Get logs status.
124
- - `GET /logs/reset`: Reset logs data.
170
+ - `POST /logs/reset`: Reset logs data.
125
171
 
126
172
  ### Traces Endpoints
127
173
 
128
174
  - `GET /traces`: List all traces.
129
175
  - `POST /traces`: Insert traces into the database.
130
176
  - `POST /traces/find`: Search traces.
131
- - `GET /traces/start`: Start traces data collection.
132
- - `GET /traces/stop`: Stop traces data collection.
177
+ - `POST /traces/start`: Start traces data collection.
178
+ - `POST /traces/stop`: Stop traces data collection.
133
179
  - `GET /traces/status`: Get traces status.
134
- - `GET /traces/reset`: Reset traces data.
180
+ - `POST /traces/reset`: Reset traces data.
135
181
 
136
182
  ### AI Endpoints
137
183
 
@@ -139,9 +185,10 @@ You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-teleme
139
185
  - `POST /ai/microservices`: Configure known microservices.
140
186
  - `GET /ai/microservices`: Retrieve the list of known microservices.
141
187
 
142
- ### UI Endpoints
188
+ ### Plugins Endpoints
143
189
 
144
- - `GET *`: Serve the telemetry UI.
190
+ - `GET /plugins/list`: List all registered plugins.
191
+ - `POST /plugins/register`: Register a new plugin.
145
192
 
146
193
  ### Utility Endpoints
147
194
 
@@ -149,59 +196,12 @@ You can access the telemetry UI in the endpoint `/telemetry` (or `/custom-teleme
149
196
  - `GET /utils/heapStats`: Show v8 heap statistics.
150
197
  - `GET /utils/generateLog`: Generate a log message.
151
198
  - `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.
199
+ - `GET /utils/health`: Perform a health check.
202
200
 
203
201
  ## Telemetry Plugins
204
202
 
203
+ > **Note:** Plugins are currently only supported for traces. Support for logs and metrics plugins will be added in future releases.
204
+
205
205
  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
206
 
207
207
  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 +225,7 @@ To perform a simple search, send a POST request to the `/telemetry/traces/find`
225
225
 
226
226
  ```json
227
227
  {
228
- "search": {
228
+ "query": {
229
229
  "attributes.http.target": "/api/v1/pets",
230
230
  "attributes.http.method": "GET",
231
231
  "$or": [
@@ -242,18 +242,17 @@ For more complex searches using regex, additional parsing on the server and extr
242
242
 
243
243
  ```json
244
244
  {
245
- "flags": {
246
- "containsRegex": true
247
- },
248
- "config": {
249
- "regexIds": ["attributes.http.target"]
250
- },
251
- "search": {
252
- "attributes.http.target": "^/api/v1/pets.*$",
245
+ "query": {
246
+ "attributes.http.target": {
247
+ "$regex": "^\/api\/v1\/pets.*$"
248
+ },
253
249
  "attributes.http.method": "GET",
254
250
  "$or": [
255
- {"attributes.http.status_code": 200},
256
- {"attributes.http.status_code": 304}
251
+ {
252
+ "attributes.http.status_code": {
253
+ "$lte": 400
254
+ }
255
+ }
257
256
  ]
258
257
  }
259
258
  }
@@ -263,6 +262,7 @@ For more complex searches using regex, additional parsing on the server and extr
263
262
 
264
263
  To run these examples, follow these steps:
265
264
 
265
+ 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
266
  1. Create a new folder for your project.
267
267
  2. Navigate to the folder and initialize a new Node.js project:
268
268
 
@@ -270,18 +270,19 @@ To run these examples, follow these steps:
270
270
  npm init -y
271
271
  ```
272
272
 
273
- 3. Install the **OAS Telemetry** package:
273
+ 3. Install the **OAS Telemetry** package and other dependencies:
274
274
 
275
275
  ```sh
276
- npm install @oas-tools/oas-telemetry
276
+ npm install @oas-tools/oas-telemetry@alpha express dotenv
277
277
  ```
278
278
 
279
- 4. Save the example code as `index.js` in the project folder.
279
+ 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
280
  5. Run the application:
281
281
 
282
282
  ```sh
283
283
  node index.js
284
284
  ```
285
+ 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
286
 
286
287
  Your project folder should now contain the necessary files to run the example with **OAS Telemetry** integrated.
287
288
 
@@ -290,100 +291,99 @@ Your project folder should now contain the necessary files to run the example wi
290
291
  ```js index.mjs
291
292
  import oasTelemetry from '@oas-tools/oas-telemetry';
292
293
  import express from 'express';
293
-
294
+ import dotenv from 'dotenv';
295
+ if (process.env.NODE_ENV !== 'test') {
296
+ dotenv.config();
297
+ }
294
298
  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
- }
299
+ const port = process.env.PORT || 3000;
300
+
301
+ const spec = {
302
+ "paths": {
303
+ "/api/v1/pets": {
304
+ "get": {
305
+ "summary": "Get pets",
306
+ "responses": {
307
+ "200": {
308
+ "description": "Success"
309
+ }
310
+ }
311
+ },
312
+ "post": {
313
+ "summary": "Insert a pet",
314
+ "responses": {
315
+ "201": {
316
+ "description": "Pet Created"
318
317
  },
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
- }
318
+ "400": {
319
+ "description": "Bad Request"
320
+ }
321
+ }
322
+ }
323
+ },
324
+ "/api/v1/pets/{petName}": {
325
+ "get": {
326
+ "summary": "Get a pet",
327
+ "parameters": [
328
+ {
329
+ "name": "petName",
330
+ "in": "path",
331
+ "required": true,
332
+ "description": "The name of the pet to retrieve",
333
+ "schema": {
334
+ "type": "string"
341
335
  }
336
+ }
337
+ ],
338
+ "responses": {
339
+ "200": {
340
+ "description": "Success"
342
341
  },
343
- "/api/v1/clinics": {
344
- "get": {
345
- "summary": "Get pets",
346
- "responses":{
347
- "200": {
348
- "description": "Success"
349
- }
350
- }
351
- }
342
+ "404": {
343
+ "description": "Not Found"
352
344
  }
353
345
  }
354
346
  }
355
-
356
- const oasTlmConfig = {
357
- spec : JSON.stringify(spec),
358
- baseURL: "/telemetry",
347
+ },
348
+ "/api/v1/clinics": {
349
+ "get": {
350
+ "summary": "Get pets",
351
+ "responses": {
352
+ "200": {
353
+ "description": "Success"
354
+ }
355
+ }
356
+ }
357
+ }
358
+ }
359
359
  }
360
- app.use(oasTelemetry(oasTlmConfig));
360
+
361
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
361
362
 
362
363
  app.use(express.json());
363
364
 
364
365
  app.listen(port, () => {
365
366
  console.log(`Example app listening at http://localhost:${port}`);
366
- console.log(`Telemetry portal available at http://localhost:${port}${oasTlmConfig.baseURL}`);
367
367
  });
368
368
 
369
- let pets =[{ name: "rocky"},{ name: "pikachu"}];
370
- let clinics =[{ name: "Pet Heaven"},{ name: "Pet Care"}];
369
+ let pets = [{ name: "rocky" }, { name: "pikachu" }];
370
+ let clinics = [{ name: "Pet Heaven" }, { name: "Pet Care" }];
371
371
 
372
372
  app.get("/api/v1/pets", (req, res) => {
373
373
  res.send(pets);
374
374
  });
375
375
  app.post("/api/v1/pets", (req, res) => {
376
- if(req.body && req.body.name){
376
+ if (req.body && req.body.name) {
377
377
  pets.push(req.body);
378
378
  res.sendStatus(201);
379
- }else{
379
+ } else {
380
380
  res.sendStatus(400);
381
381
  }
382
382
  });
383
383
  app.get("/api/v1/pets/:name", (req, res) => {
384
384
  let name = req.params.name;
385
- let filterdPets = pets.filter((p)=>(p.name==name));
386
- if(filterdPets.length > 0)
385
+ let filterdPets = pets.filter((p) => (p.name == name));
386
+ if (filterdPets.length > 0)
387
387
  return res.send(filterdPets[0]);
388
388
  else
389
389
  return res.sendStatus(404);
@@ -398,98 +398,100 @@ app.get("/api/v1/clinics", (req, res) => {
398
398
  ```js index.cjs
399
399
  let oasTelemetry = require('@oas-tools/oas-telemetry');
400
400
  let express = require('express');
401
-
401
+ let dotenv = require('dotenv');
402
+ if (process.env.NODE_ENV !== 'test') {
403
+ dotenv.config();
404
+ }
402
405
  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
- }
406
+ const port = process.env.PORT || 3000;
407
+
408
+ const spec = {
409
+ "paths": {
410
+ "/api/v1/pets": {
411
+ "get": {
412
+ "summary": "Get pets",
413
+ "responses": {
414
+ "200": {
415
+ "description": "Success"
416
+ }
417
+ }
418
+ },
419
+ "post": {
420
+ "summary": "Insert a pet",
421
+ "responses": {
422
+ "201": {
423
+ "description": "Pet Created"
426
424
  },
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
- }
425
+ "400": {
426
+ "description": "Bad Request"
427
+ }
428
+ }
429
+ }
430
+ },
431
+ "/api/v1/pets/{petName}": {
432
+ "get": {
433
+ "summary": "Get a pet",
434
+ "parameters": [
435
+ {
436
+ "name": "petName",
437
+ "in": "path",
438
+ "required": true,
439
+ "description": "The name of the pet to retrieve",
440
+ "schema": {
441
+ "type": "string"
449
442
  }
443
+ }
444
+ ],
445
+ "responses": {
446
+ "200": {
447
+ "description": "Success"
450
448
  },
451
- "/api/v1/clinics": {
452
- "get": {
453
- "summary": "Get pets",
454
- "responses":{
455
- "200": {
456
- "description": "Success"
457
- }
458
- }
459
- }
449
+ "404": {
450
+ "description": "Not Found"
451
+ }
452
+ }
453
+ }
454
+ },
455
+ "/api/v1/clinics": {
456
+ "get": {
457
+ "summary": "Get pets",
458
+ "responses": {
459
+ "200": {
460
+ "description": "Success"
460
461
  }
461
462
  }
462
463
  }
464
+ }
465
+ }
466
+ }
467
+
463
468
 
464
- app.use(oasTelemetry({
465
- spec : JSON.stringify(spec)
466
- }))
469
+ app.use(oasTelemetry({ general: { spec: JSON.stringify(spec) } }));
467
470
 
468
471
  app.use(express.json());
469
472
 
470
473
  app.listen(port, () => {
471
474
  console.log(`Example app listening at http://localhost:${port}`);
472
- console.log(`Telemetry portal available at http://localhost:${port}/telemetry`);
473
475
  });
474
476
 
475
- let pets =[{ name: "rocky"},{ name: "pikachu"}];
476
- let clinics =[{ name: "Pet Heaven"},{ name: "Pet Care"}];
477
+ let pets = [{ name: "rocky" }, { name: "pikachu" }];
478
+ let clinics = [{ name: "Pet Heaven" }, { name: "Pet Care" }];
477
479
 
478
480
  app.get("/api/v1/pets", (req, res) => {
479
481
  res.send(pets);
480
482
  });
481
483
  app.post("/api/v1/pets", (req, res) => {
482
- if(req.body && req.body.name){
484
+ if (req.body && req.body.name) {
483
485
  pets.push(req.body);
484
486
  res.sendStatus(201);
485
- }else{
487
+ } else {
486
488
  res.sendStatus(400);
487
489
  }
488
490
  });
489
491
  app.get("/api/v1/pets/:name", (req, res) => {
490
492
  let name = req.params.name;
491
- let filterdPets = pets.filter((p)=>(p.name==name));
492
- if(filterdPets.length > 0)
493
+ let filterdPets = pets.filter((p) => (p.name == name));
494
+ if (filterdPets.length > 0)
493
495
  return res.send(filterdPets[0]);
494
496
  else
495
497
  return res.sendStatus(404);