Skip to content

Commit

Permalink
Merge pull request #287 from Sanketika-Obsrv/open-telemetry
Browse files Browse the repository at this point in the history
Open Telemetry Changes
  • Loading branch information
HarishGangula authored Nov 28, 2024
2 parents 35c4370 + 4ad396b commit a2a61a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion api-service/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 1 addition & 3 deletions api-service/src/configs/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


}
43 changes: 23 additions & 20 deletions api-service/src/services/otel/OTelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,29 @@ export class OTelService {


public static generateOTelLog(auditLog: Record<string, any>, severity: 'INFO' | 'WARN' | 'ERROR', logType?: string) {
const loggerInstance = this.loggerProvider.getLogger('obsrv-api-service');

const severityMapping: Record<string, number> = {
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<string, number> = {
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);
}
}


}

0 comments on commit a2a61a3

Please sign in to comment.