MCPcopy Index your code
hub / github.com/RisingStack/trace-nodejs / wrapQuery

Function wrapQuery

lib/instrumentations/utils/wrapQuery.js:7–71  ·  view source on GitHub ↗
(original, args, agent, params)

Source from the content-addressed store, hash-verified

5var format = require('util').format
6
7function wrapQuery (original, args, agent, params) {
8 var _params = params || {}
9 var collector = agent.tracer.collector
10 var externalEdgeMetrics = agent.externalEdgeMetrics
11 var continuationMethod = _params.continuationMethod // promise || readStream || callback
12
13 var reporter = {
14 reportSend: function () {
15 var action = _params.method == null ? 'unknown' : _params.method
16 var resource = _params.url == null ? 'unknown' : _params.url
17
18 var cs = agent.tracer.collector.clientSend({
19 protocol: _params.protocol,
20 action: _params.method,
21 resource: _params.url,
22 host: _params.host,
23 data: _params.protocolSpecific,
24 severity: _params.severity
25 })
26
27 debug.info('wrapQuery', format('CS(%s) [%s %s %s %s]',
28 cs.event.p, _params.protocol,
29 action, resource, _params.host))
30
31 return cs
32 },
33
34 reportReceive: function (err, cs) {
35 var severity = err
36 ? collector.mustCollectSeverity
37 : collector.defaultSeverity
38
39 var status = err ? 'bad' : 'ok'
40
41 debug.info('wrapQuery', format('CR(%s) [%s %s] [severity: %s]',
42 cs.event.p, _params.protocol, status, severity))
43
44 collector.clientRecv({
45 protocol: _params.protocol,
46 status: err ? 'bad' : 'ok'
47 }, {
48 severity: severity
49 }, cs.briefcase)
50
51 externalEdgeMetrics.report({
52 targetHost: _params.host,
53 protocol: _params.protocol,
54 status: err
55 ? externalEdgeMetrics.EDGE_STATUS.NOT_OK
56 : externalEdgeMetrics.EDGE_STATUS.OK,
57 responseTime: microtime.now() - cs.duffelBag.timestamp
58 })
59 }
60 }
61
62 if (continuationMethod === 'promise') {
63 return wrapPromise.call(this, original, args, reporter)
64 } else if (continuationMethod === 'eventEmitter') {

Callers 1

wrapQuery.spec.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected