Added correlation ID in OCPP logs
MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -683,7 +683,16 @@ export default class Logging {
// Compute size
const sizeOfRequestDataKB = Utils.truncTo(Utils.createDecimal(
sizeof(request)).div(1024).toNumber(), 2);
- const message = `${direction} OCPP Request '${action}' on '${chargingStationID}' has been ${direction === '>>' ? 'received' : 'sent'} - Req ${sizeOfRequestDataKB} KB`;
+ const performanceID = await PerformanceStorage.savePerformanceRecord(
+ Utils.buildPerformanceRecord({
+ tenantSubdomain: tenant.subdomain,
+ chargingStationID,
+ group: PerformanceRecordGroup.OCPP,
+ reqSizeKb: sizeOfRequestDataKB,
+ action
+ })
+ );
+ const message = `${direction} OCPP Request '${action}~${Utils.last5Chars(performanceID)}' on '${chargingStationID}' has been ${direction === '>>' ? 'received' : 'sent'} - Req ${sizeOfRequestDataKB} KB`;
Utils.isDevelopmentEnv() && Logging.logConsoleInfo(message);
await Logging.logDebug({
tenantID: tenant.id,
@@ -694,15 +703,6 @@ export default class Logging {
module: module, method: action, action,
message, detailedMessages: { request }
});
- const performanceID = await PerformanceStorage.savePerformanceRecord(
- Utils.buildPerformanceRecord({
- tenantSubdomain: tenant.subdomain,
- chargingStationID,
- group: PerformanceRecordGroup.OCPP,
- reqSizeKb: sizeOfRequestDataKB,
- action
- })
- );
return {
startTimestamp: Date.now(),
performanceID
@@ -718,7 +718,7 @@ export default class Logging {
const executionDurationMillis = performanceTracingData?.startTimestamp ? Date.now() - performanceTracingData.startTimestamp : 0;
const sizeOfResponseDataKB = Utils.truncTo(Utils.createDecimal(
sizeof(response)).div(1024).toNumber(), 2);
- const message = `${direction} OCPP Request '${action}' on '${chargingStationID}' has been processed ${executionDurationMillis ? 'in ' + executionDurationMillis.toString() + ' ms' : ''} - Res ${(sizeOfResponseDataKB > 0) ? sizeOfResponseDataKB : '?'} KB`;
+ const message = `${direction} OCPP Request '${action}~${Utils.last5Chars(performanceTracingData.performanceID)}' on '${chargingStationID}' has been processed ${executionDurationMillis ? 'in ' + executionDurationMillis.toString() + ' ms' : ''} - Res ${(sizeOfResponseDataKB > 0) ? sizeOfResponseDataKB : '?'} KB`;
Utils.isDevelopmentEnv() && Logging.logConsoleInfo(message);
if (executionDurationMillis > Constants.PERF_MAX_RESPONSE_TIME_MILLIS) {
const error = new Error(`Execution must be < ${Constants.PERF_MAX_RESPONSE_TIME_MILLIS} ms`);

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -253,6 +253,13 @@ export default class Utils {
return nanoid(length);
}
+ public static last5Chars(data: string): string {
+ if (!data || data.length <= 5) {
+ return data;
+ }
+ return data.slice(data.length - 5, data.length);
+ }
+
public static generateTagID(name: string, firstName: string): string {
let tagID = '';
if (name && name.length > 0) {

Added correlation ID in OCPP logs