@oas-tools/oas-telemetry 0.7.1 → 0.8.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/.env.example +21 -2
- package/README.md +1 -2
- package/dist/cjs/config/bootConfig.cjs +19 -14
- package/dist/cjs/config/config.cjs +112 -125
- package/dist/cjs/config/config.types.cjs +1 -4
- package/dist/cjs/docs/openapi.yaml +158 -4
- package/dist/cjs/index.cjs +27 -30
- package/dist/cjs/routesManager.cjs +62 -70
- package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbLogExporter.cjs +202 -190
- package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.cjs +204 -99
- package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.cjs +152 -116
- package/dist/cjs/telemetry/custom-implementations/instrumentations/logsInstrumentation.cjs +92 -0
- package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/Chunk.cjs +159 -0
- package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/Series.cjs +168 -0
- package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/SeriesRegistry.cjs +389 -0
- package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/types.cjs +2 -0
- package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/utils.cjs +77 -0
- package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.cjs +65 -63
- package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.cjs +63 -62
- package/dist/cjs/telemetry/custom-implementations/utils/circular.cjs +47 -47
- package/dist/cjs/telemetry/custom-implementations/utils/storagePath.cjs +39 -0
- package/dist/cjs/telemetry/custom-implementations/wrappers.cjs +141 -138
- package/dist/cjs/telemetry/initializeTelemetry.cjs +35 -91
- package/dist/cjs/telemetry/telemetryConfigurator.cjs +70 -72
- package/dist/cjs/telemetry/telemetryRegistry.cjs +45 -31
- package/dist/cjs/tlm-ai/agent.cjs +49 -64
- package/dist/cjs/tlm-ai/aiController.cjs +54 -76
- package/dist/cjs/tlm-ai/aiRoutes.cjs +17 -20
- package/dist/cjs/tlm-ai/aiService.cjs +91 -95
- package/dist/cjs/tlm-ai/tools.cjs +177 -174
- package/dist/cjs/tlm-auth/authController.cjs +80 -123
- package/dist/cjs/tlm-auth/authMiddleware.cjs +25 -30
- package/dist/cjs/tlm-auth/authRoutes.cjs +11 -14
- package/dist/cjs/tlm-log/logController.cjs +171 -116
- package/dist/cjs/tlm-log/logRoutes.cjs +20 -20
- package/dist/cjs/tlm-metric/metricsController.cjs +211 -121
- package/dist/cjs/tlm-metric/metricsRoutes.cjs +23 -20
- package/dist/cjs/tlm-plugin/pluginController.cjs +128 -140
- package/dist/cjs/tlm-plugin/pluginProcess.cjs +89 -94
- package/dist/cjs/tlm-plugin/pluginRoutes.cjs +11 -14
- package/dist/cjs/tlm-plugin/pluginService.cjs +73 -74
- package/dist/cjs/tlm-trace/traceController.cjs +169 -117
- package/dist/cjs/tlm-trace/traceRoutes.cjs +20 -20
- package/dist/cjs/tlm-ui/uiRoutes.cjs +63 -32
- package/dist/cjs/tlm-util/utilController.cjs +68 -70
- package/dist/cjs/tlm-util/utilRoutes.cjs +51 -63
- package/dist/cjs/types/index.cjs +2 -5
- package/dist/cjs/utils/logger.cjs +38 -43
- package/dist/cjs/utils/regexUtils.cjs +22 -22
- package/dist/esm/config/bootConfig.js +6 -0
- package/dist/esm/config/config.js +1 -2
- package/dist/esm/docs/openapi.yaml +158 -4
- package/dist/esm/index.js +9 -8
- package/dist/esm/routesManager.js +6 -10
- package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbLogExporter.js +47 -8
- package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.js +164 -48
- package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.js +69 -29
- package/dist/esm/telemetry/custom-implementations/instrumentations/logsInstrumentation.js +85 -0
- package/dist/esm/telemetry/custom-implementations/metrics/tsdb/Chunk.js +155 -0
- package/dist/esm/telemetry/custom-implementations/metrics/tsdb/Series.js +164 -0
- package/dist/esm/telemetry/custom-implementations/metrics/tsdb/SeriesRegistry.js +382 -0
- package/dist/esm/telemetry/custom-implementations/metrics/tsdb/types.js +1 -0
- package/dist/esm/telemetry/custom-implementations/metrics/tsdb/utils.js +74 -0
- package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.js +2 -1
- package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.js +1 -1
- package/dist/esm/telemetry/custom-implementations/utils/storagePath.js +33 -0
- package/dist/esm/telemetry/custom-implementations/wrappers.js +5 -2
- package/dist/esm/telemetry/initializeTelemetry.js +27 -69
- package/dist/esm/telemetry/telemetryConfigurator.js +42 -40
- package/dist/esm/telemetry/telemetryRegistry.js +12 -1
- package/dist/esm/tlm-ai/agent.js +5 -3
- package/dist/esm/tlm-ai/aiController.js +3 -3
- package/dist/esm/tlm-ai/aiService.js +6 -2
- package/dist/esm/tlm-ai/tools.js +5 -9
- package/dist/esm/tlm-auth/authController.js +3 -2
- package/dist/esm/tlm-log/logController.js +84 -4
- package/dist/esm/tlm-log/logRoutes.js +5 -2
- package/dist/esm/tlm-metric/metricsController.js +172 -49
- package/dist/esm/tlm-metric/metricsRoutes.js +10 -4
- package/dist/esm/tlm-plugin/pluginController.js +6 -11
- package/dist/esm/tlm-plugin/pluginService.js +2 -4
- package/dist/esm/tlm-trace/traceController.js +102 -16
- package/dist/esm/tlm-trace/traceRoutes.js +5 -2
- package/dist/esm/tlm-ui/uiRoutes.js +5 -5
- package/dist/esm/tlm-util/utilController.js +3 -9
- package/dist/esm/tlm-util/utilRoutes.js +2 -2
- package/dist/types/config/bootConfig.d.ts +4 -0
- package/dist/types/config/config.d.ts +36 -7
- package/dist/types/config/config.types.d.ts +6 -0
- package/dist/types/index.d.ts +2 -3
- package/dist/types/telemetry/custom-implementations/exporters/InMemoryDbLogExporter.d.ts +4 -1
- package/dist/types/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.d.ts +60 -15
- package/dist/types/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.d.ts +9 -4
- package/dist/types/telemetry/custom-implementations/instrumentations/logsInstrumentation.d.ts +23 -0
- package/dist/types/telemetry/custom-implementations/metrics/tsdb/Chunk.d.ts +49 -0
- package/dist/types/telemetry/custom-implementations/metrics/tsdb/Series.d.ts +67 -0
- package/dist/types/telemetry/custom-implementations/metrics/tsdb/SeriesRegistry.d.ts +69 -0
- package/dist/types/telemetry/custom-implementations/metrics/tsdb/types.d.ts +68 -0
- package/dist/types/telemetry/custom-implementations/metrics/tsdb/utils.d.ts +21 -0
- package/dist/types/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.d.ts +2 -2
- package/dist/types/telemetry/custom-implementations/utils/storagePath.d.ts +12 -0
- package/dist/types/telemetry/custom-implementations/wrappers.d.ts +1 -1
- package/dist/types/telemetry/telemetryConfigurator.d.ts +1 -1
- package/dist/types/telemetry/telemetryRegistry.d.ts +8 -0
- package/dist/types/tlm-ai/agent.d.ts +1 -1
- package/dist/types/tlm-ai/aiService.d.ts +1 -1
- package/dist/types/tlm-log/logController.d.ts +2 -0
- package/dist/types/tlm-metric/metricsController.d.ts +16 -2
- package/dist/types/tlm-trace/traceController.d.ts +3 -1
- package/dist/types/types/index.d.ts +2 -2
- package/dist/ui/assets/{ApiDocsPage-C_VVPPHa.js → ApiDocsPage-BFUrXE5F.js} +2 -2
- package/dist/ui/assets/CollapsibleCard-STA1GVQO.js +1 -0
- package/dist/ui/assets/DevToolsPage-BRSfZqO_.js +1 -0
- package/dist/ui/assets/LandingPage-DzeDy7q7.js +6 -0
- package/dist/ui/assets/LogsPage-BeiFrV2X.js +1 -0
- package/dist/ui/assets/{NotFoundPage-B3quk3P1.js → NotFoundPage-fRNOatbM.js} +1 -1
- package/dist/ui/assets/PluginCreatePage-Ch_RXsdf.js +50 -0
- package/dist/ui/assets/PluginPage-Cl65ZZ_n.js +27 -0
- package/dist/ui/assets/TraceSpansPage-BoK4M5Hh.js +6 -0
- package/dist/ui/assets/VirtualizedListPanel-zcj0v7DL.js +16 -0
- package/dist/ui/assets/alert-BkNVKxJN.js +1133 -0
- package/dist/ui/assets/badge-CN7FeufU.js +1 -0
- package/dist/ui/assets/{chevron-down-CPsvsmqj.js → chevron-down-CG--ounh.js} +1 -1
- package/dist/ui/assets/{chevron-up-Df9jMo1X.js → chevron-up-B6tzMAOm.js} +1 -1
- package/dist/ui/assets/{circle-alert-DOPQPvU8.js → circle-alert-BDF8Tq9y.js} +1 -1
- package/dist/ui/assets/dialog-BrpWNk36.js +15 -0
- package/dist/ui/assets/index-6xOVKwKn.js +305 -0
- package/dist/ui/assets/index-D6f1KjWV.css +1 -0
- package/dist/ui/assets/index-D96rVSkR.js +1 -0
- package/dist/ui/assets/info-99kuqpbx.js +6 -0
- package/dist/ui/assets/{input-Dzvg_ZEZ.js → input-B-01QDg_.js} +1 -1
- package/dist/ui/assets/label-CQLeZjM1.js +1 -0
- package/dist/ui/assets/{loader-circle-CrvlRy5o.js → loader-circle-BoDGk-BO.js} +1 -1
- package/dist/ui/assets/{loginPage-qa4V-B70.js → loginPage-8F4EEd1B.js} +1 -1
- package/dist/ui/assets/metrics-page-D1GxaB_c.css +1 -0
- package/dist/ui/assets/metrics-page-DPtteXqY.js +31 -0
- package/dist/ui/assets/popover-DS_8DYYt.js +11 -0
- package/dist/ui/assets/select-DYjegiXi.js +6 -0
- package/dist/ui/assets/separator-DGsRxIrl.js +6 -0
- package/dist/ui/assets/severityOptions-DEOvJqC9.js +11 -0
- package/dist/ui/assets/square-pen-DPhgYz6O.js +6 -0
- package/dist/ui/assets/switch-Di9NJH2A.js +1 -0
- package/dist/ui/assets/trace-DJq1miYa.js +1 -0
- package/dist/ui/assets/upload-BiLTpCnX.js +11 -0
- package/dist/ui/assets/{utilService-DNyqzwj0.js → utilService-CNZOmadC.js} +1 -1
- package/dist/ui/assets/wand-sparkles-CPoBNFFg.js +6 -0
- package/dist/ui/index.html +2 -2
- package/package.json +44 -48
- package/dist/ui/assets/CollapsibleCard-B3KR_8mL.js +0 -1
- package/dist/ui/assets/DevToolsPage-OyZcDcmw.js +0 -1
- package/dist/ui/assets/LandingPage-CppFBA6K.js +0 -6
- package/dist/ui/assets/LogsPage-9Fq8GArS.js +0 -26
- package/dist/ui/assets/PluginCreatePage-X_aCH4t4.js +0 -50
- package/dist/ui/assets/PluginPage-DMDSihrZ.js +0 -27
- package/dist/ui/assets/alert-jQ9HCPIf.js +0 -1133
- package/dist/ui/assets/badge-CNq0-mH5.js +0 -1
- package/dist/ui/assets/card-DFAwwhN3.js +0 -1
- package/dist/ui/assets/index-BkD6DijD.js +0 -15
- package/dist/ui/assets/index-CERGVYZK.js +0 -292
- package/dist/ui/assets/index-CSIPf9qw.css +0 -1
- package/dist/ui/assets/label-DuVnkZ4q.js +0 -1
- package/dist/ui/assets/select-DhS8YUtJ.js +0 -1
- package/dist/ui/assets/separator-isK4chBP.js +0 -6
- package/dist/ui/assets/severityOptions-O38dSOfk.js +0 -11
- package/dist/ui/assets/switch-Z3mImG9n.js +0 -1
- package/dist/ui/assets/tabs-_77MUUQe.js +0 -16
- package/dist/ui/assets/upload-C1LT4Gkb.js +0 -16
|
@@ -1,98 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const logger_js_1 = __importDefault(require("../utils/logger.cjs"));
|
|
7
|
+
const bootConfig_js_1 = require("../config/bootConfig.cjs");
|
|
8
|
+
const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
|
|
9
|
+
const telemetryRegistry_js_1 = require("./telemetryRegistry.cjs");
|
|
10
|
+
const logsInstrumentation_js_1 = require("./custom-implementations/instrumentations/logsInstrumentation.cjs");
|
|
11
|
+
const instrumentation_runtime_node_1 = require("@opentelemetry/instrumentation-runtime-node");
|
|
13
12
|
// THIS INSTRUMENTATIONS NEED TO BE LOADED BEFORE ANYTHING ELSE
|
|
14
13
|
// They use monkey-patching to instrument the HTTP server and client.
|
|
15
14
|
// THIS FILE MUST BE CALLED BEFORE ANYTHING ELSE
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
} else {
|
|
19
|
-
_logger.default.info('🚀 Initializing Open Telemetry');
|
|
20
|
-
initializeTraces();
|
|
21
|
-
initializeMetrics();
|
|
22
|
-
initializeLogs();
|
|
23
|
-
(0, _instrumentation.registerInstrumentations)({
|
|
24
|
-
instrumentations: [new _instrumentationHttp.HttpInstrumentation()
|
|
25
|
-
// new ExpressInstrumentation(),
|
|
26
|
-
]
|
|
27
|
-
});
|
|
15
|
+
if (bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_MODULE_DISABLED) {
|
|
16
|
+
logger_js_1.default.info('🚫 OASTLM module is disabled, Auto Instrumentations not initialized.');
|
|
28
17
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Object.keys(_telemetryRegistry.originalConsoleMethods).forEach(method => {
|
|
47
|
-
// @ts-expect-error yes
|
|
48
|
-
console[method] = (...args) => {
|
|
49
|
-
const severity = getSeverityForMethod(method);
|
|
50
|
-
loggerInstance.emit({
|
|
51
|
-
severityNumber: severity.number,
|
|
52
|
-
severityText: severity.text,
|
|
53
|
-
body: _util.default.format(...args),
|
|
54
|
-
attributes: {
|
|
55
|
-
'source': `console.${method}`,
|
|
56
|
-
"library": "oas-telemetry"
|
|
18
|
+
else {
|
|
19
|
+
if (!(0, telemetryRegistry_js_1.isBootInitialized)()) {
|
|
20
|
+
// Only HTTP instrumentation por ahora
|
|
21
|
+
const httpInstrumentation = new instrumentation_http_1.HttpInstrumentation({
|
|
22
|
+
// Ignore internal telemetry routes
|
|
23
|
+
ignoreIncomingRequestHook: (req) => {
|
|
24
|
+
const url = req.url || '';
|
|
25
|
+
const path = url.split('?')[0]; // Remove query params
|
|
26
|
+
// Ignore all baseUrl routes except those with 'generate'
|
|
27
|
+
if (path.includes(bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_BASE_URL)) {
|
|
28
|
+
return !path.includes('generate');
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (!bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_AUTOINSTRUMENTATIONS_NODE_DISABLED) {
|
|
34
|
+
telemetryRegistry_js_1.instrumentations.push(httpInstrumentation, new instrumentation_runtime_node_1.RuntimeNodeInstrumentation());
|
|
57
35
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
function initializeMetrics() {
|
|
65
|
-
_logger.default.info('📈 Initializing MeterProvider');
|
|
66
|
-
// WARN: Default PeriodicExportingMetricReader is added post initialization (see telemetryConfigurator.ts)
|
|
67
|
-
// The in memory exporter is added by default to that reader. More readers are allowed to be added dynamically
|
|
36
|
+
if (!bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_AUTOINSTRUMENTATIONS_LOGS_DISABLED) {
|
|
37
|
+
telemetryRegistry_js_1.instrumentations.push(new logsInstrumentation_js_1.LogsInstrumentation());
|
|
38
|
+
}
|
|
39
|
+
(0, telemetryRegistry_js_1.setBootInitialized)(true);
|
|
40
|
+
logger_js_1.default.info('✅ Auto Instrumentations created successfully');
|
|
41
|
+
}
|
|
68
42
|
}
|
|
69
|
-
function getSeverityForMethod(method) {
|
|
70
|
-
switch (method) {
|
|
71
|
-
case "log":
|
|
72
|
-
case "info":
|
|
73
|
-
return {
|
|
74
|
-
number: _apiLogs.SeverityNumber.INFO,
|
|
75
|
-
text: "INFO"
|
|
76
|
-
};
|
|
77
|
-
case "debug":
|
|
78
|
-
return {
|
|
79
|
-
number: _apiLogs.SeverityNumber.DEBUG,
|
|
80
|
-
text: "DEBUG"
|
|
81
|
-
};
|
|
82
|
-
case "warn":
|
|
83
|
-
return {
|
|
84
|
-
number: _apiLogs.SeverityNumber.WARN,
|
|
85
|
-
text: "WARN"
|
|
86
|
-
};
|
|
87
|
-
case "error":
|
|
88
|
-
return {
|
|
89
|
-
number: _apiLogs.SeverityNumber.ERROR,
|
|
90
|
-
text: "ERROR"
|
|
91
|
-
};
|
|
92
|
-
default:
|
|
93
|
-
return {
|
|
94
|
-
number: _apiLogs.SeverityNumber.INFO,
|
|
95
|
-
text: "INFO"
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,81 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.configureTelemetry = void 0;
|
|
7
|
-
var _sdkTraceNode = require("@opentelemetry/sdk-trace-node");
|
|
8
|
-
var _telemetryRegistry = require("./telemetryRegistry.cjs");
|
|
9
|
-
var _logger = _interopRequireDefault(require("../utils/logger.cjs"));
|
|
10
|
-
var _sdkLogs = require("@opentelemetry/sdk-logs");
|
|
11
|
-
var _sdkMetrics = require("@opentelemetry/sdk-metrics");
|
|
12
|
-
var _hostMetrics = require("@opentelemetry/host-metrics");
|
|
13
|
-
var _bootConfig = require("../config/bootConfig.cjs");
|
|
14
|
-
var _pluginService = require("../tlm-plugin/pluginService.cjs");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
const configureTelemetry = oasTlmConfig => {
|
|
17
|
-
configurePlugins(oasTlmConfig);
|
|
18
|
-
configureTraces(oasTlmConfig);
|
|
19
|
-
configureMetrics(oasTlmConfig);
|
|
20
|
-
configureLogs(oasTlmConfig);
|
|
21
|
-
_logger.default.info("✅ Telemetry configured successfully. All exporters are ready");
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
6
|
exports.configureTelemetry = configureTelemetry;
|
|
7
|
+
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
8
|
+
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
9
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
10
|
+
const logger_js_1 = __importDefault(require("../utils/logger.cjs"));
|
|
11
|
+
const telemetryRegistry_js_1 = require("./telemetryRegistry.cjs");
|
|
12
|
+
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
13
|
+
const bootConfig_js_1 = require("../config/bootConfig.cjs");
|
|
14
|
+
const pluginService_js_1 = require("../tlm-plugin/pluginService.cjs");
|
|
15
|
+
function configureTelemetry(oasTlmConfig) {
|
|
16
|
+
logger_js_1.default.info("🚀 Configuring Telemetry...");
|
|
17
|
+
if (oasTlmConfig.instrumentations) {
|
|
18
|
+
telemetryRegistry_js_1.instrumentations.push(...oasTlmConfig.instrumentations);
|
|
19
|
+
}
|
|
20
|
+
configurePlugins(oasTlmConfig);
|
|
21
|
+
const mainTraceProcessor = configureTraces(oasTlmConfig);
|
|
22
|
+
const mainMetricReader = configureMetrics(oasTlmConfig);
|
|
23
|
+
const mainLogProcessor = configureLogs(oasTlmConfig);
|
|
24
|
+
const sdk = new sdk_node_1.NodeSDK({
|
|
25
|
+
instrumentations: telemetryRegistry_js_1.instrumentations,
|
|
26
|
+
resource: telemetryRegistry_js_1.oasTelemetryResource,
|
|
27
|
+
traceExporter: telemetryRegistry_js_1.inMemoryDbSpanExporter,
|
|
28
|
+
spanProcessors: [mainTraceProcessor, ...oasTlmConfig.traces.extraProcessors || []],
|
|
29
|
+
metricReaders: [mainMetricReader, ...(oasTlmConfig.metrics.extraReaders || [])],
|
|
30
|
+
logRecordProcessors: [mainLogProcessor, ...oasTlmConfig.logs.extraProcessors || []],
|
|
31
|
+
});
|
|
32
|
+
sdk.start();
|
|
33
|
+
logger_js_1.default.info("✅ Node SDK started with telemetry configuration");
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
24
36
|
function configurePlugins(oasTlmConfig) {
|
|
25
|
-
|
|
37
|
+
pluginService_js_1.pluginService.enabled = oasTlmConfig.plugins.enabled;
|
|
26
38
|
}
|
|
27
39
|
function configureTraces(oasTlmConfig) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// TRACES CONFIGURATION
|
|
41
|
+
// [OT]Provider -> [OT]SpanProcessor(multiSpan) -> n Processors(eg mainProcessor, extra) -> 1 SpanExporter
|
|
42
|
+
telemetryRegistry_js_1.inMemoryDbSpanExporter.retentionTimeInSeconds = oasTlmConfig.traces.memoryExporter.retentionTimeSeconds;
|
|
43
|
+
telemetryRegistry_js_1.inMemoryDbSpanExporter.setEnabledValue(oasTlmConfig.traces.memoryExporter.enabled);
|
|
44
|
+
const mainExporter = telemetryRegistry_js_1.multiSpanExporter;
|
|
45
|
+
let mainProcessor = new sdk_trace_node_1.BatchSpanProcessor(mainExporter);
|
|
46
|
+
if (bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_ENV !== 'production') {
|
|
47
|
+
logger_js_1.default.info('Not in production, using SimpleSpanProcessor for traces');
|
|
48
|
+
mainProcessor = new sdk_trace_node_1.SimpleSpanProcessor(mainExporter);
|
|
49
|
+
}
|
|
50
|
+
mainExporter.addExporters(telemetryRegistry_js_1.inMemoryDbSpanExporter); // Main exporter have at least the in-memory exporter used by the traces controller
|
|
51
|
+
mainExporter.addExporters(oasTlmConfig.traces.extraExporters);
|
|
52
|
+
return mainProcessor;
|
|
53
|
+
}
|
|
54
|
+
function configureMetrics(oasTlmConfig) {
|
|
55
|
+
// METRICS CONFIGURATION
|
|
56
|
+
telemetryRegistry_js_1.inMemoryDbMetricExporter.setEnabledValue(oasTlmConfig.metrics.memoryExporter.enabled);
|
|
57
|
+
telemetryRegistry_js_1.inMemoryDbMetricExporter.retentionTimeInSeconds = oasTlmConfig.metrics.memoryExporter.retentionTimeSeconds;
|
|
58
|
+
const mainReader = new sdk_metrics_1.PeriodicExportingMetricReader({
|
|
59
|
+
exporter: telemetryRegistry_js_1.inMemoryDbMetricExporter,
|
|
60
|
+
exportIntervalMillis: oasTlmConfig.metrics.mainMetricReaderOptions.exportIntervalMillis,
|
|
61
|
+
metricProducers: oasTlmConfig.metrics.mainMetricReaderOptions.metricProducers
|
|
62
|
+
});
|
|
63
|
+
return mainReader;
|
|
43
64
|
}
|
|
44
65
|
function configureLogs(oasTlmConfig) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
_telemetryRegistry.dynamicMultiLogProcessor.addProcessors(oasTlmConfig.logs.extraProcessors);
|
|
66
|
+
// LOGS CONFIGURATION
|
|
67
|
+
// [OT]LoggerProvider -> [OT]LogRecordProcessor(multiLogProcessor) -> n Processors(eg mainProcessor, extra) -> 1 LogExporter
|
|
68
|
+
telemetryRegistry_js_1.inMemoryDbLogExporter.setEnabledValue(oasTlmConfig.logs.memoryExporter.enabled);
|
|
69
|
+
telemetryRegistry_js_1.inMemoryDbLogExporter.retentionTimeInSeconds = oasTlmConfig.logs.memoryExporter.retentionTimeSeconds;
|
|
70
|
+
const mainExporter = telemetryRegistry_js_1.multiLogExporter;
|
|
71
|
+
let mainProcessor = new sdk_logs_1.BatchLogRecordProcessor(mainExporter);
|
|
72
|
+
if (bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_ENV !== 'production') {
|
|
73
|
+
logger_js_1.default.info('Not in production, using SimpleLogRecordProcessor for logs');
|
|
74
|
+
mainProcessor = new sdk_logs_1.SimpleLogRecordProcessor(mainExporter);
|
|
75
|
+
}
|
|
76
|
+
mainExporter.addExporters(telemetryRegistry_js_1.inMemoryDbLogExporter); // Main exporter have at least the in-memory exporter used by the logs controller
|
|
77
|
+
mainExporter.addExporters(oasTlmConfig.logs.extraExporters);
|
|
78
|
+
return mainProcessor;
|
|
59
79
|
}
|
|
60
|
-
function configureMetrics(oasTlmConfig) {
|
|
61
|
-
// METRICS CONFIGURATION
|
|
62
|
-
// [CUSTOM]MeterProvider -> n [OTel]MetricReader -> (0-1) MetricExporter (only if push-based reader)
|
|
63
|
-
_telemetryRegistry.inMemoryDbMetricExporter.setEnabledValue(oasTlmConfig.metrics.memoryExporter.enabled);
|
|
64
|
-
_telemetryRegistry.inMemoryDbMetricExporter.retentionTimeInSeconds = oasTlmConfig.metrics.memoryExporter.retentionTimeSeconds;
|
|
65
|
-
const mainReader = new _sdkMetrics.PeriodicExportingMetricReader({
|
|
66
|
-
exporter: _telemetryRegistry.inMemoryDbMetricExporter,
|
|
67
|
-
exportIntervalMillis: oasTlmConfig.metrics.mainMetricReaderOptions.exportIntervalMillis,
|
|
68
|
-
metricProducers: oasTlmConfig.metrics.mainMetricReaderOptions.metricProducers
|
|
69
|
-
});
|
|
70
|
-
const meterProvider = new _sdkMetrics.MeterProvider({
|
|
71
|
-
resource: _telemetryRegistry.oasTelemetryResource,
|
|
72
|
-
readers: [mainReader, ...oasTlmConfig.metrics.extraReaders],
|
|
73
|
-
views: oasTlmConfig.metrics.extraViews || []
|
|
74
|
-
});
|
|
75
|
-
// TODO maybe hostMetrics are too much, consider using only a subset of them.
|
|
76
|
-
const hostMetrics = new _hostMetrics.HostMetrics({
|
|
77
|
-
meterProvider: meterProvider
|
|
78
|
-
});
|
|
79
|
-
// AFTER adding all readers, start the instrumentations
|
|
80
|
-
hostMetrics.start();
|
|
81
|
-
}
|
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instrumentations = exports.inMemoryDbMetricExporter = exports.originalConsoleMethods = exports.dynamicMultiLogProcessor = exports.multiLogExporter = exports.inMemoryDbLogExporter = exports.dynamicMultiSpanProcessor = exports.multiSpanExporter = exports.inMemoryDbSpanExporter = exports.oasTelemetryResource = void 0;
|
|
4
|
+
exports.isBootInitialized = isBootInitialized;
|
|
5
|
+
exports.setBootInitialized = setBootInitialized;
|
|
6
|
+
exports.isTelemetryConfigured = isTelemetryConfigured;
|
|
7
|
+
exports.setTelemetryConfigured = setTelemetryConfigured;
|
|
8
|
+
exports.setTelemetryRouter = setTelemetryRouter;
|
|
9
|
+
exports.getTelemetryRouter = getTelemetryRouter;
|
|
10
|
+
const InMemoryDbSpanExporter_js_1 = require("./custom-implementations/exporters/InMemoryDbSpanExporter.cjs");
|
|
11
|
+
const wrappers_js_1 = require("./custom-implementations/wrappers.cjs");
|
|
12
|
+
const InMemoryDbLogExporter_js_1 = require("./custom-implementations/exporters/InMemoryDbLogExporter.cjs");
|
|
13
|
+
const InMemoryDbMetricExporter_js_1 = require("./custom-implementations/exporters/InMemoryDbMetricExporter.cjs");
|
|
14
|
+
const dynamicMultiSpanProcessor_js_1 = require("./custom-implementations/processors/dynamicMultiSpanProcessor.cjs");
|
|
15
|
+
const dynamicMultiLogProcessor_js_1 = require("./custom-implementations/processors/dynamicMultiLogProcessor.cjs");
|
|
16
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
17
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
18
|
+
const bootConfig_js_1 = require("../config/bootConfig.cjs");
|
|
16
19
|
// GLOBAL REGISTRY of telemetry components, used by SDKs and controllers.
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
let _bootInitialized = false;
|
|
21
|
+
let _telemetryConfigured = false;
|
|
22
|
+
let _router = undefined;
|
|
23
|
+
function isBootInitialized() { return _bootInitialized; }
|
|
24
|
+
function setBootInitialized(v) { _bootInitialized = v; }
|
|
25
|
+
function isTelemetryConfigured() { return _telemetryConfigured; }
|
|
26
|
+
function setTelemetryConfigured(v) { _telemetryConfigured = v; }
|
|
27
|
+
function setTelemetryRouter(router) { _router = router; }
|
|
28
|
+
function getTelemetryRouter() { return _router; }
|
|
29
|
+
exports.oasTelemetryResource = (0, resources_1.resourceFromAttributes)({
|
|
30
|
+
[semantic_conventions_1.ATTR_SERVICE_NAME]: bootConfig_js_1.bootEnvVariables.OASTLM_BOOT_SERVICE_NAME
|
|
19
31
|
});
|
|
20
32
|
// TRACES -------------------------------------------------------------------------------------
|
|
21
33
|
// This is the main exporter for oas-telemetry spans. (Used by the traces controller)
|
|
22
|
-
|
|
34
|
+
exports.inMemoryDbSpanExporter = new InMemoryDbSpanExporter_js_1.InMemoryDbSpanExporter();
|
|
23
35
|
// This allows to add more exporter in the future without changing the code
|
|
24
|
-
|
|
36
|
+
exports.multiSpanExporter = new wrappers_js_1.EnablerMultiSpanExporter();
|
|
25
37
|
// This allows the addition of more processors at runtime
|
|
26
|
-
|
|
38
|
+
exports.dynamicMultiSpanProcessor = new dynamicMultiSpanProcessor_js_1.DynamicMultiSpanProcessor();
|
|
27
39
|
// LOGS ----------------------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
exports.inMemoryDbLogExporter = new InMemoryDbLogExporter_js_1.InMemoryDbLogExporter();
|
|
41
|
+
exports.multiLogExporter = new wrappers_js_1.EnablerMultiLogExporter();
|
|
42
|
+
exports.dynamicMultiLogProcessor = new dynamicMultiLogProcessor_js_1.DynamicMultiLogRecordProcessor();
|
|
43
|
+
// For custom log instrumentation, and lib logging
|
|
44
|
+
exports.originalConsoleMethods = {
|
|
45
|
+
log: console.log,
|
|
46
|
+
warn: console.warn,
|
|
47
|
+
error: console.error,
|
|
48
|
+
info: console.info,
|
|
49
|
+
debug: console.debug,
|
|
38
50
|
};
|
|
39
51
|
// METRICS -------------------------------------------------------------------------------------
|
|
40
52
|
// Metrics follow a different pattern in OpenTelemetry
|
|
41
|
-
|
|
53
|
+
exports.inMemoryDbMetricExporter = new InMemoryDbMetricExporter_js_1.InMemoryDbMetricExporter();
|
|
42
54
|
// Readers and their exporters cannot be grouped together in a MultiReader or similar construct
|
|
43
|
-
// due to differences in aggregation temporality and aggregation selection.
|
|
55
|
+
// due to differences in aggregation temporality and aggregation selection.
|
|
56
|
+
// INSTRUMENTATIONS -----------------------------------------------------------------------
|
|
57
|
+
exports.instrumentations = [];
|
|
@@ -1,68 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.agent = agent;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async function agent(openai, messages, model = "gpt-3.5-turbo", extraPrompts = []) {
|
|
16
|
-
for (let i = 0; i < 5; i++) {
|
|
17
|
-
const modelResponse = await openai.chat.completions.create({
|
|
18
|
-
model,
|
|
19
|
-
messages,
|
|
20
|
-
tools: _tools.tools
|
|
21
|
-
});
|
|
22
|
-
const {
|
|
23
|
-
finish_reason,
|
|
24
|
-
message
|
|
25
|
-
} = modelResponse.choices[0];
|
|
26
|
-
if (finish_reason === "tool_calls" && message.tool_calls) {
|
|
27
|
-
_logger.default.debug("Tool calls detected:", message.tool_calls);
|
|
28
|
-
const results = [];
|
|
29
|
-
for (const toolCall of message.tool_calls) {
|
|
30
|
-
const functionName = toolCall.function.name;
|
|
31
|
-
const functionToCall = _tools.availableTools[functionName];
|
|
32
|
-
const functionArgs = JSON.parse(toolCall.function.arguments);
|
|
33
|
-
const functionArgsArr = Object.values(functionArgs);
|
|
34
|
-
// @ts-expect-error yes
|
|
35
|
-
// eslint-disable-next-line prefer-spread
|
|
36
|
-
const functionResponse = await functionToCall.apply(null, functionArgsArr);
|
|
37
|
-
results.push({
|
|
38
|
-
name: functionName,
|
|
39
|
-
response: functionResponse
|
|
7
|
+
const tools_js_1 = require("./tools.cjs");
|
|
8
|
+
const logger_js_1 = __importDefault(require("../utils/logger.cjs"));
|
|
9
|
+
async function agent(openai, messages, model = "gpt-3.5-turbo") {
|
|
10
|
+
for (let i = 0; i < 5; i++) {
|
|
11
|
+
const modelResponse = await openai.chat.completions.create({
|
|
12
|
+
model,
|
|
13
|
+
messages,
|
|
14
|
+
tools: tools_js_1.tools,
|
|
40
15
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
16
|
+
const { finish_reason, message } = modelResponse.choices[0];
|
|
17
|
+
if (finish_reason === "tool_calls" && message.tool_calls) {
|
|
18
|
+
logger_js_1.default.debug("Tool calls detected:", message.tool_calls);
|
|
19
|
+
const results = [];
|
|
20
|
+
for (const toolCall of message.tool_calls) {
|
|
21
|
+
// Type guard for tool_calls
|
|
22
|
+
if (toolCall.type !== 'function' || !toolCall.function)
|
|
23
|
+
continue;
|
|
24
|
+
const functionName = toolCall.function.name;
|
|
25
|
+
const functionToCall = tools_js_1.availableTools[functionName];
|
|
26
|
+
const functionArgs = JSON.parse(toolCall.function.arguments);
|
|
27
|
+
const functionArgsArr = Object.values(functionArgs);
|
|
28
|
+
// eslint-disable-next-line prefer-spread
|
|
29
|
+
const functionResponse = await functionToCall.apply(null, functionArgsArr);
|
|
30
|
+
results.push({
|
|
31
|
+
name: functionName,
|
|
32
|
+
response: functionResponse,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const resultMessage = results.map(({ name, response }, idx) => {
|
|
36
|
+
const toolCall = message.tool_calls?.[idx];
|
|
37
|
+
const params = toolCall && toolCall.type === 'function' && toolCall.function ? JSON.parse(toolCall.function.arguments) : {};
|
|
38
|
+
return `Tool "${name}" called with parameters:\n${JSON.stringify(params, null, 2)}\nResult:\n${JSON.stringify(response, null, 2)}`;
|
|
39
|
+
}).join("\n\n");
|
|
40
|
+
messages.push({
|
|
41
|
+
role: "function",
|
|
42
|
+
name: "multiple_tool_calls",
|
|
43
|
+
content: resultMessage,
|
|
44
|
+
timestamp: new Date().toISOString()
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (finish_reason === "stop") {
|
|
48
|
+
messages.push({ ...message, timestamp: new Date().toISOString() });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
61
51
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
role: "assistant",
|
|
65
|
-
content: "Maximum iterations reached without a suitable response. Try a more specific query.",
|
|
66
|
-
timestamp: new Date().toISOString()
|
|
67
|
-
});
|
|
68
|
-
}
|
|
52
|
+
messages.push({ role: "assistant", content: "Maximum iterations reached without a suitable response. Try a more specific query.", timestamp: new Date().toISOString() });
|
|
53
|
+
}
|