@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.
- package/.env.example +50 -17
- package/README.md +242 -240
- 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 +52 -0
- package/dist/cjs/telemetry/custom-implementations/exporters/PluginMetricExporter.cjs +53 -0
- package/dist/cjs/telemetry/custom-implementations/exporters/PluginSpanExporter.cjs +69 -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 +40 -19
- package/dist/cjs/tlm-plugin/pluginRoutes.cjs +8 -6
- package/dist/cjs/tlm-plugin/pluginService.cjs +25 -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 +44 -0
- package/dist/esm/telemetry/custom-implementations/exporters/PluginMetricExporter.js +43 -0
- package/dist/esm/telemetry/custom-implementations/exporters/PluginSpanExporter.js +61 -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 +40 -19
- package/dist/esm/tlm-plugin/pluginRoutes.js +6 -5
- package/dist/esm/tlm-plugin/pluginService.js +19 -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 +253 -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/pluginRoutes.d.ts +1 -2
- package/dist/types/tlm-plugin/pluginService.d.ts +9 -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 +7 -46
- package/dist/types/utils/regexUtils.d.ts +1 -0
- package/dist/ui/assets/index-D9HsRlaQ.js +437 -0
- package/dist/ui/assets/index-DEyIcKBi.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,18 @@
|
|
|
1
1
|
# OAS TELEMETRY
|
|
2
2
|
|
|
3
|
-
**OAS Telemetry**
|
|
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
|
-
|
|
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
|
-
> - **
|
|
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:**
|
|
21
|
-
> - **Configuration:**
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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",
|
|
85
|
-
jwtSecret: "
|
|
86
|
-
|
|
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 `
|
|
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
|
|
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
|
-
- `
|
|
112
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
- `
|
|
122
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
- `
|
|
132
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
###
|
|
188
|
+
### Plugins Endpoints
|
|
143
189
|
|
|
144
|
-
- `GET
|
|
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
|
-
"
|
|
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
|
-
"
|
|
246
|
-
"
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
{
|
|
256
|
-
|
|
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 = {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
"
|
|
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
|
-
}
|
|
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
|
-
"
|
|
344
|
-
"
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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 = {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
-
"
|
|
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
|
-
}
|
|
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
|
-
"
|
|
452
|
-
"
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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);
|