Skip to content

Commit

Permalink
Merge pull request #325 from sematext/pbc_SC-16333_vercel-syslog-parsing
Browse files Browse the repository at this point in the history
SC-16333 Extract fields from vercel syslog messages
  • Loading branch information
PabloB94 authored May 25, 2023
2 parents da86d3e + bbe315e commit 829e771
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface
"esversion" : 6, // Disable JSHint from unnecessary warnings when code use ES6 syntax
"esversion" : 9, // Disable JSHint from unnecessary warnings when code use ES6 syntax


// Custom Globals
Expand Down
53 changes: 44 additions & 9 deletions lib/plugins/output-filter/vercel-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ function parseVercelLog (log) {
initDuration.coldStart = true
initDuration.initDuration = +lambdaVals[4].match(initDurationRegex)[1]
}

return {
message,
duration,
billedDuration,
memorySize,
maxMemoryUsed,
...initDuration,
...rest
const logDetails = extractLogDetails(message)
if (logDetails === message) {
return {
message,
duration,
billedDuration,
memorySize,
maxMemoryUsed,
...initDuration,
...rest
}
} else {
return {
...logDetails,
duration,
billedDuration,
memorySize,
maxMemoryUsed,
...initDuration,
...rest
}
}
}

Expand Down Expand Up @@ -121,4 +133,27 @@ function tryParseErrorLine (line) {
}
}

function extractLogDetails (logLine) {
const regex = /^START RequestId: (\S+) Version: (\S+)\n([^]+?)\t(\S+)\t(\S+)\t({(?:[^{}]|{[^{}]*})+})/ // Regular expression to match the log details

const match = logLine.match(regex) // Find the match of the regular expression in the log line

if (match) {
const requestId = match[1]
const version = match[2]
const timestamp = match[3]
const logLevel = match[5]
const message = match[6] // Get the JSON object string
return {
requestId,
version,
timestamp,
logLevel,
message
}
}

return { message: logLine } // Return unparsed if no log details are found in the log line
}

module.exports = formatVercelLogsOutput

0 comments on commit 829e771

Please sign in to comment.