Skip to content

Commit

Permalink
Merge pull request #2733 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu committed Oct 21, 2021
2 parents f5820bb + 78f0645 commit bfbab66
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"lambda-monitor-logger": "3.0.1",
"lodash.get": "4.4.2",
"lru-cache-ext": "2.0.1",
"object-scan": "17.1.0",
"promise-pool-ext": "2.1.2",
"request": "2.88.2",
"request-promise-native": "1.0.9",
Expand Down
14 changes: 14 additions & 0 deletions src/logic/bundler-handler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const objectScan = require('object-scan');
const Datadog = require('./util/datadog');

module.exports = async (event, context) => {
Expand All @@ -6,5 +7,18 @@ module.exports = async (event, context) => {
return;
}
const arr = event.Records.map(({ body }) => JSON.parse(body));
// Workaround since Datadog strips empty objects
// Reference: https://docs.datadoghq.com/logs/log_configuration/parsing/?tab=matchers
objectScan(['[*]**'], {
filterFn: ({ parent, property, value }) => {
if (value === null) {
// eslint-disable-next-line no-param-reassign
parent[property] = '<null>';
} else if (value instanceof Object && Object.keys(value).length === 0) {
// eslint-disable-next-line no-param-reassign
parent[property] = `<empty ${JSON.stringify(value)}>`;
}
}
})(arr);
await datadog.Logger.uploadJsonArray(arr);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
"_level": "warning",
"_group": "/aws/lambda/peg-solitiare-dev-overview",
"path": "path/to/data3.json.gz",
"status": 200
"status": 200,
"event": {
"emptyArray": "<empty []>",
"emptyObj": "<empty {}>",
"arrContainingEmptyObj": [
"<empty {}>"
],
"null": "<null>"
}
}
],
"status": 200,
Expand Down
6 changes: 6 additions & 0 deletions test/lambda/tests/bundlerHandler/multi_event.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"_timestamp": 1632869955749,
"_level": "warning",
"_group": "/aws/lambda/peg-solitiare-dev-overview",
"event": {
"emptyArray": [],
"emptyObj": {},
"arrContainingEmptyObj": [{}],
"null": null
},
"path": "path/to/data3.json.gz",
"status": 200
},
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5272,6 +5272,11 @@ object-scan@17.0.0:
resolved "https://registry.yarnpkg.com/object-scan/-/object-scan-17.0.0.tgz#ee51a7f7c2b6a056ae513a67d75955ddcf545fd1"
integrity sha512-/GkRZGupBmWcbmWqWqQ5/I98MRryIlrTVenteL7DOvymqm11WlL4tcXwxH7iV+9Pc8ouQwtk/4rLAnXJp6Qobw==

object-scan@17.1.0:
version "17.1.0"
resolved "https://registry.yarnpkg.com/object-scan/-/object-scan-17.1.0.tgz#35e67020b94ee1e6cd59ccef5ff91c2e4e5e302d"
integrity sha512-r+LfWbSftyqVBj/WqSEQ4sSCDN1T0JBVCfHp2WO3vf1ykn6IjVMKtJ34+ABvdDDGjjCgq1L8TC6yc2CV37jRwA==

object-treeify@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/object-treeify/-/object-treeify-2.0.0.tgz#4c6c7f016f69b5f84c5f7d882bf41d18bdf03acb"
Expand Down

0 comments on commit bfbab66

Please sign in to comment.