newrelic 8.3.0 → 8.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NEWS.md +76 -0
- package/README.md +7 -6
- package/THIRD_PARTY_NOTICES.md +95 -35
- package/api.js +74 -68
- package/bin/test-naming-rules.js +22 -22
- package/lib/agent.js +4 -4
- package/lib/attributes.js +2 -2
- package/lib/collector/api.js +12 -12
- package/lib/collector/facts.js +1 -1
- package/lib/collector/http-agents.js +12 -11
- package/lib/collector/key-parser.js +1 -1
- package/lib/collector/remote-method.js +27 -26
- package/lib/config/attribute-filter.js +23 -23
- package/lib/config/default.js +12 -10
- package/lib/config/hsm.js +1 -1
- package/lib/config/index.js +82 -66
- package/lib/config/lasp.js +3 -3
- package/lib/config/merge-server-config.js +1 -1
- package/lib/db/parse-sql.js +8 -8
- package/lib/db/parsed-statement.js +9 -8
- package/lib/db/query-parsers/sql.js +7 -7
- package/lib/db/query-sample.js +9 -9
- package/lib/db/query-trace-aggregator.js +4 -4
- package/lib/db/statement-matcher.js +5 -5
- package/lib/db/utils.js +1 -1
- package/lib/environment.js +43 -43
- package/lib/errors/error-collector.js +2 -2
- package/lib/errors/error-trace-aggregator.js +1 -1
- package/lib/errors/helper.js +3 -3
- package/lib/errors/index.js +17 -17
- package/lib/feature_flags.js +7 -5
- package/lib/header-attributes.js +6 -6
- package/lib/header-processing.js +1 -1
- package/lib/instrumentation/amqplib.js +26 -26
- package/lib/instrumentation/bluebird.js +3 -3
- package/lib/instrumentation/cassandra-driver.js +7 -3
- package/lib/instrumentation/connect.js +4 -4
- package/lib/instrumentation/core/async_hooks.js +6 -6
- package/lib/instrumentation/core/domain.js +2 -2
- package/lib/instrumentation/core/globals.js +1 -1
- package/lib/instrumentation/core/http-outbound.js +15 -84
- package/lib/instrumentation/core/http.js +34 -67
- package/lib/instrumentation/core/inspector.js +2 -2
- package/lib/instrumentation/core/timers.js +7 -7
- package/lib/instrumentation/core/zlib.js +2 -2
- package/lib/instrumentation/director.js +4 -4
- package/lib/instrumentation/express.js +8 -8
- package/lib/instrumentation/fastify/spec-builders.js +57 -47
- package/lib/instrumentation/fastify.js +85 -24
- package/lib/instrumentation/generic-pool.js +1 -1
- package/lib/instrumentation/hapi/hapi-17.js +11 -11
- package/lib/instrumentation/hapi/shared.js +1 -1
- package/lib/instrumentation/hapi.js +22 -22
- package/lib/instrumentation/ioredis.js +7 -7
- package/lib/instrumentation/memcached.js +7 -7
- package/lib/instrumentation/mongodb/common.js +16 -5
- package/lib/instrumentation/mysql.js +19 -19
- package/lib/instrumentation/oracle.js +15 -15
- package/lib/instrumentation/pg.js +4 -4
- package/lib/instrumentation/promise.js +46 -46
- package/lib/instrumentation/q.js +2 -2
- package/lib/instrumentation/redis.js +11 -11
- package/lib/instrumentation/restify.js +1 -1
- package/lib/instrumentation/undici.js +242 -0
- package/lib/instrumentation/vision.js +4 -4
- package/lib/instrumentation/when.js +3 -3
- package/lib/instrumentations.js +2 -1
- package/lib/logger.js +5 -5
- package/lib/metrics/index.js +15 -15
- package/lib/metrics/mapper.js +7 -7
- package/lib/metrics/normalizer/rule.js +9 -9
- package/lib/metrics/normalizer/tx_segment.js +17 -17
- package/lib/metrics/normalizer.js +22 -22
- package/lib/metrics/recorders/custom.js +5 -5
- package/lib/metrics/recorders/generic.js +3 -3
- package/lib/metrics/recorders/http.js +7 -7
- package/lib/metrics/recorders/http_external.js +7 -7
- package/lib/metrics/recorders/message-transaction.js +5 -6
- package/lib/metrics/recorders/other.js +5 -5
- package/lib/parse-proc-cpuinfo.js +25 -19
- package/lib/parse-proc-meminfo.js +8 -2
- package/lib/prioritized-attributes.js +2 -2
- package/lib/priority-queue.js +10 -10
- package/lib/reservoir.js +3 -3
- package/lib/sampler.js +26 -26
- package/lib/serverless/aws-lambda.js +8 -2
- package/lib/shim/datastore-shim.js +35 -32
- package/lib/shim/index.js +2 -2
- package/lib/shim/message-shim.js +47 -47
- package/lib/shim/promise-shim.js +1 -1
- package/lib/shim/shim.js +61 -61
- package/lib/shim/specs/index.js +3 -3
- package/lib/shim/transaction-shim.js +44 -192
- package/lib/shim/webframework-shim.js +52 -52
- package/lib/spans/span-event.js +1 -1
- package/lib/spans/streaming-span-attributes.js +1 -1
- package/lib/stats/apdex.js +2 -2
- package/lib/stats/index.js +2 -2
- package/lib/system-info.js +23 -23
- package/lib/timer.js +5 -5
- package/lib/transaction/dt-payload.js +1 -1
- package/lib/transaction/index.js +40 -40
- package/lib/transaction/name-state.js +14 -14
- package/lib/transaction/trace/exclusive-time-calculator.js +6 -6
- package/lib/transaction/trace/index.js +14 -14
- package/lib/transaction/trace/segment.js +18 -18
- package/lib/transaction/tracecontext.js +1 -1
- package/lib/transaction/tracer/index.js +53 -49
- package/lib/uninstrumented.js +7 -7
- package/lib/util/arity.js +2 -2
- package/lib/util/byte-limit.js +4 -4
- package/lib/util/cat.js +269 -24
- package/lib/util/codec.js +2 -2
- package/lib/util/copy.js +2 -2
- package/lib/util/deep-equal.js +10 -10
- package/lib/util/flatten.js +4 -4
- package/lib/util/hashes.js +14 -14
- package/lib/util/label-parser.js +17 -17
- package/lib/util/logger.js +24 -24
- package/lib/util/process-version.js +2 -2
- package/lib/util/properties.js +4 -4
- package/lib/util/sql/obfuscate.js +15 -15
- package/lib/util/stream-sink.js +3 -3
- package/lib/util/unwrapped-core.js +2 -2
- package/lib/util/urltils.js +16 -16
- package/lib/utilization/aws-info.js +7 -7
- package/lib/utilization/azure-info.js +6 -6
- package/lib/utilization/common.js +13 -13
- package/lib/utilization/docker-info.js +11 -11
- package/lib/utilization/gcp-info.js +4 -4
- package/lib/utilization/index.js +5 -5
- package/lib/utilization/pcf-info.js +9 -9
- package/package.json +13 -6
- package/stub_api.js +8 -8
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2021 New Relic Corporation. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the IncomingMessage from a Fastify request. Depending on the
|
|
10
|
+
* context of this function it either exists on `request.raw` or just `request`
|
|
11
|
+
*
|
|
12
|
+
* @param {WebFrameworkShim} shim
|
|
13
|
+
* @param {Function} fn middleware function executing
|
|
14
|
+
* @param {string} fnName name of middleware executing
|
|
15
|
+
* @param {args} args that are passed to middleware
|
|
16
|
+
* @returns {IncomingMessage}
|
|
17
|
+
*/
|
|
18
|
+
const getRequestFromFastify = (shim, fn, fnName, args) => {
|
|
19
|
+
const [request] = args
|
|
20
|
+
|
|
21
|
+
// request is Fastify request
|
|
22
|
+
// object, get IncomingMessage from .raw
|
|
10
23
|
if (request && request.raw) {
|
|
11
24
|
return request.raw
|
|
12
25
|
}
|
|
26
|
+
|
|
27
|
+
return request
|
|
13
28
|
}
|
|
14
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the params from the Fastify request.
|
|
32
|
+
*
|
|
33
|
+
* @param {WebFrameworkShim} shim
|
|
34
|
+
* @param {Function} fn middleware function executing
|
|
35
|
+
* @param {string} fnName name of middleware executing
|
|
36
|
+
* @param {args} args that are passed to middleware
|
|
37
|
+
* @returns {object} URL params on a Fastify request
|
|
38
|
+
*/
|
|
15
39
|
const getParamsFromFastifyRequest = (shim, fn, fnName, args) => {
|
|
16
|
-
const req = args
|
|
40
|
+
const [req] = args
|
|
17
41
|
return req && req.params
|
|
18
42
|
}
|
|
19
43
|
|
|
@@ -21,32 +45,17 @@ const getParamsFromFastifyRequest = (shim, fn, fnName, args) => {
|
|
|
21
45
|
* Builds the recordMiddleware Spec for the route handler
|
|
22
46
|
*
|
|
23
47
|
* A spec is basically a specification -- or a list
|
|
24
|
-
* of
|
|
48
|
+
* of instructions to the recordMiddleware function
|
|
25
49
|
* that provide it with the information it needs to
|
|
26
50
|
* do its job. You could also think of it as a
|
|
27
51
|
* mini-DSL
|
|
52
|
+
*
|
|
53
|
+
* @param {WebFrameworkShim} shim
|
|
54
|
+
* @param {string} path URL route being executed
|
|
55
|
+
* @returns {object} spec for Fastify route handler
|
|
28
56
|
*/
|
|
29
57
|
function buildMiddlewareSpecForRouteHandler(shim, path) {
|
|
30
58
|
return {
|
|
31
|
-
/**
|
|
32
|
-
* The path to use for transaction naming
|
|
33
|
-
*/
|
|
34
|
-
route: path,
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* A function the returns the NodeJS Request Object
|
|
38
|
-
*
|
|
39
|
-
* The job of the `req` callback is to return the current NodeJS
|
|
40
|
-
* IncomingMessage object for this particular handler. Most NodeJS
|
|
41
|
-
* frameworks will pass the request to each handler -- sometimes (as
|
|
42
|
-
* is the case here) wrapped by another object.
|
|
43
|
-
*
|
|
44
|
-
* @param {any} shim the Webframework Shim
|
|
45
|
-
* @param {any} fn the handler function passed to buildMiddlewareSpec
|
|
46
|
-
* @param {any} fnName the handler function's name
|
|
47
|
-
* @param {any} args the arguments passed to the handler function
|
|
48
|
-
*/
|
|
49
|
-
req: getRawRequestFromFastifyRequest,
|
|
50
59
|
/**
|
|
51
60
|
* A function where we can wrap next, reply send, etc. methods
|
|
52
61
|
*
|
|
@@ -66,6 +75,12 @@ function buildMiddlewareSpecForRouteHandler(shim, path) {
|
|
|
66
75
|
* The isFinal param determines whether or not a path is appended for
|
|
67
76
|
* this particular piece of middleware. (i.e. if this is the final handler
|
|
68
77
|
* that is actually handling the request, the path is actually left on)
|
|
78
|
+
*
|
|
79
|
+
* @param shim
|
|
80
|
+
* @param fn
|
|
81
|
+
* @param fnName
|
|
82
|
+
* @param args
|
|
83
|
+
* @param bindSegment
|
|
69
84
|
*/
|
|
70
85
|
next: function wrapNext(shim, fn, fnName, args, bindSegment) {
|
|
71
86
|
const reply = args[1]
|
|
@@ -75,33 +90,28 @@ function buildMiddlewareSpecForRouteHandler(shim, path) {
|
|
|
75
90
|
const isFinal = true
|
|
76
91
|
bindSegment(reply, 'send', isFinal)
|
|
77
92
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* @param {any} shim the Webframework Shim
|
|
83
|
-
* @param {any} fn the handler function passed to buildMiddlewareSpec
|
|
84
|
-
* @param {any} fnName the handler function's name
|
|
85
|
-
* @param {any} args the arguments passed to the handler function
|
|
86
|
-
*/
|
|
87
|
-
params: getParamsFromFastifyRequest
|
|
93
|
+
params: getParamsFromFastifyRequest,
|
|
94
|
+
req: getRequestFromFastify,
|
|
95
|
+
route: path
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
|
|
91
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Spec for all Fastify middleware(excluding route handlers)
|
|
101
|
+
*
|
|
102
|
+
* @param {WebFrameworkShim} shim
|
|
103
|
+
* @param {string} name metric name for middleware being executed
|
|
104
|
+
* @param route
|
|
105
|
+
* @returns {object} spec for Fastify middleware
|
|
106
|
+
*/
|
|
107
|
+
function buildMiddlewareSpecForMiddlewareFunction(shim, name, route) {
|
|
92
108
|
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
next:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
const isFinal = false
|
|
101
|
-
bindSegment(next, null, isFinal)
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
params: getParamsFromFastifyRequest
|
|
109
|
+
name,
|
|
110
|
+
route,
|
|
111
|
+
next: shim.LAST,
|
|
112
|
+
params: getParamsFromFastifyRequest,
|
|
113
|
+
req: getRequestFromFastify,
|
|
114
|
+
type: shim.MIDDLEWARE
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -4,11 +4,33 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
|
+
|
|
7
8
|
const semver = require('semver')
|
|
8
9
|
const {
|
|
9
10
|
buildMiddlewareSpecForRouteHandler,
|
|
10
11
|
buildMiddlewareSpecForMiddlewareFunction
|
|
11
12
|
} = require('./fastify/spec-builders')
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* These are the events that occur during a fastify
|
|
16
|
+
* request
|
|
17
|
+
* see: https://www.fastify.io/docs/latest/Lifecycle/
|
|
18
|
+
*
|
|
19
|
+
* Note: preSerialization and onSend happen after the route handler
|
|
20
|
+
* executes. `onResponse` does not execute until after the client
|
|
21
|
+
* sends the response so it'll never be in scope of the transaction
|
|
22
|
+
*/
|
|
23
|
+
const REQUEST_HOOKS = [
|
|
24
|
+
'onRequest',
|
|
25
|
+
'preParsing',
|
|
26
|
+
'preValidation',
|
|
27
|
+
'preHandler',
|
|
28
|
+
'preSerialization',
|
|
29
|
+
'onSend',
|
|
30
|
+
'onResponse',
|
|
31
|
+
'onError'
|
|
32
|
+
]
|
|
33
|
+
|
|
12
34
|
/**
|
|
13
35
|
* Sets up fastify route handler
|
|
14
36
|
*
|
|
@@ -20,6 +42,9 @@ const {
|
|
|
20
42
|
* those private implementations from access, and getting
|
|
21
43
|
* at them would require a lot of gymnastics and hard to
|
|
22
44
|
* maintain code
|
|
45
|
+
*
|
|
46
|
+
* @param shim
|
|
47
|
+
* @param fastify
|
|
23
48
|
*/
|
|
24
49
|
const setupRouteHandler = (shim, fastify) => {
|
|
25
50
|
fastify.addHook('onRoute', (routeOptions) => {
|
|
@@ -27,10 +52,10 @@ const setupRouteHandler = (shim, fastify) => {
|
|
|
27
52
|
return
|
|
28
53
|
}
|
|
29
54
|
/**
|
|
30
|
-
*
|
|
55
|
+
* recordMiddleware handler call
|
|
31
56
|
*
|
|
32
57
|
* The WebFramework shim treats the main route handler like any other
|
|
33
|
-
* i.e. dont be confused by the call to
|
|
58
|
+
* i.e. dont be confused by the call to recordMiddleware -- we don't
|
|
34
59
|
* have a recordRouteHandler, everything goes through recordMiddleware
|
|
35
60
|
*/
|
|
36
61
|
const newRouteHandler = shim.recordMiddleware(
|
|
@@ -40,29 +65,25 @@ const setupRouteHandler = (shim, fastify) => {
|
|
|
40
65
|
|
|
41
66
|
routeOptions.handler = newRouteHandler
|
|
42
67
|
})
|
|
43
|
-
}
|
|
44
68
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return function wrappedFastifyUser() {
|
|
69
|
+
shim.wrap(fastify, 'addHook', function addWrapHook(shim, fn) {
|
|
70
|
+
return function wrappedAddHook() {
|
|
48
71
|
const args = shim.argsToArray.apply(shim, arguments)
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
middlewareFunction
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
args[0] = newMiddlewareFunction
|
|
72
|
+
const hookName = args[0]
|
|
73
|
+
if (REQUEST_HOOKS.includes(hookName)) {
|
|
74
|
+
const middlewareFunction = args[1]
|
|
75
|
+
const name = `${hookName}/${shim.getName(middlewareFunction)}`
|
|
76
|
+
const middlewareSpec = buildMiddlewareSpecForMiddlewareFunction(shim, name)
|
|
77
|
+
const newMiddlewareFunction = shim.recordMiddleware(middlewareFunction, middlewareSpec)
|
|
56
78
|
|
|
79
|
+
args[1] = newMiddlewareFunction
|
|
80
|
+
}
|
|
57
81
|
return fn.apply(this, args)
|
|
58
82
|
}
|
|
59
83
|
})
|
|
60
84
|
}
|
|
61
85
|
|
|
62
86
|
module.exports = function initialize(agent, fastify, moduleName, shim) {
|
|
63
|
-
if (!agent.config.feature_flag.fastify_instrumentation) {
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
87
|
shim.setFramework(shim.FASTIFY)
|
|
67
88
|
|
|
68
89
|
const fastifyVersion = shim.require('./package.json').version
|
|
@@ -73,18 +94,12 @@ module.exports = function initialize(agent, fastify, moduleName, shim) {
|
|
|
73
94
|
*/
|
|
74
95
|
const wrappedExport = shim.wrapExport(fastify, function wrapFastifyModule(shim, fn) {
|
|
75
96
|
return function wrappedFastifyModule() {
|
|
76
|
-
// normalize arguments
|
|
77
|
-
const args = shim.argsToArray.apply(shim, arguments)
|
|
78
|
-
|
|
79
97
|
// call original function get get fastify object (which is singleton-ish)
|
|
80
|
-
const fastifyForWrapping = fn.apply(this,
|
|
98
|
+
const fastifyForWrapping = fn.apply(this, arguments)
|
|
81
99
|
|
|
82
100
|
setupRouteHandler(shim, fastifyForWrapping)
|
|
83
101
|
|
|
84
|
-
|
|
85
|
-
if (!isv3Plus) {
|
|
86
|
-
setupMiddlewareHandlers(shim, fastifyForWrapping)
|
|
87
|
-
}
|
|
102
|
+
setupMiddlewareHandlers(shim, fastifyForWrapping, isv3Plus)
|
|
88
103
|
|
|
89
104
|
return fastifyForWrapping
|
|
90
105
|
}
|
|
@@ -95,10 +110,56 @@ module.exports = function initialize(agent, fastify, moduleName, shim) {
|
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
|
|
113
|
+
function setupMiddlewareHandlers(shim, fastify, isv3Plus) {
|
|
114
|
+
const mounterSpec = {
|
|
115
|
+
route: shim.FIRST,
|
|
116
|
+
wrapper: wrapMiddleware
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (isv3Plus) {
|
|
120
|
+
// Fastify v3+ does not ship with traditional Node.js middleware mounting.
|
|
121
|
+
// This style is accomplished leveraging decorators. Both middie (which was built-in in v2)
|
|
122
|
+
// and fastify-express mount a 'use' function for mounting middleware.
|
|
123
|
+
shim.wrap(fastify, 'decorate', function wrapDecorate(shim, fn) {
|
|
124
|
+
return function wrappedDecorate() {
|
|
125
|
+
const name = arguments[0]
|
|
126
|
+
if (name !== 'use') {
|
|
127
|
+
return fn.apply(this, arguments)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
131
|
+
args[1] = shim.wrapMiddlewareMounter(args[1], mounterSpec)
|
|
132
|
+
|
|
133
|
+
return fn.apply(this, args)
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
} else {
|
|
137
|
+
shim.wrapMiddlewareMounter(fastify, 'use', mounterSpec)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function wrapMiddleware(shim, middleware, name, route) {
|
|
142
|
+
if (shim.isWrapped(middleware)) {
|
|
143
|
+
return middleware
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// prefixing the segment name for middleware execution
|
|
147
|
+
// with the Fastify lifecycle hook
|
|
148
|
+
const segmentName = `onRequest/${name}`
|
|
149
|
+
const spec = buildMiddlewareSpecForMiddlewareFunction(shim, segmentName, route)
|
|
150
|
+
|
|
151
|
+
const newMiddlewareFunction = shim.recordMiddleware(middleware, spec)
|
|
152
|
+
|
|
153
|
+
return newMiddlewareFunction
|
|
154
|
+
}
|
|
155
|
+
|
|
98
156
|
/**
|
|
99
157
|
* module.exports = fastify
|
|
100
158
|
* module.exports.fastify = fastify
|
|
101
159
|
* module.exports.default = fastify
|
|
160
|
+
*
|
|
161
|
+
* @param original
|
|
162
|
+
* @param wrappedExport
|
|
102
163
|
*/
|
|
103
164
|
function setupExports(original, wrappedExport) {
|
|
104
165
|
wrappedExport.fastify = original.fastify
|
|
@@ -10,7 +10,7 @@ module.exports = function initialize(agent, generic, moduleName, shim) {
|
|
|
10
10
|
return false
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const proto = generic.Pool.prototype
|
|
14
14
|
shim.wrap(proto, 'acquire', function wrapAcquire(shim, acquire) {
|
|
15
15
|
if (!shim.isFunction(acquire)) {
|
|
16
16
|
return acquire
|
|
@@ -28,7 +28,7 @@ function serverFactoryWrapper(shim, fn, fnName, server) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function serverPostConstructor(shim) {
|
|
31
|
-
|
|
31
|
+
const proto = Object.getPrototypeOf(this)
|
|
32
32
|
|
|
33
33
|
if (shim.isWrapped(proto.decorate)) {
|
|
34
34
|
shim.logger.trace('Already wrapped Server proto, not wrapping again')
|
|
@@ -44,7 +44,7 @@ function serverPostConstructor(shim) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// Convert arguments to usable array
|
|
47
|
-
|
|
47
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
48
48
|
|
|
49
49
|
// Wrap the third server.decorate arg, the user-defined handler
|
|
50
50
|
shim.wrap(args, shim.THIRD, function wrapHandler(shim, fn) {
|
|
@@ -59,7 +59,7 @@ function serverPostConstructor(shim) {
|
|
|
59
59
|
return wrappedHandler
|
|
60
60
|
|
|
61
61
|
function wrappedHandler(route) {
|
|
62
|
-
|
|
62
|
+
const ret = fn.apply(this, arguments)
|
|
63
63
|
|
|
64
64
|
return typeof ret === 'function' ? wrapRouteHandler(shim, ret, route && route.path) : ret
|
|
65
65
|
}
|
|
@@ -71,7 +71,7 @@ function serverPostConstructor(shim) {
|
|
|
71
71
|
|
|
72
72
|
shim.wrap(proto, 'route', function wrapRoute(shim, original) {
|
|
73
73
|
return function wrappedRoute() {
|
|
74
|
-
|
|
74
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
75
75
|
|
|
76
76
|
if (!shim.isObject(args[0])) {
|
|
77
77
|
return original.apply(this, args)
|
|
@@ -92,7 +92,7 @@ function serverPostConstructor(shim) {
|
|
|
92
92
|
function _wrapRoute(shim, route) {
|
|
93
93
|
const routePath = prefix + route.path
|
|
94
94
|
if (shim.isArray(route)) {
|
|
95
|
-
for (
|
|
95
|
+
for (let i = 0; i < route.length; ++i) {
|
|
96
96
|
_wrapRoute(shim, route[i])
|
|
97
97
|
}
|
|
98
98
|
return
|
|
@@ -132,10 +132,10 @@ function serverPostConstructor(shim) {
|
|
|
132
132
|
|
|
133
133
|
shim.wrap(proto, 'ext', function wrapExt(shim, original) {
|
|
134
134
|
return function wrappedExt(event, method) {
|
|
135
|
-
|
|
135
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
136
136
|
|
|
137
137
|
if (shim.isArray(event)) {
|
|
138
|
-
for (
|
|
138
|
+
for (let i = 0; i < event.length; i++) {
|
|
139
139
|
event[i].method = wrapMiddleware(shim, event[i].method, event[i].type)
|
|
140
140
|
}
|
|
141
141
|
} else if (shim.isObject(event)) {
|
|
@@ -154,7 +154,7 @@ function serverPostConstructor(shim) {
|
|
|
154
154
|
|
|
155
155
|
function wrapPreHandlers(shim, container, path) {
|
|
156
156
|
if (shim.isArray(container)) {
|
|
157
|
-
for (
|
|
157
|
+
for (let i = 0; i < container.length; ++i) {
|
|
158
158
|
container[i] = wrapPreHandlers(shim, container[i], path)
|
|
159
159
|
}
|
|
160
160
|
return container
|
|
@@ -177,14 +177,14 @@ function wrapRouteHandler(shim, handler, path) {
|
|
|
177
177
|
return shim.recordMiddleware(handler, {
|
|
178
178
|
route: path,
|
|
179
179
|
req: function getReq(shim, fn, fnName, args) {
|
|
180
|
-
|
|
180
|
+
const request = args[0]
|
|
181
181
|
if (request && request.raw) {
|
|
182
182
|
return request.raw.req
|
|
183
183
|
}
|
|
184
184
|
},
|
|
185
185
|
promise: true,
|
|
186
186
|
params: function getParams(shim, fn, fnName, args) {
|
|
187
|
-
|
|
187
|
+
const req = args[0]
|
|
188
188
|
return req && req.params
|
|
189
189
|
}
|
|
190
190
|
})
|
|
@@ -200,7 +200,7 @@ function wrapMiddleware(shim, middleware, event) {
|
|
|
200
200
|
type: event === 'onPreResponse' ? shim.ERRORWARE : shim.MIDDLEWARE,
|
|
201
201
|
promise: true,
|
|
202
202
|
req: function getReq(shim, fn, fnName, args) {
|
|
203
|
-
|
|
203
|
+
const req = args[0]
|
|
204
204
|
return req && req.raw && req.raw.req
|
|
205
205
|
}
|
|
206
206
|
})
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const shared = require('./hapi/shared')
|
|
9
9
|
|
|
10
10
|
module.exports = function initialize(agent, hapi, moduleName, shim) {
|
|
11
11
|
if (!agent || !hapi || !shim) {
|
|
@@ -32,7 +32,7 @@ module.exports = function initialize(agent, hapi, moduleName, shim) {
|
|
|
32
32
|
|
|
33
33
|
// See if we can find the plugin class. This should be the super class of
|
|
34
34
|
// Server and will cover more scenarios.
|
|
35
|
-
|
|
35
|
+
const Plugin = hapi.Server.super_
|
|
36
36
|
if (_isPluginClass(Plugin)) {
|
|
37
37
|
wrapServer(shim, Plugin)
|
|
38
38
|
} else {
|
|
@@ -46,9 +46,9 @@ function wrapServer(shim, Server) {
|
|
|
46
46
|
// the second argument is expected to be a function that generates the handler function
|
|
47
47
|
shim.wrap(Server.prototype, 'handler', function wrapHandler(shim, original) {
|
|
48
48
|
return function wrappedHandler() {
|
|
49
|
-
|
|
49
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
const handlerGenerator = args[1]
|
|
52
52
|
if (typeof handlerGenerator === 'function') {
|
|
53
53
|
args[1] = wrapGenerator(handlerGenerator)
|
|
54
54
|
}
|
|
@@ -57,10 +57,10 @@ function wrapServer(shim, Server) {
|
|
|
57
57
|
|
|
58
58
|
function wrapGenerator(generator) {
|
|
59
59
|
function wrappedGenerator() {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const generatorArgs = shim.argsToArray.apply(shim, arguments)
|
|
61
|
+
const handler = generator.apply(this, generatorArgs)
|
|
62
62
|
if (typeof handler === 'function') {
|
|
63
|
-
|
|
63
|
+
const route = generatorArgs[0]
|
|
64
64
|
return wrapRouteHandler(shim, handler, route && route.path)
|
|
65
65
|
}
|
|
66
66
|
return handler
|
|
@@ -75,7 +75,7 @@ function wrapServer(shim, Server) {
|
|
|
75
75
|
|
|
76
76
|
shim.wrap(Server.prototype, 'route', function wrapRoute(shim, original) {
|
|
77
77
|
return function wrappedRoute() {
|
|
78
|
-
|
|
78
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
79
79
|
|
|
80
80
|
// first argument is expected to be the route configuration object
|
|
81
81
|
if (!shim.isObject(args[0])) {
|
|
@@ -98,7 +98,7 @@ function wrapServer(shim, Server) {
|
|
|
98
98
|
const routePath = prefix + route.path
|
|
99
99
|
// handler function could be on the route object, or on a nested config object
|
|
100
100
|
if (shim.isArray(route)) {
|
|
101
|
-
for (
|
|
101
|
+
for (let i = 0; i < route.length; ++i) {
|
|
102
102
|
_wrapRoute(shim, route[i])
|
|
103
103
|
}
|
|
104
104
|
return
|
|
@@ -119,10 +119,10 @@ function wrapServer(shim, Server) {
|
|
|
119
119
|
|
|
120
120
|
shim.wrap(Server.prototype, 'ext', function wrapExt(shim, original) {
|
|
121
121
|
return function wrappedExt(event, method) {
|
|
122
|
-
|
|
122
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
123
123
|
|
|
124
124
|
if (shim.isArray(event)) {
|
|
125
|
-
for (
|
|
125
|
+
for (let i = 0; i < event.length; i++) {
|
|
126
126
|
event[i].method = wrapMiddleware(shim, event[i].method, event[i].type)
|
|
127
127
|
}
|
|
128
128
|
} else if (shim.isObject(event)) {
|
|
@@ -142,7 +142,7 @@ function wrapServer(shim, Server) {
|
|
|
142
142
|
function wrapCreateServer(shim, hapi) {
|
|
143
143
|
shim.wrap(hapi, 'createServer', function getWrapper(shim, createServer) {
|
|
144
144
|
return function createServerWrapper() {
|
|
145
|
-
|
|
145
|
+
const server = createServer.apply(this, arguments)
|
|
146
146
|
wrapServer(shim, server.constructor)
|
|
147
147
|
shim.unwrap(hapi, 'createServer')
|
|
148
148
|
return server
|
|
@@ -152,7 +152,7 @@ function wrapCreateServer(shim, hapi) {
|
|
|
152
152
|
|
|
153
153
|
function wrapPreHandlers(shim, container, path) {
|
|
154
154
|
if (shim.isArray(container)) {
|
|
155
|
-
for (
|
|
155
|
+
for (let i = 0; i < container.length; ++i) {
|
|
156
156
|
container[i] = wrapPreHandlers(shim, container[i], path)
|
|
157
157
|
}
|
|
158
158
|
return container
|
|
@@ -194,20 +194,20 @@ function buildMiddlewareSpec(shim, path, isPreHandler) {
|
|
|
194
194
|
return {
|
|
195
195
|
route: path,
|
|
196
196
|
req: function getReq(shim, fn, fnName, args) {
|
|
197
|
-
|
|
197
|
+
const request = args[0]
|
|
198
198
|
if (request && request.raw) {
|
|
199
199
|
return request.raw.req
|
|
200
200
|
}
|
|
201
201
|
},
|
|
202
202
|
next: function wrapNext(shim, fn, fnName, args, wrap) {
|
|
203
|
-
|
|
203
|
+
const reply = args[1]
|
|
204
204
|
if (!shim.isFunction(reply)) {
|
|
205
205
|
return
|
|
206
206
|
}
|
|
207
207
|
wrapReply(wrap, reply, isPreHandler)
|
|
208
208
|
},
|
|
209
209
|
params: function getParams(shim, fn, fnName, args) {
|
|
210
|
-
|
|
210
|
+
const req = args[0]
|
|
211
211
|
return req && req.params
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -216,7 +216,7 @@ function buildMiddlewareSpec(shim, path, isPreHandler) {
|
|
|
216
216
|
function wrapHapiHandler(shim, handler) {
|
|
217
217
|
return shim.wrap(handler, function wrapHandler(shim, original) {
|
|
218
218
|
return function wrapped() {
|
|
219
|
-
|
|
219
|
+
const reply = arguments[1]
|
|
220
220
|
if (reply) {
|
|
221
221
|
shim.recordRender(reply, 'view')
|
|
222
222
|
}
|
|
@@ -230,18 +230,18 @@ function wrapMiddleware(shim, middleware, event) {
|
|
|
230
230
|
return middleware
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
|
|
233
|
+
const spec = {
|
|
234
234
|
route: event,
|
|
235
235
|
type: event === 'onPreResponse' ? shim.ERRORWARE : shim.MIDDLEWARE,
|
|
236
236
|
next: function wrapNext(shim, fn, fnName, args, wrap) {
|
|
237
|
-
|
|
237
|
+
const reply = args[1]
|
|
238
238
|
if (!reply || !shim.isFunction(reply.continue)) {
|
|
239
239
|
return
|
|
240
240
|
}
|
|
241
241
|
wrap(reply, 'continue')
|
|
242
242
|
},
|
|
243
243
|
req: function getReq(shim, fn, fnName, args) {
|
|
244
|
-
|
|
244
|
+
const request = args[0]
|
|
245
245
|
if (request && request.raw) {
|
|
246
246
|
return request.raw.req
|
|
247
247
|
}
|
|
@@ -256,7 +256,7 @@ function _isPluginClass(Plugin) {
|
|
|
256
256
|
return false
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
const proto = Plugin.prototype
|
|
260
260
|
return (
|
|
261
261
|
typeof proto.handler === 'function' &&
|
|
262
262
|
typeof proto.route === 'function' &&
|
|
@@ -265,7 +265,7 @@ function _isPluginClass(Plugin) {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
function wrapReply(wrap, reply, isPreHandler) {
|
|
268
|
-
|
|
268
|
+
const isFinal = !isPreHandler
|
|
269
269
|
// The only reply method that is actually used by pre-handlers is `response`. All
|
|
270
270
|
// other methods still exist, but don't function as they do in normal route handlers.
|
|
271
271
|
// Since they can still be referenced by users, they still need to be wrapped.
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const stringify = require('json-stringify-safe')
|
|
9
|
+
const urltils = require('../util/urltils.js')
|
|
10
10
|
|
|
11
11
|
module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
12
|
-
|
|
12
|
+
const proto = redis && redis.prototype
|
|
13
13
|
if (!proto) {
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
@@ -18,17 +18,17 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
18
18
|
shim.recordOperation(proto, 'sendCommand', wrapSendCommand)
|
|
19
19
|
|
|
20
20
|
function wrapSendCommand(shim, original, name, args) {
|
|
21
|
-
|
|
21
|
+
const command = args[0]
|
|
22
22
|
|
|
23
23
|
// TODO: Instance attributes for ioredis
|
|
24
|
-
|
|
24
|
+
const parameters = {
|
|
25
25
|
host: this.connector.options.host,
|
|
26
26
|
port_path_or_id: this.connector.options.port
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const keys = command.args
|
|
30
30
|
if (keys && typeof keys !== 'function') {
|
|
31
|
-
|
|
31
|
+
const src = Object.create(null)
|
|
32
32
|
try {
|
|
33
33
|
src.key = stringify(keys[0])
|
|
34
34
|
} catch (err) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const stringify = require('json-stringify-safe')
|
|
9
9
|
|
|
10
10
|
function wrapKeys(metacall) {
|
|
11
11
|
if (metacall.key) {
|
|
@@ -23,7 +23,7 @@ function wrapKeys(metacall) {
|
|
|
23
23
|
* instrument the memcached driver to intercept calls and keep stats on them.
|
|
24
24
|
*/
|
|
25
25
|
module.exports = function initialize(agent, memcached, moduleName, shim) {
|
|
26
|
-
|
|
26
|
+
const proto = memcached && memcached.prototype
|
|
27
27
|
if (!proto) {
|
|
28
28
|
return false
|
|
29
29
|
}
|
|
@@ -34,10 +34,10 @@ module.exports = function initialize(agent, memcached, moduleName, shim) {
|
|
|
34
34
|
// address. The query generator returns a simple object describing the
|
|
35
35
|
// memcached call. The server parameter is only provided for multi-calls.
|
|
36
36
|
// When not provided, it can be derived from the key being interacted with.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const metacall = args[0]()
|
|
38
|
+
const server = args[1]
|
|
39
|
+
const keys = wrapKeys(metacall)
|
|
40
|
+
const parameters = Object.create(null)
|
|
41
41
|
try {
|
|
42
42
|
parameters.key = stringify(keys[0])
|
|
43
43
|
} catch (err) {
|
|
@@ -46,7 +46,7 @@ module.exports = function initialize(agent, memcached, moduleName, shim) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Capture connection info for datastore instance metric.
|
|
49
|
-
|
|
49
|
+
let location = null
|
|
50
50
|
if (typeof server === 'string') {
|
|
51
51
|
location = server
|
|
52
52
|
} else if (this.HashRing && this.HashRing.get && metacall.key) {
|