@oas-tools/oas-telemetry 0.6.2 → 0.7.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +442 -442
- package/dist/{config.cjs → cjs/config.cjs} +6 -7
- package/dist/{exporters → cjs/exporters}/InMemoryDBMetricsExporter.cjs +5 -40
- package/dist/cjs/exporters/InMemoryDbExporter.cjs +87 -0
- package/dist/cjs/exporters/InMemoryLogRecordExporter.cjs +110 -0
- package/dist/{exporters → cjs/exporters}/consoleExporter.cjs +2 -7
- package/dist/{exporters → cjs/exporters}/dynamicExporter.cjs +12 -19
- package/dist/cjs/index.cjs +43 -0
- package/dist/cjs/instrumentation/index.cjs +28 -0
- package/dist/cjs/instrumentation/logs.cjs +46 -0
- package/dist/cjs/instrumentation/metrics.cjs +27 -0
- package/dist/cjs/instrumentation/traces.cjs +19 -0
- package/dist/{openTelemetry.cjs → cjs/openTelemetry.cjs} +6 -8
- package/dist/{systemMetrics.cjs → cjs/systemMetrics.cjs} +7 -7
- package/dist/cjs/tlm-ai/agent.cjs +79 -0
- package/dist/cjs/tlm-ai/aiController.cjs +69 -0
- package/dist/cjs/tlm-ai/aiRoutes.cjs +13 -0
- package/dist/cjs/tlm-ai/knownMicroservices.cjs +13 -0
- package/dist/cjs/tlm-ai/tools.cjs +504 -0
- package/dist/{routes/authRoutes.cjs → cjs/tlm-auth/authController.cjs} +21 -28
- package/dist/{middleware → cjs/tlm-auth}/authMiddleware.cjs +1 -1
- package/dist/cjs/tlm-auth/authRoutes.cjs +14 -0
- package/dist/cjs/tlm-log/logController.cjs +55 -0
- package/dist/cjs/tlm-log/logRoutes.cjs +13 -0
- package/dist/{routes → cjs/tlm-metric}/metricsRoutes.cjs +1 -2
- package/dist/{controllers → cjs/tlm-plugin}/pluginController.cjs +31 -41
- package/dist/cjs/tlm-plugin/pluginRoutes.cjs +13 -0
- package/dist/{controllers/telemetryController.cjs → cjs/tlm-trace/traceController.cjs} +8 -19
- package/dist/cjs/tlm-trace/traceRoutes.cjs +17 -0
- package/dist/cjs/tlm-ui/uiController.cjs +27 -0
- package/dist/cjs/tlm-ui/uiRoutes.cjs +31 -0
- package/dist/cjs/tlm-util/utilController.cjs +63 -0
- package/dist/cjs/tlm-util/utilRoutes.cjs +12 -0
- package/dist/cjs/tlmRoutes.cjs +79 -0
- package/dist/cjs/types/index.cjs +8 -0
- package/dist/cjs/utils/circular.cjs +90 -0
- package/dist/cjs/utils/logger.cjs +28 -0
- package/{src → dist/esm}/config.js +20 -23
- package/{src → dist/esm}/exporters/InMemoryDBMetricsExporter.js +57 -111
- package/dist/esm/exporters/InMemoryDbExporter.js +87 -0
- package/dist/esm/exporters/InMemoryLogRecordExporter.js +95 -0
- package/{src → dist/esm}/exporters/consoleExporter.js +38 -47
- package/{src → dist/esm}/exporters/dynamicExporter.js +50 -62
- package/dist/esm/index.js +39 -0
- package/dist/esm/instrumentation/index.js +26 -0
- package/dist/esm/instrumentation/logs.js +34 -0
- package/dist/esm/instrumentation/metrics.js +18 -0
- package/dist/esm/instrumentation/traces.js +12 -0
- package/{src → dist/esm}/openTelemetry.js +50 -58
- package/dist/esm/systemMetrics.js +82 -0
- package/dist/esm/tlm-ai/agent.js +68 -0
- package/dist/esm/tlm-ai/aiController.js +45 -0
- package/dist/esm/tlm-ai/aiRoutes.js +7 -0
- package/dist/esm/tlm-ai/knownMicroservices.js +5 -0
- package/dist/esm/tlm-ai/tools.js +490 -0
- package/dist/esm/tlm-auth/authController.js +41 -0
- package/{src/middleware → dist/esm/tlm-auth}/authMiddleware.js +12 -14
- package/dist/esm/tlm-auth/authRoutes.js +7 -0
- package/dist/esm/tlm-log/logController.js +36 -0
- package/dist/esm/tlm-log/logRoutes.js +7 -0
- package/{src/controllers → dist/esm/tlm-metric}/metricsController.js +28 -30
- package/{src/routes → dist/esm/tlm-metric}/metricsRoutes.js +8 -15
- package/{src/controllers → dist/esm/tlm-plugin}/pluginController.js +103 -115
- package/dist/esm/tlm-plugin/pluginRoutes.js +7 -0
- package/dist/esm/tlm-trace/traceController.js +54 -0
- package/dist/esm/tlm-trace/traceRoutes.js +11 -0
- package/dist/esm/tlm-ui/uiController.js +20 -0
- package/dist/esm/tlm-ui/uiRoutes.js +23 -0
- package/dist/esm/tlm-util/utilController.js +57 -0
- package/dist/esm/tlm-util/utilRoutes.js +6 -0
- package/dist/esm/tlmRoutes.js +72 -0
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/utils/circular.js +84 -0
- package/dist/esm/utils/logger.js +19 -0
- package/dist/types/config.d.ts +6 -0
- package/dist/types/exporters/InMemoryDBMetricsExporter.d.ts +15 -0
- package/dist/types/exporters/InMemoryDbExporter.d.ts +24 -0
- package/dist/types/exporters/InMemoryLogRecordExporter.d.ts +27 -0
- package/dist/types/exporters/consoleExporter.d.ts +13 -0
- package/dist/types/exporters/dynamicExporter.d.ts +25 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/instrumentation/index.d.ts +1 -0
- package/dist/types/instrumentation/logs.d.ts +1 -0
- package/dist/types/instrumentation/metrics.d.ts +1 -0
- package/dist/types/instrumentation/traces.d.ts +1 -0
- package/dist/types/openTelemetry.d.ts +1 -0
- package/dist/types/systemMetrics.d.ts +26 -0
- package/dist/types/tlm-ai/agent.d.ts +1 -0
- package/dist/types/tlm-ai/aiController.d.ts +4 -0
- package/dist/types/tlm-ai/aiRoutes.d.ts +2 -0
- package/dist/types/tlm-ai/knownMicroservices.d.ts +6 -0
- package/dist/types/tlm-ai/tools.d.ts +45 -0
- package/dist/types/tlm-auth/authController.d.ts +4 -0
- package/dist/types/tlm-auth/authMiddleware.d.ts +2 -0
- package/dist/types/tlm-auth/authRoutes.d.ts +2 -0
- package/dist/types/tlm-log/logController.d.ts +4 -0
- package/dist/types/tlm-log/logRoutes.d.ts +2 -0
- package/dist/types/tlm-metric/metricsController.d.ts +4 -0
- package/dist/types/tlm-metric/metricsRoutes.d.ts +2 -0
- package/dist/types/tlm-plugin/pluginController.d.ts +3 -0
- package/dist/types/tlm-plugin/pluginRoutes.d.ts +2 -0
- package/dist/types/tlm-trace/traceController.d.ts +7 -0
- package/dist/types/tlm-trace/traceRoutes.d.ts +2 -0
- package/dist/types/tlm-ui/uiController.d.ts +8 -0
- package/dist/types/tlm-ui/uiRoutes.d.ts +2 -0
- package/dist/types/tlm-util/utilController.d.ts +3 -0
- package/dist/types/tlm-util/utilRoutes.d.ts +2 -0
- package/dist/types/tlmRoutes.d.ts +2 -0
- package/dist/types/types/index.d.ts +56 -0
- package/dist/types/utils/circular.d.ts +31 -0
- package/dist/types/utils/logger.d.ts +9 -0
- package/dist/ui/assets/index-BNhZBPi2.css +1 -0
- package/dist/ui/assets/index-DxGAMrAl.js +401 -0
- package/dist/ui/index.html +14 -0
- package/dist/ui/vite.svg +1 -0
- package/package.json +80 -77
- package/dist/controllers/uiController.cjs +0 -78
- package/dist/exporters/InMemoryDbExporter.cjs +0 -178
- package/dist/index.cjs +0 -110
- package/dist/routes/telemetryRoutes.cjs +0 -31
- package/dist/services/uiService.cjs +0 -1520
- package/src/controllers/telemetryController.js +0 -69
- package/src/controllers/uiController.js +0 -69
- package/src/dev/ui/login.html +0 -32
- package/src/exporters/InMemoryDbExporter.js +0 -181
- package/src/index.js +0 -121
- package/src/routes/authRoutes.js +0 -53
- package/src/routes/telemetryRoutes.js +0 -38
- package/src/services/uiService.js +0 -1520
- package/src/systemMetrics.js +0 -102
- /package/dist/{controllers → cjs/tlm-metric}/metricsController.cjs +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>OAS-Telemetry</title>
|
|
8
|
+
<script type="module" crossorigin src="./assets/index-DxGAMrAl.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BNhZBPi2.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
package/dist/ui/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
CHANGED
|
@@ -1,77 +1,80 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@oas-tools/oas-telemetry",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "Manuel Otero",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Alejandro Santisteban",
|
|
8
|
-
"Pablo Fernandez"
|
|
9
|
-
],
|
|
10
|
-
"license": "Apache-2.0",
|
|
11
|
-
"type": "module",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"@
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"babel-plugin-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@oas-tools/oas-telemetry",
|
|
3
|
+
"version": "0.7.0-alpha.0",
|
|
4
|
+
"description": "Automatically collects and stores telemetry data in memory using OpenTelemetry. Just import the Express middleware to access it through the built-in REST API or web UI—no extra setup required.",
|
|
5
|
+
"author": "Manuel Otero",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Alejandro Santisteban",
|
|
8
|
+
"Pablo Fernandez"
|
|
9
|
+
],
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "tsx test/functional/otTestServer.ts",
|
|
14
|
+
"esm": "echo 'Remember to execute: \"npm run build\"' && node test/functional/otTestServer.mjs",
|
|
15
|
+
"cjs": "echo 'Remember to execute: \"npm run build\"' && node test/functional/otTestServer.cjs",
|
|
16
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
17
|
+
"build:esm": "tsc -p tsconfig.json",
|
|
18
|
+
"build:cjs": "babel ./dist/esm -d ./dist/cjs --out-file-extension .cjs --config-file ./.babelrc",
|
|
19
|
+
"lint": "eslint --ext .ts . --fix"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"main": "./dist/cjs/index.cjs",
|
|
25
|
+
"module": "./dist/esm/index.js",
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"require": "./dist/cjs/index.cjs",
|
|
30
|
+
"import": "./dist/esm/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@opentelemetry/core": "^2.0.1",
|
|
38
|
+
"@opentelemetry/host-metrics": "^0.36.0",
|
|
39
|
+
"@opentelemetry/instrumentation": "^0.202.0",
|
|
40
|
+
"@opentelemetry/instrumentation-http": "^0.51.0",
|
|
41
|
+
"@opentelemetry/sdk-logs": "^0.202.0",
|
|
42
|
+
"@opentelemetry/sdk-metrics": "^2.0.1",
|
|
43
|
+
"@opentelemetry/sdk-trace-node": "^2.0.1",
|
|
44
|
+
"@opentelemetry/semantic-conventions": "^1.34.0",
|
|
45
|
+
"@seald-io/nedb": "^4.0.4",
|
|
46
|
+
"axios": "^1.10.0",
|
|
47
|
+
"cookie-parser": "^1.4.7",
|
|
48
|
+
"cors": "^2.8.5",
|
|
49
|
+
"dotenv": "^16.5.0",
|
|
50
|
+
"dynamic-installer": "^1.1.1",
|
|
51
|
+
"express": "^4.21.2",
|
|
52
|
+
"import-from-string": "^0.0.4",
|
|
53
|
+
"js-yaml": "^4.1.0",
|
|
54
|
+
"jsonwebtoken": "^9.0.2",
|
|
55
|
+
"minisearch": "^7.1.2",
|
|
56
|
+
"openai": "^5.6.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@babel/cli": "^7.24.1",
|
|
60
|
+
"@babel/core": "^7.24.4",
|
|
61
|
+
"@babel/plugin-transform-class-properties": "^7.27.1",
|
|
62
|
+
"@babel/plugin-transform-object-rest-spread": "^7.27.3",
|
|
63
|
+
"@babel/preset-env": "^7.24.4",
|
|
64
|
+
"@eslint/js": "^9.29.0",
|
|
65
|
+
"@opentelemetry/api": "^1.8.0",
|
|
66
|
+
"@types/cookie-parser": "^1.4.9",
|
|
67
|
+
"@types/cors": "^2.8.19",
|
|
68
|
+
"@types/express": "^5.0.3",
|
|
69
|
+
"@types/js-yaml": "^4.0.9",
|
|
70
|
+
"@types/jsonwebtoken": "^9.0.9",
|
|
71
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
72
|
+
"babel-plugin-module-extension": "^0.1.3",
|
|
73
|
+
"babel-plugin-transform-import-meta": "^2.3.3",
|
|
74
|
+
"eslint": "^9.29.0",
|
|
75
|
+
"eslint-plugin-import": "^2.32.0",
|
|
76
|
+
"tsx": "^4.20.1",
|
|
77
|
+
"typescript": "^5.8.3",
|
|
78
|
+
"typescript-eslint": "^8.34.1"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.specLoader = exports.mainPage = exports.detailPage = exports.apiPage = void 0;
|
|
7
|
-
var _config = require("../config.cjs");
|
|
8
|
-
var _fs = require("fs");
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
11
|
-
var _uiService = _interopRequireDefault(require("../services/uiService.cjs"));
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
const apiPage = (req, res) => {
|
|
14
|
-
const baseURL = _config.globalOasTlmConfig.baseURL;
|
|
15
|
-
let text = `
|
|
16
|
-
<h1>Telemetry API routes:</h1>
|
|
17
|
-
<ul>
|
|
18
|
-
<li><a href="${baseURL}/start">${baseURL}/start</a></li>
|
|
19
|
-
<li><a href="${baseURL}/stop">${baseURL}/stop</a></li>
|
|
20
|
-
<li><a href="${baseURL}/status">${baseURL}/status</a></li>
|
|
21
|
-
<li><a href="${baseURL}/reset">${baseURL}/reset</a></li>
|
|
22
|
-
<li><a href="${baseURL}/list">${baseURL}/list</a></li>
|
|
23
|
-
<li><a href="${baseURL}/heapStats">${baseURL}/heapStats</a></li>
|
|
24
|
-
<li>${baseURL}/find [POST]</li>
|
|
25
|
-
</ul>
|
|
26
|
-
`;
|
|
27
|
-
res.send(text);
|
|
28
|
-
};
|
|
29
|
-
exports.apiPage = apiPage;
|
|
30
|
-
const mainPage = (req, res) => {
|
|
31
|
-
const baseURL = _config.globalOasTlmConfig.baseURL;
|
|
32
|
-
res.set('Content-Type', 'text/html');
|
|
33
|
-
res.send((0, _uiService.default)(baseURL).main);
|
|
34
|
-
};
|
|
35
|
-
exports.mainPage = mainPage;
|
|
36
|
-
const detailPage = (req, res) => {
|
|
37
|
-
const baseURL = _config.globalOasTlmConfig.baseURL;
|
|
38
|
-
res.set('Content-Type', 'text/html');
|
|
39
|
-
res.send((0, _uiService.default)(baseURL).detail);
|
|
40
|
-
};
|
|
41
|
-
exports.detailPage = detailPage;
|
|
42
|
-
const specLoader = (req, res) => {
|
|
43
|
-
if (_config.globalOasTlmConfig.specFileName) {
|
|
44
|
-
try {
|
|
45
|
-
const data = (0, _fs.readFileSync)(_config.globalOasTlmConfig.specFileName, {
|
|
46
|
-
encoding: 'utf8',
|
|
47
|
-
flag: 'r'
|
|
48
|
-
});
|
|
49
|
-
const extension = _path.default.extname(_config.globalOasTlmConfig.specFileName);
|
|
50
|
-
let json = data;
|
|
51
|
-
if (extension == _jsYaml.default) json = JSON.stringify(_jsYaml.default.SafeLoad(data), null, 2);
|
|
52
|
-
res.setHeader('Content-Type', 'application/json');
|
|
53
|
-
res.send(json);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
console.error(`ERROR loading spec file ${_config.globalOasTlmConfig.specFileName}: ${e}`);
|
|
56
|
-
}
|
|
57
|
-
} else if (_config.globalOasTlmConfig.spec) {
|
|
58
|
-
let spec = false;
|
|
59
|
-
try {
|
|
60
|
-
spec = JSON.parse(_config.globalOasTlmConfig.spec);
|
|
61
|
-
} catch (ej) {
|
|
62
|
-
try {
|
|
63
|
-
spec = JSON.stringify(_jsYaml.default.load(_config.globalOasTlmConfig.spec), null, 2);
|
|
64
|
-
} catch (ey) {
|
|
65
|
-
console.error(`Error parsing spec: ${ej} - ${ey}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (!spec) {
|
|
69
|
-
res.status(404);
|
|
70
|
-
} else {
|
|
71
|
-
res.setHeader('Content-Type', 'application/json');
|
|
72
|
-
res.send(spec);
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
res.status(404);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
exports.specLoader = specLoader;
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.InMemoryExporter = void 0;
|
|
7
|
-
var _core = require("@opentelemetry/core");
|
|
8
|
-
var _nedb = _interopRequireDefault(require("@seald-io/nedb"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
12
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
-
let dbglog = () => {};
|
|
14
|
-
if (process.env.OTDEBUG == "true") dbglog = console.log;
|
|
15
|
-
|
|
16
|
-
//import in memory database
|
|
17
|
-
|
|
18
|
-
class InMemoryExporter {
|
|
19
|
-
constructor() {
|
|
20
|
-
// Overrided by dynamic exporter
|
|
21
|
-
_defineProperty(this, "plugins", []);
|
|
22
|
-
this._spans = new _nedb.default();
|
|
23
|
-
this._stopped = true;
|
|
24
|
-
}
|
|
25
|
-
export(readableSpans, resultCallback) {
|
|
26
|
-
try {
|
|
27
|
-
if (!this._stopped) {
|
|
28
|
-
// Prepare spans to be inserted into the in-memory database (remove circular references and convert to nested objects)
|
|
29
|
-
const cleanSpans = readableSpans.map(nestedSpan => removeCircularRefs(nestedSpan)) // to avoid JSON parsing error
|
|
30
|
-
.map(span => applyNesting(span)) // to avoid dot notation in keys (neDB does not support dot notation in keys)
|
|
31
|
-
.filter(span => !span.attributes?.http?.target?.includes("/telemetry")); // to avoid telemetry spans
|
|
32
|
-
// Insert spans into the in-memory database
|
|
33
|
-
this._spans.insert(cleanSpans, (err, newDoc) => {
|
|
34
|
-
// p = {name, plugin
|
|
35
|
-
this.plugins.forEach((pluginResource, i) => {
|
|
36
|
-
cleanSpans.forEach(t => {
|
|
37
|
-
dbglog(`Sending trace <${t._id}> to plugin (Plugin #${i}) <${pluginResource.name}>`);
|
|
38
|
-
dbglog(`Trace: \n<${JSON.stringify(t, null, 2)}`);
|
|
39
|
-
//TODO: This should be called newSpan instead of newTrace
|
|
40
|
-
pluginResource.plugin.newTrace(t);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
if (err) {
|
|
44
|
-
console.error(err);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
setTimeout(() => resultCallback({
|
|
50
|
-
code: _core.ExportResultCode.SUCCESS
|
|
51
|
-
}), 0);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error('Error exporting spans\n' + error.message + '\n' + error.stack);
|
|
54
|
-
return resultCallback({
|
|
55
|
-
code: _core.ExportResultCode.FAILED,
|
|
56
|
-
error: new Error('Error exporting spans\n' + error.message + '\n' + error.stack)
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
start() {
|
|
61
|
-
this._stopped = false;
|
|
62
|
-
}
|
|
63
|
-
stop() {
|
|
64
|
-
this._stopped = true;
|
|
65
|
-
}
|
|
66
|
-
isRunning() {
|
|
67
|
-
return !this._stopped;
|
|
68
|
-
}
|
|
69
|
-
shutdown() {
|
|
70
|
-
this._stopped = true;
|
|
71
|
-
this._spans = new _nedb.default();
|
|
72
|
-
return this.forceFlush();
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Exports any pending spans in the exporter
|
|
76
|
-
*/
|
|
77
|
-
forceFlush() {
|
|
78
|
-
return Promise.resolve();
|
|
79
|
-
}
|
|
80
|
-
//err,docs
|
|
81
|
-
find(search, callback) {
|
|
82
|
-
this._spans.find(search, callback);
|
|
83
|
-
}
|
|
84
|
-
reset() {
|
|
85
|
-
this._spans = new _nedb.default();
|
|
86
|
-
}
|
|
87
|
-
getFinishedSpans() {
|
|
88
|
-
return this._spans.getAllData();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.InMemoryExporter = InMemoryExporter;
|
|
92
|
-
function removeCircularRefs(obj) {
|
|
93
|
-
const seen = new WeakMap(); // Used to keep track of visited objects
|
|
94
|
-
|
|
95
|
-
// Replacer function to handle circular references
|
|
96
|
-
function replacer(key, value) {
|
|
97
|
-
if (key === "_spanProcessor") {
|
|
98
|
-
return "oas-telemetry skips this field to avoid circular reference";
|
|
99
|
-
}
|
|
100
|
-
// GENERIC CIRCULAR REFERENCE HANDLING
|
|
101
|
-
// if (typeof value === "object" && value !== null) {
|
|
102
|
-
// // If the object has been visited before, return the name prefixed with "CIRCULAR+"
|
|
103
|
-
// if (seen.has(value)) {
|
|
104
|
-
// return `CIRCULAR${key}`;
|
|
105
|
-
// }
|
|
106
|
-
// seen.set(value, key); // Mark the object as visited with its name
|
|
107
|
-
// }
|
|
108
|
-
return value;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Convert the object to a string and then parse it back
|
|
112
|
-
// This will trigger the replacer function to handle circular references
|
|
113
|
-
const jsonString = JSON.stringify(obj, replacer);
|
|
114
|
-
return JSON.parse(jsonString);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Recursively converts dot-separated keys in an object to nested objects.
|
|
119
|
-
*
|
|
120
|
-
* @param {Object} obj - The object to process.
|
|
121
|
-
* @returns {Object} - The object with all dot-separated keys converted to nested objects.
|
|
122
|
-
* @example
|
|
123
|
-
* // Input:
|
|
124
|
-
* // {
|
|
125
|
-
* // "http.method": "GET",
|
|
126
|
-
* // "http.url": "http://example.com",
|
|
127
|
-
* // "nested.obj.key": "value"
|
|
128
|
-
* // }
|
|
129
|
-
* // Output:
|
|
130
|
-
* // {
|
|
131
|
-
* // "http": {
|
|
132
|
-
* // "method": "GET",
|
|
133
|
-
* // "url": "http://example.com"
|
|
134
|
-
* // },
|
|
135
|
-
* // "nested": {
|
|
136
|
-
* // "obj": {
|
|
137
|
-
* // "key": "value"
|
|
138
|
-
* // }
|
|
139
|
-
* // }
|
|
140
|
-
* // }
|
|
141
|
-
*/
|
|
142
|
-
function convertToNestedObject(obj) {
|
|
143
|
-
const result = {};
|
|
144
|
-
for (const key in obj) {
|
|
145
|
-
const keys = key.split('.');
|
|
146
|
-
let temp = result;
|
|
147
|
-
for (let i = 0; i < keys.length; i++) {
|
|
148
|
-
const currentKey = keys[i];
|
|
149
|
-
if (i === keys.length - 1) {
|
|
150
|
-
// Last key, set the value
|
|
151
|
-
temp[currentKey] = obj[key];
|
|
152
|
-
} else {
|
|
153
|
-
// Intermediate key, ensure the object exists
|
|
154
|
-
if (!temp[currentKey]) {
|
|
155
|
-
temp[currentKey] = {};
|
|
156
|
-
}
|
|
157
|
-
temp = temp[currentKey];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Applies nesting to all dot-separated keys within an object.
|
|
166
|
-
*
|
|
167
|
-
* @param {Object} obj - The object to apply nesting to.
|
|
168
|
-
* @returns {Object} - The transformed object with nested structures.
|
|
169
|
-
*/
|
|
170
|
-
function applyNesting(obj) {
|
|
171
|
-
// Recursively apply convertToNestedObject to each level of the object
|
|
172
|
-
for (const key in obj) {
|
|
173
|
-
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
174
|
-
obj[key] = applyNesting(obj[key]);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return convertToNestedObject(obj);
|
|
178
|
-
}
|
package/dist/index.cjs
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = oasTelemetry;
|
|
7
|
-
require("./openTelemetry.cjs");
|
|
8
|
-
var _config = require("./config.cjs");
|
|
9
|
-
var _cookieParser = _interopRequireDefault(require("cookie-parser"));
|
|
10
|
-
var _express = require("express");
|
|
11
|
-
var _authMiddleware = require("./middleware/authMiddleware.cjs");
|
|
12
|
-
var _authRoutes = _interopRequireDefault(require("./routes/authRoutes.cjs"));
|
|
13
|
-
var _telemetryRoutes = require("./routes/telemetryRoutes.cjs");
|
|
14
|
-
var _InMemoryDbExporter = require("./exporters/InMemoryDbExporter.cjs");
|
|
15
|
-
var _metricsRoutes = _interopRequireDefault(require("./routes/metricsRoutes.cjs"));
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
let dbglog = () => {};
|
|
18
|
-
if (process.env.OTDEBUG == "true") dbglog = console.log;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Returns the Oas Telemetry middleware. The parameters are the same as `globalOasTlmConfig`.
|
|
22
|
-
* All parameters are optional. However, either `spec` or `specFileName` must be provided to enable endpoint filtering.
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} OasTlmConfig Configuration object.
|
|
25
|
-
* @param {string} [OasTlmConfig.baseURL="/telemetry"] The base URL for the telemetry routes.
|
|
26
|
-
* @param {Object} [OasTlmConfig.spec] The OpenAPI spec object.
|
|
27
|
-
* @param {string} [OasTlmConfig.specFileName] Alternative to `spec`: the path to the OpenAPI spec file.
|
|
28
|
-
* @param {boolean} [OasTlmConfig.autoActivate=true] Whether to start telemetry automatically on load.
|
|
29
|
-
* @param {boolean} [OasTlmConfig.authEnabled=true] Whether to enable authentication middleware.
|
|
30
|
-
* @param {number} [OasTlmConfig.apiKeyMaxAge=1800000] The maximum age of the API key in milliseconds.
|
|
31
|
-
* @param {string} [OasTlmConfig.defaultApiKey] The default API key to use.
|
|
32
|
-
* @param {OasTlmExporter} [OasTlmConfig.exporter=InMemoryExporter] The exporter to use. Must implement the `OasTlmExporter` interface.
|
|
33
|
-
* @returns {Router} The middleware router for Oas Telemetry.
|
|
34
|
-
*/
|
|
35
|
-
function oasTelemetry(OasTlmConfig) {
|
|
36
|
-
const router = (0, _express.Router)();
|
|
37
|
-
if (process.env.OASTLM_MODULE_DISABLED === 'true') {
|
|
38
|
-
return router;
|
|
39
|
-
}
|
|
40
|
-
;
|
|
41
|
-
if (OasTlmConfig) {
|
|
42
|
-
console.log("User provided config");
|
|
43
|
-
// Global = user-provided || default, for each key
|
|
44
|
-
for (const key in _config.globalOasTlmConfig) {
|
|
45
|
-
_config.globalOasTlmConfig[key] = OasTlmConfig[key] ?? _config.globalOasTlmConfig[key];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
console.log("baseURL: ", _config.globalOasTlmConfig.baseURL);
|
|
49
|
-
_config.globalOasTlmConfig.dynamicExporter.changeExporter(_config.globalOasTlmConfig.exporter ?? new _InMemoryDbExporter.InMemoryExporter());
|
|
50
|
-
if (_config.globalOasTlmConfig.spec) dbglog(`Spec content provided`);else {
|
|
51
|
-
if (_config.globalOasTlmConfig.specFileName != "") dbglog(`Spec file used for telemetry: ${_config.globalOasTlmConfig.specFileName}`);else {
|
|
52
|
-
console.error("No spec available !");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
let allAuthMiddlewares = getWrappedMiddlewares(() => _config.globalOasTlmConfig.authEnabled, [(0, _cookieParser.default)(), _authRoutes.default, _authMiddleware.authMiddleware]);
|
|
56
|
-
const baseURL = _config.globalOasTlmConfig.baseURL;
|
|
57
|
-
router.use((0, _express.json)());
|
|
58
|
-
router.use(baseURL, allAuthMiddlewares);
|
|
59
|
-
router.use(baseURL, _telemetryRoutes.telemetryRoutes);
|
|
60
|
-
router.use(baseURL + "/metrics", _metricsRoutes.default);
|
|
61
|
-
if (_config.globalOasTlmConfig.autoActivate) {
|
|
62
|
-
_config.globalOasTlmConfig.dynamicExporter.exporter?.start();
|
|
63
|
-
}
|
|
64
|
-
return router;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @typedef OasTlmExporter
|
|
69
|
-
* Represents an exporter that processes and manages telemetry data.
|
|
70
|
-
* Any custom exporter must implement these methods.
|
|
71
|
-
*
|
|
72
|
-
* @method {void} start() Starts the exporter, allowing it to process data.
|
|
73
|
-
* @method {void} stop() Stops the exporter and halts data processing.
|
|
74
|
-
* @method {void} reset() Resets the internal state of the exporter (e.g., clears buffers or data stores).
|
|
75
|
-
* @method {boolean} isRunning() Returns whether the exporter is actively processing data.
|
|
76
|
-
* @method {Array} getFinishedSpans() Retrieves the collected spans from the exporter.
|
|
77
|
-
* @method {any} export(ReadableSpan, SpanExporterResultCallback) Exports spans.
|
|
78
|
-
* @method {Promise<void>} shutdown() Gracefully shuts down the exporter, flushing data if necessary.
|
|
79
|
-
* @method {Promise<void>} forceFlush() Exports any pending data that has not yet been processed.
|
|
80
|
-
* @property {Array} plugins An array of plugins that can be activated by the exporter.
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* This function wraps the provided middleware functions with a condition callback.
|
|
85
|
-
* If the condition callback returns true, the middleware/router will be executed.
|
|
86
|
-
* If the condition callback returns false, the middleware/router will be skipped.
|
|
87
|
-
*
|
|
88
|
-
* @callback {function} conditionCallback A callback function that returns a boolean to determine if the middleware should be used.
|
|
89
|
-
* @param {Array} middlewares An array of middleware or routers to be wrapped.
|
|
90
|
-
* @returns {Array} An array of wrapped middleware functions.
|
|
91
|
-
*/
|
|
92
|
-
function getWrappedMiddlewares(conditionCallback, middlewares) {
|
|
93
|
-
return middlewares.map(middleware => {
|
|
94
|
-
return function (req, res, next) {
|
|
95
|
-
if (conditionCallback()) {
|
|
96
|
-
if (typeof middleware === 'function') {
|
|
97
|
-
// look for handle property, if it exists, it's a router. If not call middleware
|
|
98
|
-
if (middleware.handle) {
|
|
99
|
-
middleware.handle(req, res, next);
|
|
100
|
-
} else {
|
|
101
|
-
middleware(req, res, next);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
next();
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
module.exports = exports.default;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.telemetryRoutes = exports.default = void 0;
|
|
7
|
-
var _express = require("express");
|
|
8
|
-
var _uiController = require("../controllers/uiController.cjs");
|
|
9
|
-
var _telemetryController = require("../controllers/telemetryController.cjs");
|
|
10
|
-
var _pluginController = require("../controllers/pluginController.cjs");
|
|
11
|
-
const telemetryRoutes = exports.telemetryRoutes = (0, _express.Router)();
|
|
12
|
-
|
|
13
|
-
// Main Pages
|
|
14
|
-
telemetryRoutes.get('/', _uiController.mainPage);
|
|
15
|
-
telemetryRoutes.get('/detail/*', _uiController.detailPage);
|
|
16
|
-
telemetryRoutes.get('/spec', _uiController.specLoader);
|
|
17
|
-
telemetryRoutes.get('/api', _uiController.apiPage);
|
|
18
|
-
|
|
19
|
-
// Telemetry Control
|
|
20
|
-
telemetryRoutes.get('/start', _telemetryController.startTelemetry);
|
|
21
|
-
telemetryRoutes.get('/stop', _telemetryController.stopTelemetry);
|
|
22
|
-
telemetryRoutes.get('/status', _telemetryController.statusTelemetry);
|
|
23
|
-
telemetryRoutes.get('/reset', _telemetryController.resetTelemetry);
|
|
24
|
-
telemetryRoutes.get('/list', _telemetryController.listTelemetry);
|
|
25
|
-
telemetryRoutes.post('/find', _telemetryController.findTelemetry);
|
|
26
|
-
telemetryRoutes.get('/heapStats', _telemetryController.heapStats);
|
|
27
|
-
|
|
28
|
-
// Plugins
|
|
29
|
-
telemetryRoutes.get('/plugins', _pluginController.listPlugins);
|
|
30
|
-
telemetryRoutes.post('/plugins', _pluginController.registerPlugin);
|
|
31
|
-
var _default = exports.default = telemetryRoutes;
|