-
Notifications
You must be signed in to change notification settings - Fork 225
/
_agent.js
58 lines (50 loc) · 1.57 KB
/
_agent.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
/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/
'use strict';
// DEPRECATED: New tests should not use this wrapper. Instead using the
// real Agent directly, and its `agent.destroy()` method to clean up state
// and the end of tests. E.g.:
//
// const Agent = require('.../lib/agent')
// test('test name', t => {
// const agent = new Agent().start({ ... })
// ...
// agent.destroy()
// t.end()
// })
var Agent = require('../lib/agent');
var symbols = require('../lib/symbols');
var Filters = require('object-filter-sequence');
var uncaughtExceptionListeners = process._events.uncaughtException;
var agent;
module.exports = setup;
function setup() {
clean();
uncaughtExceptionListeners = process._events.uncaughtException;
process.removeAllListeners('uncaughtException');
agent = new Agent();
return agent;
}
function clean() {
global[symbols.agentInitialized] = null;
process._events.uncaughtException = uncaughtExceptionListeners;
if (agent) {
agent._errorFilters = new Filters();
agent._transactionFilters = new Filters();
agent._spanFilters = new Filters();
if (agent._instrumentation) {
agent._instrumentation._started = false;
if (agent._instrumentation._ritmHook) {
agent._instrumentation._ritmHook.unhook();
}
}
agent._metrics.stop();
if (agent._apmClient && agent._apmClient.destroy) {
agent._apmClient.destroy();
}
agent._apmClient = null;
}
}