Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified azure/activity_logs_monitoring/deploy.zip
Binary file not shown.
14 changes: 6 additions & 8 deletions azure/activity_logs_monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const { app, InvocationContext } = require('@azure/functions');

const VERSION = '2.1.1';
const VERSION = '2.2.0';

const STRING = 'string'; // example: 'some message'
const STRING_ARRAY = 'string-array'; // example: ['one message', 'two message', ...]
Expand Down Expand Up @@ -383,30 +383,28 @@ class EventhubLogHandler {
this.records.push(originalRecord);
}
} else {
this.records.push(this.fixPropertiesJsonString(originalRecord));
this.records.push(this.parseProperties(originalRecord));
}
} else {
record = this.addTagsToStringLog(record);
this.records.push(record);
}
}

fixPropertiesJsonString(record) {
parseProperties(record) {
// Check if properties field is a malformed JSON String
if (Object.hasOwn(record, 'properties') && (typeof record.properties === 'string') && (record.properties.includes("':'"))) {
try {
// If the check is true, find and replace single quotes
// with double quotes, to make a proper JSON
// which is then converted into a JSON Object
record.properties = JSON.parse(record.properties.replace(/'/g, '"'));
return record;
let parsedProperties = JSON.parse(record.properties.replace(/'/g, '"'));
record.properties = parsedProperties;
} catch {
this.context.error('Unable to fix properties field to JSON Object');
return record;
}
} else {
return record;
}
return record;
}

handleLogs(logs) {
Expand Down
18 changes: 13 additions & 5 deletions azure/activity_logs_monitoring/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure/activity_logs_monitoring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"author": "Datadog",
"license": "Apache-2.0",
"dependencies": {
"@azure/functions": "^4.8.0"
"@azure/functions": "^4.9.0"
}
}
12 changes: 6 additions & 6 deletions azure/test/activity_logs_monitoring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,15 +818,15 @@ describe('Log Splitting', function() {
});
});
});
describe('EventhubLogHandler Fix Properties Json String', function() {
describe('EventhubLogHandler Parse Properties', function() {

beforeEach(function() {
this.forwarder = setUp();
});

it('parses properties string with single quotes into object', function() {
const record = { properties: "{'key':'value'}" };
const result = this.forwarder.fixPropertiesJsonString(record);
const result = this.forwarder.parseProperties(record);

const expectedProperties = { properties: { key: "value" } };

Expand All @@ -842,7 +842,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {

it('parses object that doesnt have properties', function() {
const record = { hostname: "server_name", subObject: { key:"value"} };
const result = this.forwarder.fixPropertiesJsonString(record);
const result = this.forwarder.parseProperties(record);

assert.deepEqual(
record,
Expand All @@ -856,7 +856,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {

it('parses properties string with nested objects', function() {
const record = { properties: "{'key':'value','subObj':{ 'subKey' : 'subValue' }}" };
const result = this.forwarder.fixPropertiesJsonString(record);
const result = this.forwarder.parseProperties(record);

const expectedProperties = { properties: { key: "value", subObj: { subKey: "subValue"} } };

Expand All @@ -872,7 +872,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {

it("leaves properties string unchanged when it doesn't match the malformed pattern", function() {
const record = { properties: 'some plain string without colons' };
const result = this.forwarder.fixPropertiesJsonString(record);
const result = this.forwarder.parseProperties(record);

assert.deepEqual(
record,
Expand All @@ -887,7 +887,7 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
it('logs an error and returns original record when replacement results in invalid JSON', function() {
// includes the "':'" marker so the function attempts replacement, but JSON remains invalid
const badRecord = { properties: "Look i know i shouldn't but, i will do this ':' " };
const result = this.forwarder.fixPropertiesJsonString(badRecord);
const result = this.forwarder.parseProperties(badRecord);

assert.deepEqual(
badRecord,
Expand Down
Loading