-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLoopProcessor.js
More file actions
54 lines (49 loc) · 1.63 KB
/
Copy pathEventLoopProcessor.js
File metadata and controls
54 lines (49 loc) · 1.63 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
49
50
51
52
53
54
"use strict";
const performance = require("perf_hooks").performance;
const eventLoopStats = require("event-loop-stats");
exports.__esModule = true;
exports.EventLoopProcessor = void 0;
var lag = 0;
var events;
function measureLag() {
var start = performance.now();
setTimeout(function () {
lag = performance.now() - start;
measureLag(); // Recurse
});
}
// Requires npm install --save event-loop-stats
function measureEvents() {
events = eventLoopStats.sense();
}
var EventLoopProcessor = /** @class */ (function () {
function EventLoopProcessor(nextProcessor) {
measureLag();
this._nextProcessor = nextProcessor;
}
EventLoopProcessor.prototype.onStart = function (span, parentContext) {
// Save Event Loop Metrics
span.setAttribute("node.event_loop_lag", lag);
measureEvents();
span.setAttribute("node.event_loop_max", events.max);
span.setAttribute("node.event_loop_min", events.min);
span.setAttribute("node.event_loop_sum", events.sum);
span.setAttribute("node.event_loop_num", events.num);
if (this._nextProcessor) {
this._nextProcessor.onStart(span, parentContext);
}
};
EventLoopProcessor.prototype.onEnd = function (span) {
if (this._nextProcessor) {
this._nextProcessor.onEnd(span);
}
};
EventLoopProcessor.prototype.shutdown = function () {
return this._nextProcessor ? this._nextProcessor.shutdown() : Promise.resolve();
};
EventLoopProcessor.prototype.forceFlush = function () {
return this._nextProcessor ? this._nextProcessor.forceFlush() : Promise.resolve();
};
return EventLoopProcessor;
})();
exports.EventLoopProcessor = EventLoopProcessor;