Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 38 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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];
Expand Down Expand Up @@ -87,26 +89,44 @@ 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
.split("INFO")[0]
.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: {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down