Skip to content

Commit 486d79e

Browse files
Applied recommendation from mattsp1290, which simplifies the if condition
Co-authored-by: Matt Spurlin <matt.spurlin@datadoghq.com>
1 parent 4411f19 commit 486d79e

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

azure/activity_logs_monitoring/index.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -390,27 +390,18 @@ class EventhubLogHandler {
390390
}
391391

392392
fixPropertiesJsonString(record) {
393-
try {
394-
// Check if properties field is a string
395-
if (typeof record.properties === 'string') {
396-
// If it is a string, check if it is a malformed JSON String
397-
// By checking for ':'
398-
if (record.properties.includes("':'")) {
399-
// If the check is true, find / replace single quotes
400-
// with double quotes, to make a proper JSON
401-
// which is then converted into a JSON Object
402-
record.properties = JSON.parse(record.properties.replace(/'/g, '"'));
403-
return record;
404-
}else {
405-
return record;
406-
}
407-
} else {
408-
return record;
393+
// Check if properties field is a malformed JSON String
394+
if (Object.hasOwn(record, 'properties') && (typeof record.properties === 'string') && (record.properties.includes("':'"))) {
395+
try {
396+
// If the check is true, find and replace single quotes
397+
// with double quotes, to make a proper JSON
398+
// which is then converted into a JSON Object
399+
parsedProperties = JSON.parse(record.properties.replace(/'/g, '"'));
400+
record.properties = parsedProperties;
401+
} catch {
402+
this.context.error('Unable to fix properties field to JSON Object');
409403
}
410-
} catch {
411-
this.context.error('Unable to fix properties field to JSON Object');
412-
return record;
413-
}
404+
return record;
414405
}
415406

416407
handleLogs(logs) {

0 commit comments

Comments
 (0)