diff --git a/api-service/src/app.ts b/api-service/src/app.ts index e01491cd..abc6b51d 100644 --- a/api-service/src/app.ts +++ b/api-service/src/app.ts @@ -15,7 +15,8 @@ import _ from "lodash"; const app: Application = express(); -((config.otel && _.toLower(config?.otel?.enable) === "true")) && OTelService.init() // Initialisation of Open telemetry Service. +// Initialisation of Open telemetry Service. +(config.otel && _.toLower(config?.otel?.enable) === "true") ? OTelService.init() : console.info("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 61ca7980..3539f491 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..65186cbd 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 && _.toLower(config?.otel?.enable) === "true")){ + 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); + } } + }