From cc128fb6796a539e66b94c4317422b2d40938dba Mon Sep 17 00:00:00 2001 From: Manjunath Date: Thu, 28 Nov 2024 14:59:23 +0530 Subject: [PATCH 1/2] #I250: Updated the configurations of open telemetry service --- api-service/src/app.ts | 3 +- api-service/src/configs/Config.ts | 4 +- api-service/src/services/otel/OTelService.ts | 43 +++++++++++--------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/api-service/src/app.ts b/api-service/src/app.ts index bfcc2f9a..101a4d9e 100644 --- a/api-service/src/app.ts +++ b/api-service/src/app.ts @@ -14,7 +14,8 @@ import { interceptAuditEvents } from "./services/telemetry"; const app: Application = express(); -(config.otel && config.otel.enable) && OTelService.init() // Initialisation of Open telemetry Service. +// Initialisation of Open telemetry Service. +(config.otel && config.otel.enable) ? OTelService.init() : console.log("OpenTelemetry Service is disabled"); app.use(bodyParser.json({ limit: config.body_parser_limit})); app.use(express.text()); diff --git a/api-service/src/configs/Config.ts b/api-service/src/configs/Config.ts index f681e022..6a9cf1e5 100644 --- a/api-service/src/configs/Config.ts +++ b/api-service/src/configs/Config.ts @@ -116,9 +116,7 @@ export const config = { "user_token_public_key": process.env.user_token_public_key || "", "is_RBAC_enabled": process.env.is_rbac_enabled || "false", "otel": { - "enable": process.env.OTEL_ENABLE || true, + "enable": process.env.OTEL_ENABLE || false, "collector_endpoint": process.env.OTEL_COLLECTOR_ENDPOINT || "http://localhost:4318" } - - } diff --git a/api-service/src/services/otel/OTelService.ts b/api-service/src/services/otel/OTelService.ts index fc8c0a54..aa56425a 100644 --- a/api-service/src/services/otel/OTelService.ts +++ b/api-service/src/services/otel/OTelService.ts @@ -130,26 +130,29 @@ export class OTelService { public static generateOTelLog(auditLog: Record, severity: 'INFO' | 'WARN' | 'ERROR', logType?: string) { - const loggerInstance = this.loggerProvider.getLogger('obsrv-api-service'); - - const severityMapping: Record = { - INFO: logsAPI.SeverityNumber.INFO, - WARN: logsAPI.SeverityNumber.WARN, - ERROR: logsAPI.SeverityNumber.ERROR, - }; - - const severityNumber = severityMapping[severity] || logsAPI.SeverityNumber.INFO; - - const logRecord = { - severityNumber, - severityText: severity, - body: JSON.stringify(auditLog), - attributes: { - 'log.type': logType || 'console', - ...auditLog, - }, - }; - loggerInstance.emit(logRecord); + if(config.otel && config.otel.enable){ + const loggerInstance = this.loggerProvider.getLogger('obsrv-api-service'); + + const severityMapping: Record = { + INFO: logsAPI.SeverityNumber.INFO, + WARN: logsAPI.SeverityNumber.WARN, + ERROR: logsAPI.SeverityNumber.ERROR, + }; + + const severityNumber = severityMapping[severity] || logsAPI.SeverityNumber.INFO; + + const logRecord = { + severityNumber, + severityText: severity, + body: JSON.stringify(auditLog), + attributes: { + 'log.type': logType || 'console', + ...auditLog, + }, + }; + loggerInstance.emit(logRecord); + } } + } From 4ad396bf9fc81af219f6b140c8de7a4be63f0887 Mon Sep 17 00:00:00 2001 From: Manjunath Date: Thu, 28 Nov 2024 16:47:18 +0530 Subject: [PATCH 2/2] #I250: Moved the file from otel to services --- api-service/src/services/otel/OTelService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-service/src/services/otel/OTelService.ts b/api-service/src/services/otel/OTelService.ts index aa56425a..65186cbd 100644 --- a/api-service/src/services/otel/OTelService.ts +++ b/api-service/src/services/otel/OTelService.ts @@ -130,7 +130,7 @@ export class OTelService { public static generateOTelLog(auditLog: Record, severity: 'INFO' | 'WARN' | 'ERROR', logType?: string) { - if(config.otel && config.otel.enable){ + if((config.otel && _.toLower(config?.otel?.enable) === "true")){ const loggerInstance = this.loggerProvider.getLogger('obsrv-api-service'); const severityMapping: Record = {