Skip to content

Commit

Permalink
Fixing parsing of Cloudwatch Logs streamed to Lambda.
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetric committed Sep 10, 2019
1 parent e8a9353 commit 3abd040
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion handlers/convertString.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ exports.process = function(config) {

config.data = _.map(config.data, function(datum) {
var parts = _.map(datum, function(value, key) {
key = key.replace('-', '_').replace(/\W/g, '');
key = String(key).replace('-', '_').replace(/\W/g, '');
value = String(value).replace(/\n/g, ' ');
return key + '="' + value + '"';
});

Expand Down
11 changes: 7 additions & 4 deletions handlers/formatCloudwatchLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ exports.process = function(config) {
if (parts && parts[1] === 'START') {
item.logType = 'start';
parts = item.message.match(/^START RequestId: ([a-z0-9-]+) Version: (\S+)/); // eslint-disable-line max-len
if (parts && parts.length === 3) {
if (parts && parts.length >= 3) {
item.requestId = parts[1];
item.lambdaVersion = parts[2];
delete item.message;
}
} else if (parts && parts[1] === 'REPORT') {
item.logType = 'report';
parts = item.message.match(/^REPORT RequestId: ([a-z0-9-]+)\tDuration: ([0-9.]+) ms\tBilled Duration: ([0-9.]+) ms \tMemory Size: ([0-9.]+) MB\tMax Memory Used: ([0-9.]+)/); // eslint-disable-line max-len
if (parts && parts.length === 6) {
parts = item.message.match(/^REPORT RequestId: ([a-z0-9-]+)\tDuration: ([0-9.]+) ms\tBilled Duration: ([0-9.]+) ms\tMemory Size: ([0-9.]+) MB\tMax Memory Used: ([0-9.]+)/); // eslint-disable-line max-len
if (parts && parts.length >= 6) {
item.requestId = parts[1];
item.duration = parts[2];
item.durationBilled = parts[3];
item.memConfigured = parts[4];
item.memUsed = parts[5];
delete item.message;
}
} else if (parts && parts[1] === 'END') {
item.logType = 'end';
parts = item.message.match(/^END RequestId: ([a-z0-9-]+)/);
if (parts && parts[1]) {
item.requestId = parts[1];
delete item.message;
}
} else {
item.logType = 'message';
parts = item.message.match(/^(.*)\t(.*)\t((.|\n)*)/m);
if (parts && parts.length === 5) {
if (parts && parts.length >= 5) {
item.requestId = parts[2];
item.message = parts[3];
}
Expand Down

0 comments on commit 3abd040

Please sign in to comment.