@oas-tools/oas-telemetry 0.7.0-alpha.2 → 0.7.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/.env.example +50 -17
  2. package/README.md +244 -239
  3. package/dist/cjs/config/bootConfig.cjs +18 -0
  4. package/dist/cjs/config/config.cjs +145 -0
  5. package/dist/cjs/config/config.types.cjs +5 -0
  6. package/dist/cjs/index.cjs +19 -25
  7. package/dist/cjs/{tlmRoutes.cjs → routesManager.cjs} +28 -21
  8. package/dist/cjs/{exporters/InMemoryLogRecordExporter.cjs → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.cjs} +42 -19
  9. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.cjs +97 -0
  10. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.cjs +118 -0
  11. package/dist/cjs/telemetry/custom-implementations/exporters/PluginLogExporter.cjs +45 -0
  12. package/dist/cjs/telemetry/custom-implementations/exporters/PluginMetricExporter.cjs +46 -0
  13. package/dist/cjs/telemetry/custom-implementations/exporters/PluginSpanExporter.cjs +61 -0
  14. package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.cjs +70 -0
  15. package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.cjs +70 -0
  16. package/dist/cjs/{utils → telemetry/custom-implementations/utils}/circular.cjs +39 -49
  17. package/dist/cjs/telemetry/custom-implementations/wrappers.cjs +175 -0
  18. package/dist/cjs/telemetry/initializeTelemetry.cjs +74 -0
  19. package/dist/cjs/telemetry/telemetryConfigurator.cjs +84 -0
  20. package/dist/cjs/telemetry/telemetryRegistry.cjs +40 -0
  21. package/dist/cjs/tlm-ai/agent.cjs +82 -63
  22. package/dist/cjs/tlm-ai/aiController.cjs +5 -4
  23. package/dist/cjs/tlm-ai/aiRoutes.cjs +9 -6
  24. package/dist/cjs/tlm-ai/tools.cjs +16 -9
  25. package/dist/cjs/tlm-auth/authController.cjs +14 -15
  26. package/dist/cjs/tlm-auth/authMiddleware.cjs +11 -10
  27. package/dist/cjs/tlm-auth/authRoutes.cjs +9 -7
  28. package/dist/cjs/tlm-log/logController.cjs +45 -18
  29. package/dist/cjs/tlm-log/logRoutes.cjs +16 -11
  30. package/dist/cjs/tlm-metric/metricsController.cjs +37 -12
  31. package/dist/cjs/tlm-metric/metricsRoutes.cjs +16 -11
  32. package/dist/cjs/tlm-plugin/pluginController.cjs +114 -75
  33. package/dist/cjs/tlm-plugin/pluginProcess.cjs +108 -0
  34. package/dist/cjs/tlm-plugin/pluginRoutes.cjs +11 -6
  35. package/dist/cjs/tlm-plugin/pluginService.cjs +79 -0
  36. package/dist/cjs/tlm-trace/traceController.cjs +54 -45
  37. package/dist/cjs/tlm-trace/traceRoutes.cjs +16 -11
  38. package/dist/cjs/tlm-ui/uiRoutes.cjs +26 -20
  39. package/dist/cjs/tlm-util/utilController.cjs +8 -9
  40. package/dist/cjs/tlm-util/utilRoutes.cjs +22 -19
  41. package/dist/cjs/types/index.cjs +0 -1
  42. package/dist/cjs/utils/logger.cjs +3 -5
  43. package/dist/cjs/utils/regexUtils.cjs +27 -0
  44. package/dist/esm/config/bootConfig.js +11 -0
  45. package/dist/esm/config/config.js +126 -0
  46. package/dist/esm/index.js +18 -29
  47. package/dist/esm/{tlmRoutes.js → routesManager.js} +27 -22
  48. package/dist/esm/{exporters/InMemoryLogRecordExporter.js → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.js} +31 -17
  49. package/dist/esm/{exporters/InMemoryDBMetricsExporter.js → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.js} +31 -17
  50. package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.js +105 -0
  51. package/dist/esm/telemetry/custom-implementations/exporters/PluginLogExporter.js +36 -0
  52. package/dist/esm/telemetry/custom-implementations/exporters/PluginMetricExporter.js +35 -0
  53. package/dist/esm/telemetry/custom-implementations/exporters/PluginSpanExporter.js +52 -0
  54. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.js +64 -0
  55. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.js +64 -0
  56. package/dist/esm/telemetry/custom-implementations/utils/circular.js +76 -0
  57. package/dist/esm/telemetry/custom-implementations/wrappers.js +163 -0
  58. package/dist/esm/telemetry/initializeTelemetry.js +71 -0
  59. package/dist/esm/telemetry/telemetryConfigurator.js +74 -0
  60. package/dist/esm/telemetry/telemetryRegistry.js +34 -0
  61. package/dist/esm/tlm-ai/agent.js +77 -59
  62. package/dist/esm/tlm-ai/aiController.js +5 -4
  63. package/dist/esm/tlm-ai/aiRoutes.js +7 -5
  64. package/dist/esm/tlm-ai/tools.js +18 -9
  65. package/dist/esm/tlm-auth/authController.js +9 -10
  66. package/dist/esm/tlm-auth/authMiddleware.js +10 -9
  67. package/dist/esm/tlm-auth/authRoutes.js +8 -6
  68. package/dist/esm/tlm-log/logController.js +36 -16
  69. package/dist/esm/tlm-log/logRoutes.js +15 -11
  70. package/dist/esm/tlm-metric/metricsController.js +29 -10
  71. package/dist/esm/tlm-metric/metricsRoutes.js +15 -11
  72. package/dist/esm/tlm-plugin/pluginController.js +112 -77
  73. package/dist/esm/tlm-plugin/pluginProcess.js +101 -0
  74. package/dist/esm/tlm-plugin/pluginRoutes.js +10 -6
  75. package/dist/esm/tlm-plugin/pluginService.js +73 -0
  76. package/dist/esm/tlm-trace/traceController.js +40 -35
  77. package/dist/esm/tlm-trace/traceRoutes.js +15 -11
  78. package/dist/esm/tlm-ui/uiRoutes.js +24 -19
  79. package/dist/esm/tlm-util/utilController.js +8 -9
  80. package/dist/esm/tlm-util/utilRoutes.js +17 -15
  81. package/dist/esm/types/index.js +0 -1
  82. package/dist/esm/utils/logger.js +3 -4
  83. package/dist/esm/utils/regexUtils.js +23 -0
  84. package/dist/types/config/bootConfig.d.ts +5 -0
  85. package/dist/types/config/config.d.ts +858 -0
  86. package/dist/types/config/config.types.d.ts +34 -0
  87. package/dist/types/index.d.ts +5 -4
  88. package/dist/types/routesManager.d.ts +3 -0
  89. package/dist/types/{exporters/InMemoryLogRecordExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbLogExporter.d.ts} +6 -6
  90. package/dist/types/{exporters/InMemoryDBMetricsExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.d.ts} +7 -7
  91. package/dist/types/{exporters/InMemoryDbExporter.d.ts → telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.d.ts} +9 -9
  92. package/dist/types/telemetry/custom-implementations/exporters/PluginLogExporter.d.ts +8 -0
  93. package/dist/types/telemetry/custom-implementations/exporters/PluginMetricExporter.d.ts +12 -0
  94. package/dist/types/telemetry/custom-implementations/exporters/PluginSpanExporter.d.ts +14 -0
  95. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.d.ts +32 -0
  96. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.d.ts +34 -0
  97. package/dist/types/telemetry/custom-implementations/utils/circular.d.ts +27 -0
  98. package/dist/types/telemetry/custom-implementations/wrappers.d.ts +52 -0
  99. package/dist/types/telemetry/initializeTelemetry.d.ts +1 -0
  100. package/dist/types/telemetry/telemetryConfigurator.d.ts +2 -0
  101. package/dist/types/telemetry/telemetryRegistry.d.ts +20 -0
  102. package/dist/types/tlm-ai/agent.d.ts +2 -1
  103. package/dist/types/tlm-ai/aiController.d.ts +4 -3
  104. package/dist/types/tlm-ai/aiRoutes.d.ts +2 -2
  105. package/dist/types/tlm-ai/tools.d.ts +3 -1
  106. package/dist/types/tlm-auth/authController.d.ts +4 -3
  107. package/dist/types/tlm-auth/authMiddleware.d.ts +2 -1
  108. package/dist/types/tlm-auth/authRoutes.d.ts +2 -2
  109. package/dist/types/tlm-log/logController.d.ts +1 -0
  110. package/dist/types/tlm-log/logRoutes.d.ts +2 -2
  111. package/dist/types/tlm-metric/metricsController.d.ts +1 -0
  112. package/dist/types/tlm-metric/metricsRoutes.d.ts +2 -2
  113. package/dist/types/tlm-plugin/pluginController.d.ts +4 -1
  114. package/dist/types/tlm-plugin/pluginProcess.d.ts +1 -0
  115. package/dist/types/tlm-plugin/pluginRoutes.d.ts +1 -2
  116. package/dist/types/tlm-plugin/pluginService.d.ts +24 -0
  117. package/dist/types/tlm-trace/traceController.d.ts +7 -6
  118. package/dist/types/tlm-trace/traceRoutes.d.ts +2 -2
  119. package/dist/types/tlm-ui/uiRoutes.d.ts +1 -2
  120. package/dist/types/tlm-util/utilController.d.ts +2 -1
  121. package/dist/types/tlm-util/utilRoutes.d.ts +2 -2
  122. package/dist/types/types/index.d.ts +17 -47
  123. package/dist/types/utils/regexUtils.d.ts +1 -0
  124. package/dist/ui/assets/index-BzIdRox6.js +1733 -0
  125. package/dist/ui/assets/index-CkoHzrrt.css +1 -0
  126. package/dist/ui/index.html +3 -3
  127. package/dist/ui/oas-tlm.svg +185 -0
  128. package/package.json +12 -7
  129. package/dist/cjs/config.cjs +0 -31
  130. package/dist/cjs/exporters/InMemoryDBMetricsExporter.cjs +0 -74
  131. package/dist/cjs/exporters/InMemoryDbExporter.cjs +0 -102
  132. package/dist/cjs/exporters/consoleExporter.cjs +0 -47
  133. package/dist/cjs/exporters/dynamicExporter.cjs +0 -57
  134. package/dist/cjs/instrumentation/index.cjs +0 -28
  135. package/dist/cjs/instrumentation/logs.cjs +0 -46
  136. package/dist/cjs/instrumentation/metrics.cjs +0 -27
  137. package/dist/cjs/instrumentation/traces.cjs +0 -19
  138. package/dist/esm/config.js +0 -20
  139. package/dist/esm/exporters/InMemoryDbExporter.js +0 -102
  140. package/dist/esm/exporters/consoleExporter.js +0 -38
  141. package/dist/esm/exporters/dynamicExporter.js +0 -50
  142. package/dist/esm/instrumentation/index.js +0 -26
  143. package/dist/esm/instrumentation/logs.js +0 -34
  144. package/dist/esm/instrumentation/metrics.js +0 -18
  145. package/dist/esm/instrumentation/traces.js +0 -12
  146. package/dist/esm/utils/circular.js +0 -84
  147. package/dist/types/config.d.ts +0 -6
  148. package/dist/types/exporters/consoleExporter.d.ts +0 -13
  149. package/dist/types/exporters/dynamicExporter.d.ts +0 -25
  150. package/dist/types/instrumentation/logs.d.ts +0 -1
  151. package/dist/types/instrumentation/metrics.d.ts +0 -1
  152. package/dist/types/instrumentation/traces.d.ts +0 -1
  153. package/dist/types/tlmRoutes.d.ts +0 -2
  154. package/dist/types/utils/circular.d.ts +0 -31
  155. package/dist/ui/assets/index-BNhZBPi2.css +0 -1
  156. package/dist/ui/assets/index-DxGAMrAl.js +0 -401
  157. package/dist/ui/vite.svg +0 -1
  158. /package/dist/{types/instrumentation/index.d.ts → esm/config/config.types.js} +0 -0
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ConsoleExporter = void 0;
7
- class ConsoleExporter {
8
- constructor() {
9
- // PLUGIN SYSTEM -----------------------------------------------------------
10
- this.plugins = [];
11
- }
12
- // OPEN TELEMETRY EXPORTER INTERFACE ---------------------------------------
13
- export(readableSpans, resultCallback) {
14
- console.log('ConsoleExporter | Received spans: ', readableSpans.length);
15
- setTimeout(() => resultCallback({
16
- code: 0
17
- }), 0);
18
- }
19
- shutdown() {
20
- return this.forceFlush();
21
- }
22
- forceFlush() {
23
- return Promise.resolve();
24
- }
25
- // OAS-TOOLS OAS-TELEMETRY EXPORTER INTERFACE ---------------------------------------
26
- start() {
27
- console.log("Exporter started");
28
- }
29
- stop() {
30
- console.log("Exporter stopped");
31
- }
32
- reset() {
33
- console.log("Exporter reset");
34
- }
35
- isRunning() {
36
- return true;
37
- }
38
- find(search, callback) {
39
- console.log("Getting finished spans");
40
- callback(null, []);
41
- return [];
42
- }
43
- getFinishedSpans() {
44
- return [];
45
- }
46
- }
47
- exports.ConsoleExporter = ConsoleExporter;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.DynamicExporter = void 0;
7
- var _consoleExporter = require("./consoleExporter.cjs");
8
- /**
9
- * DynamicExporter is a class that can be used to dynamically change the exporter used by OpenTelemetry.
10
- * This is useful when you want to change the exporter at runtime.
11
- * Links start, stop and export methods to the Real exporter.
12
- */
13
- class DynamicExporter {
14
- /**
15
- * Returns the list of plugins registered in the exporter
16
- */
17
- getPlugins() {
18
- return this.exporter.plugins;
19
- }
20
- /**
21
- * Registers a plugin in the exporter
22
- */
23
- pushPlugin(pluginResource) {
24
- if (!this.exporter.plugins) {
25
- this.exporter.plugins = [];
26
- }
27
- this.exporter.plugins.push(pluginResource);
28
- }
29
- activatePlugin(pluginId) {
30
- const plugins = this.exporter.plugins;
31
- if (plugins) {
32
- // plugin.active = true;
33
- plugins.forEach(plugin => {
34
- if (plugin.id === pluginId) {
35
- plugin.active = true;
36
- }
37
- });
38
- }
39
- }
40
- constructor() {
41
- const defaultExporter = new _consoleExporter.ConsoleExporter();
42
- this.exporter = defaultExporter;
43
- this.export = (readableSpans, resultCallback) => defaultExporter.export(readableSpans, resultCallback);
44
- this.shutdown = () => defaultExporter.shutdown();
45
- this.forceFlush = () => defaultExporter.forceFlush();
46
- }
47
- changeExporter(newExporter) {
48
- this.exporter = newExporter;
49
- // OpenTelemetry methods
50
- this.export = (readableSpan, resultCallback) => newExporter.export(readableSpan, resultCallback);
51
- this.shutdown = () => newExporter.shutdown();
52
- this.forceFlush = () => newExporter.forceFlush();
53
- // Other methods should be called directly from the exporter: globalOasTlmConfig.dynamicSpanExporter.exporter.method()
54
- }
55
- }
56
- exports.DynamicExporter = DynamicExporter;
57
- var _default = exports.default = DynamicExporter;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- var _resources = require("@opentelemetry/resources");
4
- var _instrumentationHttp = require("@opentelemetry/instrumentation-http");
5
- var _semanticConventions = require("@opentelemetry/semantic-conventions");
6
- var _logger = _interopRequireDefault(require("../utils/logger.cjs"));
7
- var _logs = require("./logs.cjs");
8
- var _traces = require("./traces.cjs");
9
- var _instrumentation = require("@opentelemetry/instrumentation");
10
- var _metrics = require("./metrics.cjs");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- // import { NodeSDK } from '@opentelemetry/sdk-node';
13
-
14
- const oasTelemetryResource = (0, _resources.resourceFromAttributes)({
15
- [_semanticConventions.ATTR_SERVICE_NAME]: 'oas-telemetry-service'
16
- });
17
- if (process.env.OASTLM_MODULE_DISABLED !== 'true') {
18
- (0, _traces.initializeTraces)(oasTelemetryResource);
19
- (0, _metrics.initializeMetrics)(oasTelemetryResource);
20
- (0, _logs.initializeLogs)(oasTelemetryResource);
21
- (0, _instrumentation.registerInstrumentations)({
22
- instrumentations: [new _instrumentationHttp.HttpInstrumentation()
23
- // new ExpressInstrumentation(),
24
- ]
25
- });
26
- } else {
27
- _logger.default.info('🚫 OASTLM module is disabled, SDKs not initialized.');
28
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initializeLogs = initializeLogs;
7
- var _sdkLogs = require("@opentelemetry/sdk-logs");
8
- var _apiLogs = require("@opentelemetry/api-logs");
9
- var _config = require("../config.cjs");
10
- var _logger = _interopRequireDefault(require("../utils/logger.cjs"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- function initializeLogs(resource) {
13
- // Create and configure LoggerProvider
14
- const logExporter = _config.globalOasTlmConfig.logExporter;
15
- const logRecordProcessor = new _sdkLogs.SimpleLogRecordProcessor(logExporter);
16
- const loggerProvider = new _sdkLogs.LoggerProvider({
17
- resource: resource,
18
- processors: [logRecordProcessor]
19
- });
20
- // Get a logger instance
21
- const loggerInstance = loggerProvider.getLogger('oas-telemetry'); // Use loggerProvider to get the logger
22
- // Override console methods to emit logs via OpenTelemetry
23
- const originalConsoleMethods = {
24
- log: console.log,
25
- warn: console.warn,
26
- error: console.error,
27
- info: console.info,
28
- debug: console.debug
29
- };
30
- Object.keys(originalConsoleMethods).forEach(method => {
31
- // @ts-expect-error yes
32
- console[method] = (...args) => {
33
- loggerInstance.emit({
34
- severityNumber: _apiLogs.SeverityNumber[method.toUpperCase()] || _apiLogs.SeverityNumber.INFO,
35
- severityText: method.toUpperCase(),
36
- body: args.join(' '),
37
- attributes: {
38
- 'source.source': `console.${method}`
39
- }
40
- });
41
- // @ts-expect-error yes
42
- originalConsoleMethods[method](...args);
43
- };
44
- });
45
- _logger.default.info('✅ OpenTelemetry Logs initialized.');
46
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initializeMetrics = initializeMetrics;
7
- var _sdkMetrics = require("@opentelemetry/sdk-metrics");
8
- var _logger = _interopRequireDefault(require("../utils/logger.cjs"));
9
- var _config = require("../config.cjs");
10
- var _hostMetrics = require("@opentelemetry/host-metrics");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- function initializeMetrics(resource) {
13
- const metricReader = new _sdkMetrics.PeriodicExportingMetricReader({
14
- // exporter: new ConsoleMetricExporter(),
15
- exporter: _config.globalOasTlmConfig.metricsExporter,
16
- exportIntervalMillis: _config.globalOasTlmConfig.metricsExporterInterval
17
- });
18
- const meterProvider = new _sdkMetrics.MeterProvider({
19
- resource: resource,
20
- readers: [metricReader]
21
- });
22
- const hostMetrics = new _hostMetrics.HostMetrics({
23
- meterProvider
24
- });
25
- hostMetrics.start();
26
- _logger.default.info('✅ OpenTelemetry Metrics initialized.');
27
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.initializeTraces = initializeTraces;
7
- var _logger = _interopRequireDefault(require("../utils/logger.cjs"));
8
- var _sdkTraceNode = require("@opentelemetry/sdk-trace-node");
9
- var _config = require("../config.cjs");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- function initializeTraces(resource) {
12
- const tracerProvider = new _sdkTraceNode.NodeTracerProvider({
13
- resource: resource,
14
- spanProcessors: [new _sdkTraceNode.BatchSpanProcessor(_config.globalOasTlmConfig.dynamicSpanExporter)]
15
- });
16
- // tracerProvider.addSpanProcessor();
17
- tracerProvider.register();
18
- _logger.default.info('✅ OpenTelemetry Traces initialized.');
19
- }
@@ -1,20 +0,0 @@
1
- import DynamicExporter from "./exporters/dynamicExporter.js";
2
- import { InMemoryDBMetricsExporter } from "./exporters/InMemoryDBMetricsExporter.js";
3
- import { InMemoryLogRecordExporter } from "./exporters/InMemoryLogRecordExporter.js";
4
- //Environment variables
5
- //OASTLM_MODULE_DISABLED = 'true' //Disables the module (empty middleware and no tracing)
6
- export const globalOasTlmConfig = {
7
- dynamicSpanExporter: new DynamicExporter(),
8
- metricsExporter: new InMemoryDBMetricsExporter(),
9
- logExporter: new InMemoryLogRecordExporter(),
10
- metricsExporterInterval: 1000 * 30, // milliseconds
11
- baseURL: "/telemetry",
12
- spec: null,
13
- specFileName: "",
14
- autoActivate: true,
15
- authEnabled: false,
16
- apiKeyMaxAge: 1000 * 60 * 60, // 1 hour
17
- password: "oas-telemetry-password",
18
- jwtSecret: "oas-telemetry-secret",
19
- };
20
- export default { globalOasTlmConfig };
@@ -1,102 +0,0 @@
1
- import { ExportResultCode } from '@opentelemetry/core';
2
- //import in memory database
3
- import dataStore from '@seald-io/nedb';
4
- import logger from '../utils/logger.js';
5
- import { applyNesting, removeCircularRefs } from '../utils/circular.js';
6
- import { globalOasTlmConfig } from '../config.js';
7
- export class InMemoryExporter {
8
- constructor() {
9
- // Overrided by dynamic exporter
10
- this.plugins = [];
11
- this._spans = new dataStore();
12
- this._stopped = true;
13
- }
14
- ;
15
- export(readableSpans, resultCallback) {
16
- try {
17
- if (!this._stopped) {
18
- // Prepare spans to be inserted into the in-memory database (remove circular references and convert to nested objects)
19
- const cleanSpans = readableSpans
20
- .map(nestedSpan => removeCircularRefs(nestedSpan)) // to avoid JSON parsing error
21
- .map(span => applyNesting(span)) // to avoid dot notation in keys (neDB does not support dot notation in keys)
22
- .filter(span => {
23
- const target = span?.attributes?.http?.target; // Exclude spans where target includes 'telemetry' but NOT 'telemetry/utils'
24
- if (target && target.includes(globalOasTlmConfig.baseURL)) {
25
- return target.includes(globalOasTlmConfig.baseURL + '/utils');
26
- }
27
- return true;
28
- });
29
- // Insert spans into the in-memory database
30
- this._spans.insert(cleanSpans, (err, _newDoc) => {
31
- // p = {name, plugin
32
- this.plugins.forEach((pluginResource, i) => {
33
- cleanSpans.forEach((span) => {
34
- logger.debug(`Sending span <${span._id}> to plugin (Plugin #${i}) <${pluginResource.name}>`);
35
- logger.debug(`Span: \n<${JSON.stringify(span, null, 2)}`);
36
- //TODO: This should be called newSpan instead of newTrace
37
- pluginResource.plugin.newTrace(span);
38
- });
39
- });
40
- if (err) {
41
- console.error(err);
42
- return;
43
- }
44
- });
45
- }
46
- setTimeout(() => resultCallback({ code: ExportResultCode.SUCCESS }), 0);
47
- }
48
- catch (error) {
49
- console.error('Error exporting spans\n' + error.message + '\n' + error.stack);
50
- return resultCallback({
51
- code: ExportResultCode.FAILED,
52
- error: new Error('Error exporting spans\n' + error.message + '\n' + error.stack),
53
- });
54
- }
55
- }
56
- ;
57
- start() {
58
- this._stopped = false;
59
- }
60
- ;
61
- stop() {
62
- this._stopped = true;
63
- }
64
- ;
65
- isRunning() {
66
- return !this._stopped;
67
- }
68
- ;
69
- shutdown() {
70
- this._stopped = true;
71
- this._spans = new dataStore();
72
- return this.forceFlush();
73
- }
74
- ;
75
- /**
76
- * Exports any pending spans in the exporter
77
- */
78
- forceFlush() {
79
- return Promise.resolve();
80
- }
81
- ;
82
- //err,docs
83
- find(search, callback) {
84
- this._spans.find(search, callback);
85
- }
86
- reset() {
87
- this._spans = new dataStore();
88
- }
89
- ;
90
- getFinishedSpans() {
91
- return this._spans.getAllData();
92
- }
93
- ;
94
- /**
95
- * Inserts spans into the in-memory database.
96
- * @param spans - The spans to insert.
97
- * @param callback - The callback to execute after insertion.
98
- */
99
- insert(spans, callback) {
100
- this._spans.insert(spans, callback);
101
- }
102
- }
@@ -1,38 +0,0 @@
1
- export class ConsoleExporter {
2
- constructor() {
3
- // PLUGIN SYSTEM -----------------------------------------------------------
4
- this.plugins = [];
5
- }
6
- // OPEN TELEMETRY EXPORTER INTERFACE ---------------------------------------
7
- export(readableSpans, resultCallback) {
8
- console.log('ConsoleExporter | Received spans: ', readableSpans.length);
9
- setTimeout(() => resultCallback({ code: 0 }), 0);
10
- }
11
- shutdown() {
12
- return this.forceFlush();
13
- }
14
- forceFlush() {
15
- return Promise.resolve();
16
- }
17
- // OAS-TOOLS OAS-TELEMETRY EXPORTER INTERFACE ---------------------------------------
18
- start() {
19
- console.log("Exporter started");
20
- }
21
- stop() {
22
- console.log("Exporter stopped");
23
- }
24
- reset() {
25
- console.log("Exporter reset");
26
- }
27
- isRunning() {
28
- return true;
29
- }
30
- find(search, callback) {
31
- console.log("Getting finished spans");
32
- callback(null, []);
33
- return [];
34
- }
35
- getFinishedSpans() {
36
- return [];
37
- }
38
- }
@@ -1,50 +0,0 @@
1
- import { ConsoleExporter } from "./consoleExporter.js";
2
- /**
3
- * DynamicExporter is a class that can be used to dynamically change the exporter used by OpenTelemetry.
4
- * This is useful when you want to change the exporter at runtime.
5
- * Links start, stop and export methods to the Real exporter.
6
- */
7
- export class DynamicExporter {
8
- /**
9
- * Returns the list of plugins registered in the exporter
10
- */
11
- getPlugins() {
12
- return this.exporter.plugins;
13
- }
14
- /**
15
- * Registers a plugin in the exporter
16
- */
17
- pushPlugin(pluginResource) {
18
- if (!this.exporter.plugins) {
19
- this.exporter.plugins = [];
20
- }
21
- this.exporter.plugins.push(pluginResource);
22
- }
23
- activatePlugin(pluginId) {
24
- const plugins = this.exporter.plugins;
25
- if (plugins) {
26
- // plugin.active = true;
27
- plugins.forEach((plugin) => {
28
- if (plugin.id === pluginId) {
29
- plugin.active = true;
30
- }
31
- });
32
- }
33
- }
34
- constructor() {
35
- const defaultExporter = new ConsoleExporter();
36
- this.exporter = defaultExporter;
37
- this.export = (readableSpans, resultCallback) => defaultExporter.export(readableSpans, resultCallback);
38
- this.shutdown = () => defaultExporter.shutdown();
39
- this.forceFlush = () => defaultExporter.forceFlush();
40
- }
41
- changeExporter(newExporter) {
42
- this.exporter = newExporter;
43
- // OpenTelemetry methods
44
- this.export = (readableSpan, resultCallback) => newExporter.export(readableSpan, resultCallback);
45
- this.shutdown = () => newExporter.shutdown();
46
- this.forceFlush = () => newExporter.forceFlush();
47
- // Other methods should be called directly from the exporter: globalOasTlmConfig.dynamicSpanExporter.exporter.method()
48
- }
49
- }
50
- export default DynamicExporter;
@@ -1,26 +0,0 @@
1
- // import { NodeSDK } from '@opentelemetry/sdk-node';
2
- import { resourceFromAttributes } from '@opentelemetry/resources';
3
- import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
4
- import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
5
- import logger from '../utils/logger.js';
6
- import { initializeLogs } from './logs.js';
7
- import { initializeTraces } from './traces.js';
8
- import { registerInstrumentations } from '@opentelemetry/instrumentation';
9
- import { initializeMetrics } from './metrics.js';
10
- const oasTelemetryResource = resourceFromAttributes({
11
- [ATTR_SERVICE_NAME]: 'oas-telemetry-service'
12
- });
13
- if (process.env.OASTLM_MODULE_DISABLED !== 'true') {
14
- initializeTraces(oasTelemetryResource);
15
- initializeMetrics(oasTelemetryResource);
16
- initializeLogs(oasTelemetryResource);
17
- registerInstrumentations({
18
- instrumentations: [
19
- new HttpInstrumentation(),
20
- // new ExpressInstrumentation(),
21
- ],
22
- });
23
- }
24
- else {
25
- logger.info('🚫 OASTLM module is disabled, SDKs not initialized.');
26
- }
@@ -1,34 +0,0 @@
1
- import { LoggerProvider, SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs';
2
- import { SeverityNumber } from '@opentelemetry/api-logs';
3
- import { globalOasTlmConfig } from '../config.js';
4
- import logger from '../utils/logger.js';
5
- export function initializeLogs(resource) {
6
- // Create and configure LoggerProvider
7
- const logExporter = globalOasTlmConfig.logExporter;
8
- const logRecordProcessor = new SimpleLogRecordProcessor(logExporter);
9
- const loggerProvider = new LoggerProvider({ resource: resource, processors: [logRecordProcessor] });
10
- // Get a logger instance
11
- const loggerInstance = loggerProvider.getLogger('oas-telemetry'); // Use loggerProvider to get the logger
12
- // Override console methods to emit logs via OpenTelemetry
13
- const originalConsoleMethods = {
14
- log: console.log,
15
- warn: console.warn,
16
- error: console.error,
17
- info: console.info,
18
- debug: console.debug,
19
- };
20
- Object.keys(originalConsoleMethods).forEach((method) => {
21
- // @ts-expect-error yes
22
- console[method] = (...args) => {
23
- loggerInstance.emit({
24
- severityNumber: SeverityNumber[method.toUpperCase()] || SeverityNumber.INFO,
25
- severityText: method.toUpperCase(),
26
- body: args.join(' '),
27
- attributes: { 'source.source': `console.${method}` },
28
- });
29
- // @ts-expect-error yes
30
- originalConsoleMethods[method](...args);
31
- };
32
- });
33
- logger.info('✅ OpenTelemetry Logs initialized.');
34
- }
@@ -1,18 +0,0 @@
1
- import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
2
- import logger from '../utils/logger.js';
3
- import { globalOasTlmConfig } from '../config.js';
4
- import { HostMetrics } from '@opentelemetry/host-metrics';
5
- export function initializeMetrics(resource) {
6
- const metricReader = new PeriodicExportingMetricReader({
7
- // exporter: new ConsoleMetricExporter(),
8
- exporter: globalOasTlmConfig.metricsExporter,
9
- exportIntervalMillis: globalOasTlmConfig.metricsExporterInterval
10
- });
11
- const meterProvider = new MeterProvider({
12
- resource: resource,
13
- readers: [metricReader],
14
- });
15
- const hostMetrics = new HostMetrics({ meterProvider });
16
- hostMetrics.start();
17
- logger.info('✅ OpenTelemetry Metrics initialized.');
18
- }
@@ -1,12 +0,0 @@
1
- import logger from '../utils/logger.js';
2
- import { NodeTracerProvider, BatchSpanProcessor } from '@opentelemetry/sdk-trace-node';
3
- import { globalOasTlmConfig } from '../config.js';
4
- export function initializeTraces(resource) {
5
- const tracerProvider = new NodeTracerProvider({
6
- resource: resource,
7
- spanProcessors: [new BatchSpanProcessor(globalOasTlmConfig.dynamicSpanExporter)]
8
- });
9
- // tracerProvider.addSpanProcessor();
10
- tracerProvider.register();
11
- logger.info('✅ OpenTelemetry Traces initialized.');
12
- }
@@ -1,84 +0,0 @@
1
- export function removeCircularRefs(obj) {
2
- // const seen = new WeakMap(); // Used to keep track of visited objects
3
- // Replacer function to handle circular references
4
- function replacer(key, value) {
5
- if (key === "_spanProcessor") {
6
- return "oas-telemetry skips this field to avoid circular reference";
7
- }
8
- // GENERIC CIRCULAR REFERENCE HANDLING
9
- // if (typeof value === "object" && value !== null) {
10
- // // If the object has been visited before, return the name prefixed with "CIRCULAR+"
11
- // if (seen.has(value)) {
12
- // return `CIRCULAR${key}`;
13
- // }
14
- // seen.set(value, key); // Mark the object as visited with its name
15
- // }
16
- return value;
17
- }
18
- // Convert the object to a string and then parse it back
19
- // This will trigger the replacer function to handle circular references
20
- const jsonString = JSON.stringify(obj, replacer);
21
- return JSON.parse(jsonString);
22
- }
23
- /**
24
- * Recursively converts dot-separated keys in an object to nested objects.
25
- *
26
- * @param {any} obj - The object to process.
27
- * @returns {any} - The object with all dot-separated keys converted to nested objects.
28
- * @example
29
- * // Input:
30
- * // {
31
- * // "http.method": "GET",
32
- * // "http.url": "http://example.com",
33
- * // "nested.obj.key": "value"
34
- * // }
35
- * // Output:
36
- * // {
37
- * // "http": {
38
- * // "method": "GET",
39
- * // "url": "http://example.com"
40
- * // },
41
- * // "nested": {
42
- * // "obj": {
43
- * // "key": "value"
44
- * // }
45
- * // }
46
- * // }
47
- */
48
- export function convertToNestedObject(obj) {
49
- const result = {};
50
- for (const key in obj) {
51
- const keys = key.split('.');
52
- let temp = result;
53
- for (let i = 0; i < keys.length; i++) {
54
- const currentKey = keys[i];
55
- if (i === keys.length - 1) {
56
- // Last key, set the value
57
- temp[currentKey] = obj[key];
58
- }
59
- else {
60
- // Intermediate key, ensure the object exists
61
- if (!temp[currentKey]) {
62
- temp[currentKey] = {};
63
- }
64
- temp = temp[currentKey];
65
- }
66
- }
67
- }
68
- return result;
69
- }
70
- /**
71
- * Applies nesting to all dot-separated keys within an object.
72
- */
73
- export function applyNesting(obj) {
74
- for (const key in obj) {
75
- const value = obj[key];
76
- if (Array.isArray(value)) {
77
- obj[key] = value.map(item => typeof item === 'object' && item !== null ? applyNesting(item) : item);
78
- }
79
- else if (typeof value === 'object' && value !== null) {
80
- obj[key] = applyNesting(value);
81
- }
82
- }
83
- return convertToNestedObject(obj);
84
- }
@@ -1,6 +0,0 @@
1
- import { type GlobalOasTlmConfig } from "./types/index.js";
2
- export declare const globalOasTlmConfig: GlobalOasTlmConfig;
3
- declare const _default: {
4
- globalOasTlmConfig: GlobalOasTlmConfig;
5
- };
6
- export default _default;
@@ -1,13 +0,0 @@
1
- import { OasTlmExporter } from "../types/index.js";
2
- export declare class ConsoleExporter implements OasTlmExporter {
3
- plugins: never[];
4
- export(readableSpans: any, resultCallback: any): void;
5
- shutdown(): Promise<void>;
6
- forceFlush(): Promise<void>;
7
- start(): void;
8
- stop(): void;
9
- reset(): void;
10
- isRunning(): boolean;
11
- find(search: any, callback: any): never[];
12
- getFinishedSpans(): any[];
13
- }
@@ -1,25 +0,0 @@
1
- import { OasTlmExporter, PluginResource } from "../types/index.js";
2
- import { SpanExporter } from '@opentelemetry/sdk-trace-base';
3
- /**
4
- * DynamicExporter is a class that can be used to dynamically change the exporter used by OpenTelemetry.
5
- * This is useful when you want to change the exporter at runtime.
6
- * Links start, stop and export methods to the Real exporter.
7
- */
8
- export declare class DynamicExporter implements SpanExporter {
9
- exporter: OasTlmExporter;
10
- export: (readableSpans: any, resultCallback: any) => void;
11
- shutdown: () => Promise<void>;
12
- forceFlush: () => Promise<void>;
13
- /**
14
- * Returns the list of plugins registered in the exporter
15
- */
16
- getPlugins(): Array<PluginResource>;
17
- /**
18
- * Registers a plugin in the exporter
19
- */
20
- pushPlugin(pluginResource: PluginResource): void;
21
- activatePlugin(pluginId: string): void;
22
- constructor();
23
- changeExporter(newExporter: OasTlmExporter): void;
24
- }
25
- export default DynamicExporter;
@@ -1 +0,0 @@
1
- export declare function initializeLogs(resource: any): void;