-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (48 loc) · 1.58 KB
/
index.js
File metadata and controls
48 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"use strict";
function log(event, executionContent) {
var date1_ms = executionContent.startedAt.getTime();
var date2_ms = executionContent.finishedAt.getTime();
var executionTime = Number.isFinite(date2_ms - date1_ms)
? date2_ms - date1_ms
: 0;
var logExt = {
event: event,
response: {
statusCode: executionContent.statusCode,
body: executionContent.resBody,
},
executionTime: executionTime,
};
console.log("firetail:log-ext:" +
Buffer.from(JSON.stringify(logExt)).toString("base64"));
}
function wrap(next) {
return function (event, context) {
var startedAt = new Date();
var observations = [];
var workInProgress;
if (next.constructor.name === "Promise" ||
next.constructor.name === "AsyncFunction") {
workInProgress = next(event, context, function () { });
}
else if (typeof next === "function") {
workInProgress = Promise.resolve(next(event, context, function () { }));
}
else {
workInProgress = Promise.resolve(next);
}
return workInProgress.then(function (result) {
var body = result.body, statusCode = result.statusCode;
var finishedAt = new Date();
log(event, {
statusCode: statusCode || 200,
resBody: body,
startedAt: startedAt,
finishedAt: finishedAt,
});
return result;
});
};
}
module.exports = wrap;
//# sourceMappingURL=index.js.map