Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion signalfx-transform-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ function sanitize(name) {
function extractDetailsForSfx(cwEvent) {
let detailsMap = {};
for (let [key, value] of Object.entries(cwEvent.detail)) {
detailsMap[sanitize(DETAIL_PREFIX + key)] = isPrimitive(value) ? value : JSON.stringify(value);
let sanitizedKey = sanitize(DETAIL_PREFIX + key);
if (value == null || typeof value == "boolean" || !isPrimitive(value)) {
detailsMap[sanitizedKey] = JSON.stringify(value);
} else {
detailsMap[sanitizedKey] = value;
}
}
return detailsMap;
}
Expand Down
22 changes: 17 additions & 5 deletions spec/signalfx-transform-helper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,34 @@ describe('signalfx-transform-helper', () => {
expect(sanitizedAndPrefixed).to.deep.equal(expected);
});

it('should stringify arrays and objects', () => {
it('should stringify arrays, objects, nulls and booleans', () => {
const obj = {
id: "7bf73129-1428-4cd3-a780-95db273d1602",
'detail-type': "EC2 Instance State-change Notification",
detail: {
key1: 'value',
key2: 5,
key3: {inner1: 42, inner2: 43},
key4: [2, "one"]
"key2.1": 5.1,
key3: {' inner1 ': 42, inner2: null},
key4: [2, "one"],
key5: [],
' key6 ': ' value space-surrounded ',
key7: null,
key8: true,
key9: new Boolean(false),
}
};
const expected = {
detail_key1: 'value',
detail_key2: 5,
detail_key3: '{"inner1":42,"inner2":43}',
detail_key4: '[2,"one"]'
detail_key2_1: 5.1,
detail_key3: '{" inner1 ":42,"inner2":null}',
detail_key4: '[2,"one"]',
detail_key5: '[]',
detail__key6_: ' value space-surrounded ',
detail_key7: 'null',
detail_key8: 'true',
detail_key9: 'false',
};
const sanitizedAndPrefixed = signalfxHelper.extractDetailsForSfx(obj);
expect(sanitizedAndPrefixed).to.deep.equal(expected);
Expand Down