@oas-tools/oas-telemetry 0.5.0 → 0.5.2
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 +277 -41
- package/dist/config.cjs +2 -2
- package/dist/controllers/telemetryController.cjs +15 -15
- package/dist/exporters/InMemoryDbExporter.cjs +1 -1
- package/dist/index.cjs +31 -3
- package/dist/openTelemetry.cjs +16 -1
- package/package.json +3 -2
- package/src/config.js +2 -2
- package/src/controllers/telemetryController.js +2 -1
- package/src/exporters/InMemoryDbExporter.js +1 -1
- package/src/index.js +32 -5
- package/src/openTelemetry.js +16 -2
- package/src/services/uiService.js +21 -21
- package/dist/client.cjs +0 -14
- package/dist/middleware/auth.cjs +0 -17
- package/dist/telemetry.cjs +0 -23
- package/dist/types/exporters/InMemoryDbExporter.d.ts +0 -16
- package/dist/types/index.d.ts +0 -1
- package/dist/types/telemetry.d.ts +0 -2
- package/dist/types/ui.d.ts +0 -4
- package/dist/ui.cjs +0 -1200
package/src/index.js
CHANGED
|
@@ -22,6 +22,7 @@ if (process.env.OTDEBUG == "true")
|
|
|
22
22
|
* @param {Object} [OasTlmConfig.spec] The OpenAPI spec object.
|
|
23
23
|
* @param {string} [OasTlmConfig.specFileName] Alternative to `spec`: the path to the OpenAPI spec file.
|
|
24
24
|
* @param {boolean} [OasTlmConfig.autoActivate=true] Whether to start telemetry automatically on load.
|
|
25
|
+
* @param {boolean} [OasTlmConfig.authEnabled=true] Whether to enable authentication middleware.
|
|
25
26
|
* @param {number} [OasTlmConfig.apiKeyMaxAge=1800000] The maximum age of the API key in milliseconds.
|
|
26
27
|
* @param {string} [OasTlmConfig.defaultApiKey] The default API key to use.
|
|
27
28
|
* @param {OasTlmExporter} [OasTlmConfig.exporter=InMemoryExporter] The exporter to use. Must implement the `OasTlmExporter` interface.
|
|
@@ -51,12 +52,10 @@ export default function oasTelemetry(OasTlmConfig) {
|
|
|
51
52
|
console.error("No spec available !");
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
router.use(cookieParser());
|
|
55
|
+
let allAuthMiddlewares = getWrappedMiddlewares(() => globalOasTlmConfig.authEnabled, [cookieParser(),authRoutes,authMiddleware]);
|
|
56
56
|
const baseURL = globalOasTlmConfig.baseURL;
|
|
57
57
|
router.use(json());
|
|
58
|
-
router.use(baseURL,
|
|
59
|
-
router.use(baseURL, authMiddleware); // Add the auth middleware
|
|
58
|
+
router.use(baseURL, allAuthMiddlewares);
|
|
60
59
|
router.use(baseURL, telemetryRoutes);
|
|
61
60
|
|
|
62
61
|
if (globalOasTlmConfig.autoActivate) {
|
|
@@ -67,7 +66,6 @@ export default function oasTelemetry(OasTlmConfig) {
|
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
|
|
70
|
-
|
|
71
69
|
/**
|
|
72
70
|
* @typedef OasTlmExporter
|
|
73
71
|
* Represents an exporter that processes and manages telemetry data.
|
|
@@ -83,3 +81,32 @@ export default function oasTelemetry(OasTlmConfig) {
|
|
|
83
81
|
* @method {Promise<void>} forceFlush() Exports any pending data that has not yet been processed.
|
|
84
82
|
* @property {Array} plugins An array of plugins that can be activated by the exporter.
|
|
85
83
|
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* This function wraps the provided middleware functions with a condition callback.
|
|
87
|
+
* If the condition callback returns true, the middleware/router will be executed.
|
|
88
|
+
* If the condition callback returns false, the middleware/router will be skipped.
|
|
89
|
+
*
|
|
90
|
+
* @callback {function} conditionCallback A callback function that returns a boolean to determine if the middleware should be used.
|
|
91
|
+
* @param {Array} middlewares An array of middleware or routers to be wrapped.
|
|
92
|
+
* @returns {Array} An array of wrapped middleware functions.
|
|
93
|
+
*/
|
|
94
|
+
function getWrappedMiddlewares(conditionCallback, middlewares) {
|
|
95
|
+
return middlewares.map(middleware => {
|
|
96
|
+
return function (req, res, next) {
|
|
97
|
+
if (conditionCallback()) {
|
|
98
|
+
if (typeof middleware === 'function') {
|
|
99
|
+
// look for handle property, if it exists, it's a router. If not call middleware
|
|
100
|
+
if (middleware.handle) {
|
|
101
|
+
middleware.handle(req, res, next);
|
|
102
|
+
} else {
|
|
103
|
+
middleware(req, res, next);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
next();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
}
|
package/src/openTelemetry.js
CHANGED
|
@@ -8,7 +8,7 @@ import { globalOasTlmConfig } from './config.js';
|
|
|
8
8
|
|
|
9
9
|
// DynamicExporter allows changing to any exporter at runtime;
|
|
10
10
|
const traceExporter = globalOasTlmConfig.dynamicExporter;
|
|
11
|
-
|
|
11
|
+
// Alternative 1: Using NodeSDK
|
|
12
12
|
const sdk = new NodeSDK({
|
|
13
13
|
resource: new Resource({
|
|
14
14
|
service: 'oas-telemetry-service'
|
|
@@ -19,4 +19,18 @@ import { globalOasTlmConfig } from './config.js';
|
|
|
19
19
|
|
|
20
20
|
if (process.env.OASTLM_MODULE_DISABLED !== 'true') {
|
|
21
21
|
sdk.start()
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Alternative 2:
|
|
25
|
+
// const provider = new NodeTracerProvider();
|
|
26
|
+
// provider.addSpanProcessor(new SimpleSpanProcessor(traceExporter));
|
|
27
|
+
|
|
28
|
+
// if (process.env.OASTLM_MODULE_DISABLED !== 'true') {
|
|
29
|
+
// provider.register();
|
|
30
|
+
// registerInstrumentations({
|
|
31
|
+
// instrumentations: [
|
|
32
|
+
// new HttpInstrumentation(),
|
|
33
|
+
// new ExpressInstrumentation(),
|
|
34
|
+
// ],
|
|
35
|
+
// });
|
|
36
|
+
// }
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// WARNING: This file is autogenerated. DO NOT EDIT!
|
|
4
|
-
//This file is autogenerated by dev/ui/exportHtmlToUi.js
|
|
5
|
-
const ui = (baseURL) => {
|
|
6
|
-
if(!baseURL) return htmlMap;
|
|
7
|
-
return Object.keys(htmlMap).reduce((acc, key) => {
|
|
8
|
-
acc[key] = htmlMap[key].replace(/\/telemetry/g, baseURL);
|
|
9
|
-
return acc;
|
|
10
|
-
}, {});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const htmlMap =
|
|
14
|
-
{
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// WARNING: This file is autogenerated. DO NOT EDIT!
|
|
4
|
+
//This file is autogenerated by dev/ui/exportHtmlToUi.js
|
|
5
|
+
const ui = (baseURL) => {
|
|
6
|
+
if(!baseURL) return htmlMap;
|
|
7
|
+
return Object.keys(htmlMap).reduce((acc, key) => {
|
|
8
|
+
acc[key] = htmlMap[key].replace(/\/telemetry/g, baseURL);
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const htmlMap =
|
|
14
|
+
{
|
|
15
15
|
detail: `<!DOCTYPE html>
|
|
16
16
|
<html lang="en">
|
|
17
17
|
|
|
@@ -632,7 +632,7 @@ detail: `<!DOCTYPE html>
|
|
|
632
632
|
|
|
633
633
|
</body>
|
|
634
634
|
|
|
635
|
-
</html>`,
|
|
635
|
+
</html>`,
|
|
636
636
|
login: `<!DOCTYPE html>
|
|
637
637
|
<html lang="en">
|
|
638
638
|
<head>
|
|
@@ -813,7 +813,7 @@ login: `<!DOCTYPE html>
|
|
|
813
813
|
</script>
|
|
814
814
|
</body>
|
|
815
815
|
</html>
|
|
816
|
-
`,
|
|
816
|
+
`,
|
|
817
817
|
main: `<!DOCTYPE html>
|
|
818
818
|
<html lang="en">
|
|
819
819
|
|
|
@@ -1513,8 +1513,8 @@ main: `<!DOCTYPE html>
|
|
|
1513
1513
|
</script>
|
|
1514
1514
|
</body>
|
|
1515
1515
|
|
|
1516
|
-
</html>`,
|
|
1517
|
-
};
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
export default ui
|
|
1516
|
+
</html>`,
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
export default ui
|
package/dist/client.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// client.js
|
|
4
|
-
|
|
5
|
-
function sendRequest(url, options = {}) {
|
|
6
|
-
const apiKey = localStorage.getItem('apiKey');
|
|
7
|
-
if (!options.headers) {
|
|
8
|
-
options.headers = {};
|
|
9
|
-
}
|
|
10
|
-
options.headers['x-api-key'] = apiKey;
|
|
11
|
-
return fetch(url, options);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// ...existing code...
|
package/dist/middleware/auth.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = auth;
|
|
7
|
-
function auth(req, res, next) {
|
|
8
|
-
const apiKey = req.query.apiKey || req.body.apiKey;
|
|
9
|
-
if (apiKey === process.env.APIKEY) {
|
|
10
|
-
next();
|
|
11
|
-
} else {
|
|
12
|
-
res.status(401).send({
|
|
13
|
-
valid: false
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
module.exports = exports.default;
|
package/dist/telemetry.cjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// tracing.js
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.inMemoryExporter = void 0;
|
|
9
|
-
var _sdkNode = require("@opentelemetry/sdk-node");
|
|
10
|
-
var _resources = require("@opentelemetry/resources");
|
|
11
|
-
var _instrumentationHttp = require("@opentelemetry/instrumentation-http");
|
|
12
|
-
var _InMemoryDbExporter = require("./exporters/InMemoryDbExporter.cjs");
|
|
13
|
-
// import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
14
|
-
|
|
15
|
-
// Create an in-memory span exporter
|
|
16
|
-
const inMemoryExporter = exports.inMemoryExporter = new _InMemoryDbExporter.InMemoryExporter();
|
|
17
|
-
const traceExporter = inMemoryExporter;
|
|
18
|
-
const sdk = new _sdkNode.NodeSDK({
|
|
19
|
-
resource: new _resources.Resource(),
|
|
20
|
-
traceExporter,
|
|
21
|
-
instrumentations: [new _instrumentationHttp.HttpInstrumentation()]
|
|
22
|
-
});
|
|
23
|
-
sdk.start();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export class InMemoryExporter {
|
|
2
|
-
static plugins: any[];
|
|
3
|
-
_spans: any;
|
|
4
|
-
_stopped: boolean;
|
|
5
|
-
export(readableSpans: any, resultCallback: any): any;
|
|
6
|
-
start(): void;
|
|
7
|
-
stop(): void;
|
|
8
|
-
shutdown(): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Exports any pending spans in the exporter
|
|
11
|
-
*/
|
|
12
|
-
forceFlush(): Promise<void>;
|
|
13
|
-
reset(): void;
|
|
14
|
-
getFinishedSpans(): any;
|
|
15
|
-
activatePlugin(plugin: any): void;
|
|
16
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function oasTelemetry(tlConfig?: any): import("express-serve-static-core").Router;
|
package/dist/types/ui.d.ts
DELETED