forked from Meteor-Community-Packages/meteor-elastic-apm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
meteor-elastic-apm.js
67 lines (54 loc) · 1.97 KB
/
meteor-elastic-apm.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint-disable no-undef */
const shimmer = require('shimmer');
const Fibers = require('fibers');
const Agent = require('elastic-apm-node');
const { Session, Subscription, MongoCursor } = require('./meteorx');
const instrumentMethods = require('./instrumenting/methods');
const instrumentHttpIn = require('./instrumenting/http-in');
const instrumentHttpOut = require('./instrumenting/http-out');
const instrumentSession = require('./instrumenting/session');
const instrumentSubscription = require('./instrumenting/subscription');
const instrumentAsync = require('./instrumenting/async');
const instrumentDB = require('./instrumenting/db');
const startMetrics = require('./metrics');
const hackDB = require('./hacks');
const [framework, version] = Meteor.release.split('@');
Agent.setFramework({
name: framework,
version,
override: true
});
shimmer.wrap(Agent, 'start', function(startAgent) {
return function(...args) {
const config = args[0] || {};
if (config.active !== false) {
try {
// Must be called before any other route is registered on WebApp.
instrumentHttpIn(Agent, WebApp);
Meteor.startup(() => {
try {
hackDB();
instrumentMethods(Agent, Meteor);
instrumentHttpOut(Agent, WebApp);
instrumentSession(Agent, Session);
instrumentSubscription(Agent, Subscription);
instrumentAsync(Agent, Fibers);
instrumentDB(Agent, Meteor, MongoCursor);
startAgent.apply(Agent, args);
startMetrics(Agent);
Agent.logger.info('meteor-elastic-apm completed instrumenting');
} catch (e) {
Agent.logger.error('Could not start meteor-elastic-apm');
throw e;
}
});
} catch (e) {
Agent.logger.error('Could not start meteor-elastic-apm');
throw e;
}
} else {
Agent.logger.warn('meteor-elastic-apm is not active');
}
};
});
module.exports = Agent;