Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 0f6dd0c

Browse files
authored
We can't use nulls and booleans as dimension values… (#45)
1 parent f5bb81c commit 0f6dd0c

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

signalfx-transform-helper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ function sanitize(name) {
1919
function extractDetailsForSfx(cwEvent) {
2020
let detailsMap = {};
2121
for (let [key, value] of Object.entries(cwEvent.detail)) {
22-
detailsMap[sanitize(DETAIL_PREFIX + key)] = isPrimitive(value) ? value : JSON.stringify(value);
22+
let sanitizedKey = sanitize(DETAIL_PREFIX + key);
23+
if (value == null || typeof value == "boolean" || !isPrimitive(value)) {
24+
detailsMap[sanitizedKey] = JSON.stringify(value);
25+
} else {
26+
detailsMap[sanitizedKey] = value;
27+
}
2328
}
2429
return detailsMap;
2530
}

spec/signalfx-transform-helper-spec.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,34 @@ describe('signalfx-transform-helper', () => {
3232
expect(sanitizedAndPrefixed).to.deep.equal(expected);
3333
});
3434

35-
it('should stringify arrays and objects', () => {
35+
it('should stringify arrays, objects, nulls and booleans', () => {
3636
const obj = {
3737
id: "7bf73129-1428-4cd3-a780-95db273d1602",
3838
'detail-type': "EC2 Instance State-change Notification",
3939
detail: {
4040
key1: 'value',
4141
key2: 5,
42-
key3: {inner1: 42, inner2: 43},
43-
key4: [2, "one"]
42+
"key2.1": 5.1,
43+
key3: {' inner1 ': 42, inner2: null},
44+
key4: [2, "one"],
45+
key5: [],
46+
' key6 ': ' value space-surrounded ',
47+
key7: null,
48+
key8: true,
49+
key9: new Boolean(false),
4450
}
4551
};
4652
const expected = {
4753
detail_key1: 'value',
4854
detail_key2: 5,
49-
detail_key3: '{"inner1":42,"inner2":43}',
50-
detail_key4: '[2,"one"]'
55+
detail_key2_1: 5.1,
56+
detail_key3: '{" inner1 ":42,"inner2":null}',
57+
detail_key4: '[2,"one"]',
58+
detail_key5: '[]',
59+
detail__key6_: ' value space-surrounded ',
60+
detail_key7: 'null',
61+
detail_key8: 'true',
62+
detail_key9: 'false',
5163
};
5264
const sanitizedAndPrefixed = signalfxHelper.extractDetailsForSfx(obj);
5365
expect(sanitizedAndPrefixed).to.deep.equal(expected);

0 commit comments

Comments
 (0)