@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.
- package/.env.example +50 -17
- package/README.md +244 -239
- package/dist/cjs/config/bootConfig.cjs +18 -0
- package/dist/cjs/config/config.cjs +145 -0
- package/dist/cjs/config/config.types.cjs +5 -0
- package/dist/cjs/index.cjs +19 -25
- package/dist/cjs/{tlmRoutes.cjs → routesManager.cjs} +28 -21
- package/dist/cjs/{exporters/InMemoryLogRecordExporter.cjs → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.cjs} +42 -19
- package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.cjs +97 -0
- package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.cjs +118 -0
- package/dist/cjs/telemetry/custom-implementations/exporters/PluginLogExporter.cjs +45 -0
- package/dist/cjs/telemetry/custom-implementations/exporters/PluginMetricExporter.cjs +46 -0
- package/dist/cjs/telemetry/custom-implementations/exporters/PluginSpanExporter.cjs +61 -0
- package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.cjs +70 -0
- package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.cjs +70 -0
- package/dist/cjs/{utils → telemetry/custom-implementations/utils}/circular.cjs +39 -49
- package/dist/cjs/telemetry/custom-implementations/wrappers.cjs +175 -0
- package/dist/cjs/telemetry/initializeTelemetry.cjs +74 -0
- package/dist/cjs/telemetry/telemetryConfigurator.cjs +84 -0
- package/dist/cjs/telemetry/telemetryRegistry.cjs +40 -0
- package/dist/cjs/tlm-ai/agent.cjs +82 -63
- package/dist/cjs/tlm-ai/aiController.cjs +5 -4
- package/dist/cjs/tlm-ai/aiRoutes.cjs +9 -6
- package/dist/cjs/tlm-ai/tools.cjs +16 -9
- package/dist/cjs/tlm-auth/authController.cjs +14 -15
- package/dist/cjs/tlm-auth/authMiddleware.cjs +11 -10
- package/dist/cjs/tlm-auth/authRoutes.cjs +9 -7
- package/dist/cjs/tlm-log/logController.cjs +45 -18
- package/dist/cjs/tlm-log/logRoutes.cjs +16 -11
- package/dist/cjs/tlm-metric/metricsController.cjs +37 -12
- package/dist/cjs/tlm-metric/metricsRoutes.cjs +16 -11
- package/dist/cjs/tlm-plugin/pluginController.cjs +114 -75
- package/dist/cjs/tlm-plugin/pluginProcess.cjs +108 -0
- package/dist/cjs/tlm-plugin/pluginRoutes.cjs +11 -6
- package/dist/cjs/tlm-plugin/pluginService.cjs +79 -0
- package/dist/cjs/tlm-trace/traceController.cjs +54 -45
- package/dist/cjs/tlm-trace/traceRoutes.cjs +16 -11
- package/dist/cjs/tlm-ui/uiRoutes.cjs +26 -20
- package/dist/cjs/tlm-util/utilController.cjs +8 -9
- package/dist/cjs/tlm-util/utilRoutes.cjs +22 -19
- package/dist/cjs/types/index.cjs +0 -1
- package/dist/cjs/utils/logger.cjs +3 -5
- package/dist/cjs/utils/regexUtils.cjs +27 -0
- package/dist/esm/config/bootConfig.js +11 -0
- package/dist/esm/config/config.js +126 -0
- package/dist/esm/index.js +18 -29
- package/dist/esm/{tlmRoutes.js → routesManager.js} +27 -22
- package/dist/esm/{exporters/InMemoryLogRecordExporter.js → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.js} +31 -17
- package/dist/esm/{exporters/InMemoryDBMetricsExporter.js → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.js} +31 -17
- package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.js +105 -0
- package/dist/esm/telemetry/custom-implementations/exporters/PluginLogExporter.js +36 -0
- package/dist/esm/telemetry/custom-implementations/exporters/PluginMetricExporter.js +35 -0
- package/dist/esm/telemetry/custom-implementations/exporters/PluginSpanExporter.js +52 -0
- package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.js +64 -0
- package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.js +64 -0
- package/dist/esm/telemetry/custom-implementations/utils/circular.js +76 -0
- package/dist/esm/telemetry/custom-implementations/wrappers.js +163 -0
- package/dist/esm/telemetry/initializeTelemetry.js +71 -0
- package/dist/esm/telemetry/telemetryConfigurator.js +74 -0
- package/dist/esm/telemetry/telemetryRegistry.js +34 -0
- package/dist/esm/tlm-ai/agent.js +77 -59
- package/dist/esm/tlm-ai/aiController.js +5 -4
- package/dist/esm/tlm-ai/aiRoutes.js +7 -5
- package/dist/esm/tlm-ai/tools.js +18 -9
- package/dist/esm/tlm-auth/authController.js +9 -10
- package/dist/esm/tlm-auth/authMiddleware.js +10 -9
- package/dist/esm/tlm-auth/authRoutes.js +8 -6
- package/dist/esm/tlm-log/logController.js +36 -16
- package/dist/esm/tlm-log/logRoutes.js +15 -11
- package/dist/esm/tlm-metric/metricsController.js +29 -10
- package/dist/esm/tlm-metric/metricsRoutes.js +15 -11
- package/dist/esm/tlm-plugin/pluginController.js +112 -77
- package/dist/esm/tlm-plugin/pluginProcess.js +101 -0
- package/dist/esm/tlm-plugin/pluginRoutes.js +10 -6
- package/dist/esm/tlm-plugin/pluginService.js +73 -0
- package/dist/esm/tlm-trace/traceController.js +40 -35
- package/dist/esm/tlm-trace/traceRoutes.js +15 -11
- package/dist/esm/tlm-ui/uiRoutes.js +24 -19
- package/dist/esm/tlm-util/utilController.js +8 -9
- package/dist/esm/tlm-util/utilRoutes.js +17 -15
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/utils/logger.js +3 -4
- package/dist/esm/utils/regexUtils.js +23 -0
- package/dist/types/config/bootConfig.d.ts +5 -0
- package/dist/types/config/config.d.ts +858 -0
- package/dist/types/config/config.types.d.ts +34 -0
- package/dist/types/index.d.ts +5 -4
- package/dist/types/routesManager.d.ts +3 -0
- package/dist/types/{exporters/InMemoryLogRecordExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.d.ts} +6 -6
- package/dist/types/{exporters/InMemoryDBMetricsExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.d.ts} +7 -7
- package/dist/types/{exporters/InMemoryDbExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.d.ts} +9 -9
- package/dist/types/telemetry/custom-implementations/exporters/PluginLogExporter.d.ts +8 -0
- package/dist/types/telemetry/custom-implementations/exporters/PluginMetricExporter.d.ts +12 -0
- package/dist/types/telemetry/custom-implementations/exporters/PluginSpanExporter.d.ts +14 -0
- package/dist/types/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.d.ts +32 -0
- package/dist/types/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.d.ts +34 -0
- package/dist/types/telemetry/custom-implementations/utils/circular.d.ts +27 -0
- package/dist/types/telemetry/custom-implementations/wrappers.d.ts +52 -0
- package/dist/types/telemetry/initializeTelemetry.d.ts +1 -0
- package/dist/types/telemetry/telemetryConfigurator.d.ts +2 -0
- package/dist/types/telemetry/telemetryRegistry.d.ts +20 -0
- package/dist/types/tlm-ai/agent.d.ts +2 -1
- package/dist/types/tlm-ai/aiController.d.ts +4 -3
- package/dist/types/tlm-ai/aiRoutes.d.ts +2 -2
- package/dist/types/tlm-ai/tools.d.ts +3 -1
- package/dist/types/tlm-auth/authController.d.ts +4 -3
- package/dist/types/tlm-auth/authMiddleware.d.ts +2 -1
- package/dist/types/tlm-auth/authRoutes.d.ts +2 -2
- package/dist/types/tlm-log/logController.d.ts +1 -0
- package/dist/types/tlm-log/logRoutes.d.ts +2 -2
- package/dist/types/tlm-metric/metricsController.d.ts +1 -0
- package/dist/types/tlm-metric/metricsRoutes.d.ts +2 -2
- package/dist/types/tlm-plugin/pluginController.d.ts +4 -1
- package/dist/types/tlm-plugin/pluginProcess.d.ts +1 -0
- package/dist/types/tlm-plugin/pluginRoutes.d.ts +1 -2
- package/dist/types/tlm-plugin/pluginService.d.ts +24 -0
- package/dist/types/tlm-trace/traceController.d.ts +7 -6
- package/dist/types/tlm-trace/traceRoutes.d.ts +2 -2
- package/dist/types/tlm-ui/uiRoutes.d.ts +1 -2
- package/dist/types/tlm-util/utilController.d.ts +2 -1
- package/dist/types/tlm-util/utilRoutes.d.ts +2 -2
- package/dist/types/types/index.d.ts +17 -47
- package/dist/types/utils/regexUtils.d.ts +1 -0
- package/dist/ui/assets/index-BzIdRox6.js +1733 -0
- package/dist/ui/assets/index-CkoHzrrt.css +1 -0
- package/dist/ui/index.html +3 -3
- package/dist/ui/oas-tlm.svg +185 -0
- package/package.json +12 -7
- package/dist/cjs/config.cjs +0 -31
- package/dist/cjs/exporters/InMemoryDBMetricsExporter.cjs +0 -74
- package/dist/cjs/exporters/InMemoryDbExporter.cjs +0 -102
- package/dist/cjs/exporters/consoleExporter.cjs +0 -47
- package/dist/cjs/exporters/dynamicExporter.cjs +0 -57
- package/dist/cjs/instrumentation/index.cjs +0 -28
- package/dist/cjs/instrumentation/logs.cjs +0 -46
- package/dist/cjs/instrumentation/metrics.cjs +0 -27
- package/dist/cjs/instrumentation/traces.cjs +0 -19
- package/dist/esm/config.js +0 -20
- package/dist/esm/exporters/InMemoryDbExporter.js +0 -102
- package/dist/esm/exporters/consoleExporter.js +0 -38
- package/dist/esm/exporters/dynamicExporter.js +0 -50
- package/dist/esm/instrumentation/index.js +0 -26
- package/dist/esm/instrumentation/logs.js +0 -34
- package/dist/esm/instrumentation/metrics.js +0 -18
- package/dist/esm/instrumentation/traces.js +0 -12
- package/dist/esm/utils/circular.js +0 -84
- package/dist/types/config.d.ts +0 -6
- package/dist/types/exporters/consoleExporter.d.ts +0 -13
- package/dist/types/exporters/dynamicExporter.d.ts +0 -25
- package/dist/types/instrumentation/logs.d.ts +0 -1
- package/dist/types/instrumentation/metrics.d.ts +0 -1
- package/dist/types/instrumentation/traces.d.ts +0 -1
- package/dist/types/tlmRoutes.d.ts +0 -2
- package/dist/types/utils/circular.d.ts +0 -31
- package/dist/ui/assets/index-BNhZBPi2.css +0 -1
- package/dist/ui/assets/index-DxGAMrAl.js +0 -401
- package/dist/ui/vite.svg +0 -1
- /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**
|
|
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
|
-
|
|
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
|
-
> - **
|
|
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
|
|
21
|
-
> - **Configuration:**
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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",
|
|
85
|
-
jwtSecret: "
|
|
86
|
-
|
|
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 `
|
|
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
|
|
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
|
-
- `
|
|
112
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
- `
|
|
122
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
- `
|
|
132
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
###
|
|
191
|
+
### Plugins Endpoints
|
|
143
192
|
|
|
144
|
-
- `GET
|
|
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
|
-
"
|
|
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
|
-
"
|
|
246
|
-
"
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
{
|
|
256
|
-
|
|
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 = {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
"
|
|
320
|
-
"
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
"
|
|
344
|
-
"
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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 = {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
-
"
|
|
428
|
-
"
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
"
|
|
452
|
-
"
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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);
|