diff --git a/index.js b/index.js index c51399d..34e33df 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ const gatherData = async () => { for (const logStream of logStreams.logStreams) { let latestLogStream = {}; let lastToken; + let currentTraceId = ""; do { lastToken = latestLogStream.nextForwardToken; const params2 = { @@ -46,6 +47,7 @@ const gatherData = async () => { } for (const logEvent of latestLogStream.events) { + // parse AWS provided values if (logEvent.message.startsWith("REPORT")) { const parts = logEvent.message.replace("\n", "").split("\t"); const requestId = /REPORT RequestId: (.*)/.exec(parts[0])[1]; @@ -87,7 +89,23 @@ const gatherData = async () => { }); continue; } + + if (logEvent.message.includes("ERROR")) { + console.log("Application has thrown error", logEvent.message); + if (currentTraceId) { + Object.assign(result[currentTraceId] || {}, { + error: { + message: logEvent.message, + }, + }); + } else { + console.log("no trace id beloning to current error", logEvent); + } + continue; + } + try { + console.log("Parse INFO message"); const msg = logEvent.message.split("INFO").slice(-1)[0]; const parsed = JSON.parse(msg); const requestId = logEvent.message @@ -95,18 +113,20 @@ const gatherData = async () => { .split("\t")[1]; const starttime = parsed.starttime; const endtime = parsed.endtime; - const traceId = parsed.traceId; - if (result[traceId]) { + currentTraceId = parsed.traceId; + + // add current entry to existing result object + if (result[currentTraceId]) { const obj = starttime ? { starttime } : { endtime }; - result[traceId].invocationInformation[ + result[currentTraceId].invocationInformation[ requestId ] = Object.assign( - result[traceId].invocationInformation[requestId] || {}, + result[currentTraceId].invocationInformation[requestId] || {}, obj ); } else { - result[traceId] = { - traceId, + result[currentTraceId] = { + traceId: currentTraceId, starttime: "", endtime: "", invocationInformation: { @@ -122,17 +142,18 @@ const gatherData = async () => { ); Object.entries(result).map(([traceId, value]) => { - if ( - Object.values(value.invocationInformation).length < fusionConfig.length - ) { - console.log( - "invocation information smaller than fusion config", - value.invocationInformation, - fusionConfig - ); - delete result[traceId]; - return; - } + // if ( + // Object.values(value.invocationInformation).length < fusionConfig.length + // ) { + // console.log( + // "invocation information smaller than fusion config", + // value.invocationInformation, + // fusionConfig + // ); + // delete result[traceId]; + // return; + // } + // find biggest endtime Object.values(value.invocationInformation).reduce((prev, curr) => { if (!curr.endtime) { diff --git a/package-lock.json b/package-lock.json index 15c8f34..448dc7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -168,9 +168,9 @@ } }, "node-fetch": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", - "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" }, "process-nextick-args": { "version": "2.0.1", diff --git a/package.json b/package.json index ca14ef1..88e79ba 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "mongodb": "^3.5.6", - "node-fetch": "^2.6.0", + "node-fetch": "^2.6.1", "dotenv": "^8.2.0" }, "devDependencies": {