_agent.js
1.73 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
'use strict'
var Instrumentation = require('../../lib/instrumentation')
var logger = require('../../lib/logger')
logger.init({ level: 'fatal' })
var noop = function () {}
var sharedInstrumentation
module.exports = function mockAgent (cb) {
var agent = {
active: true,
instrument: true,
timeout: {
active: false,
errorResult: 42,
errorThreshold: 250
},
_httpClient: {
request: cb || noop
},
_ignoreUrlStr: [],
_ignoreUrlRegExp: [],
_ignoreUserAgentStr: [],
_ignoreUserAgentRegExp: [],
_platform: {}
}
// We do not want to start the instrumenation multiple times during testing.
// This would result in core functions being patched multiple times
if (!sharedInstrumentation) {
sharedInstrumentation = new Instrumentation(agent)
agent._instrumentation = sharedInstrumentation
agent.startTransaction = sharedInstrumentation.startTransaction.bind(sharedInstrumentation)
agent.endTransaction = sharedInstrumentation.endTransaction.bind(sharedInstrumentation)
agent.setTransactionName = sharedInstrumentation.setTransactionName.bind(sharedInstrumentation)
agent.buildTrace = sharedInstrumentation.buildTrace.bind(sharedInstrumentation)
agent._instrumentation.start()
} else {
sharedInstrumentation._agent = agent
agent._instrumentation = sharedInstrumentation
agent.startTransaction = sharedInstrumentation.startTransaction.bind(sharedInstrumentation)
agent.endTransaction = sharedInstrumentation.endTransaction.bind(sharedInstrumentation)
agent.setTransactionName = sharedInstrumentation.setTransactionName.bind(sharedInstrumentation)
agent.buildTrace = sharedInstrumentation.buildTrace.bind(sharedInstrumentation)
}
return agent
}