newrelic 7.5.2 → 8.3.0
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 +4989 -4886
- package/THIRD_PARTY_NOTICES.md +625 -216
- package/api.js +105 -174
- package/bin/test-naming-rules.js +38 -32
- package/bin/tracetractor +0 -1
- package/index.js +12 -18
- package/lib/agent.js +108 -111
- package/lib/aggregators/base-aggregator.js +1 -1
- package/lib/aggregators/event-aggregator.js +6 -6
- package/lib/attributes.js +12 -13
- package/lib/collector/api.js +32 -42
- package/lib/collector/facts.js +67 -65
- package/lib/collector/http-agents.js +30 -27
- package/lib/collector/parse-response.js +1 -2
- package/lib/collector/remote-method.js +43 -36
- package/lib/collector/serverless.js +13 -18
- package/lib/collector/ssl/certificates.js +1056 -1056
- package/lib/config/attribute-filter.js +90 -82
- package/lib/config/default.js +30 -18
- package/lib/config/env.js +17 -12
- package/lib/config/harvest-config-validator.js +1 -1
- package/lib/config/index.js +160 -177
- package/lib/config/merge-server-config.js +7 -5
- package/lib/custom-events/custom-event-aggregator.js +1 -1
- package/lib/db/parse-sql.js +6 -9
- package/lib/db/parsed-statement.js +6 -13
- package/lib/db/query-parsers/sql.js +6 -9
- package/lib/db/query-sample.js +7 -3
- package/lib/db/query-trace-aggregator.js +12 -12
- package/lib/db/utils.js +1 -1
- package/lib/environment.js +173 -138
- package/lib/errors/error-collector.js +18 -31
- package/lib/errors/error-event-aggregator.js +1 -1
- package/lib/errors/error-trace-aggregator.js +2 -3
- package/lib/errors/helper.js +21 -30
- package/lib/errors/index.js +16 -28
- package/lib/feature_flags.js +5 -8
- package/lib/grpc/connection/states.js +6 -6
- package/lib/grpc/connection.js +35 -46
- package/lib/header-attributes.js +49 -53
- package/lib/instrumentation/amqplib.js +8 -17
- package/lib/instrumentation/bluebird.js +61 -20
- package/lib/instrumentation/cassandra-driver.js +2 -2
- package/lib/instrumentation/connect.js +4 -3
- package/lib/instrumentation/core/async_hooks.js +11 -4
- package/lib/instrumentation/core/child_process.js +20 -28
- package/lib/instrumentation/core/crypto.js +1 -7
- package/lib/instrumentation/core/dns.js +3 -7
- package/lib/instrumentation/core/domain.js +2 -8
- package/lib/instrumentation/core/fs.js +22 -37
- package/lib/instrumentation/core/globals.js +3 -7
- package/lib/instrumentation/core/http-outbound.js +15 -40
- package/lib/instrumentation/core/http.js +29 -63
- package/lib/instrumentation/core/inspector.js +6 -10
- package/lib/instrumentation/core/net.js +3 -1
- package/lib/instrumentation/core/timers.js +17 -24
- package/lib/instrumentation/core/zlib.js +2 -10
- package/lib/instrumentation/express.js +4 -2
- package/lib/instrumentation/fastify/spec-builders.js +5 -0
- package/lib/instrumentation/fastify.js +37 -10
- package/lib/instrumentation/hapi/hapi-17.js +9 -10
- package/lib/instrumentation/hapi.js +15 -15
- package/lib/instrumentation/ioredis.js +1 -2
- package/lib/instrumentation/memcached.js +39 -43
- package/lib/instrumentation/mongodb/common.js +218 -0
- package/lib/instrumentation/mongodb/constants.js +87 -0
- package/lib/instrumentation/mongodb/v2-mongo.js +110 -0
- package/lib/instrumentation/mongodb/v3-mongo.js +80 -0
- package/lib/instrumentation/mongodb/v4-mongo.js +90 -0
- package/lib/instrumentation/mongodb.js +20 -312
- package/lib/instrumentation/mysql.js +33 -26
- package/lib/instrumentation/oracle.js +10 -14
- package/lib/instrumentation/pg.js +30 -21
- package/lib/instrumentation/promise.js +20 -17
- package/lib/instrumentation/redis.js +30 -30
- package/lib/instrumentation/when.js +9 -1
- package/lib/instrumentations.js +24 -24
- package/lib/logger.js +1 -1
- package/lib/metrics/index.js +37 -17
- package/lib/metrics/mapper.js +9 -9
- package/lib/metrics/metric-aggregator.js +5 -10
- package/lib/metrics/names.js +8 -7
- package/lib/metrics/normalizer/rule.js +6 -7
- package/lib/metrics/normalizer/tx_segment.js +17 -13
- package/lib/metrics/normalizer.js +30 -33
- package/lib/metrics/recorders/custom.js +3 -1
- package/lib/metrics/recorders/distributed-trace.js +3 -18
- package/lib/metrics/recorders/generic.js +3 -2
- package/lib/metrics/recorders/http.js +4 -6
- package/lib/metrics/recorders/http_external.js +1 -3
- package/lib/metrics/recorders/message-transaction.js +2 -12
- package/lib/metrics/recorders/other.js +2 -12
- package/lib/parse-proc-cpuinfo.js +11 -16
- package/lib/parse-proc-meminfo.js +5 -3
- package/lib/prioritized-attributes.js +12 -17
- package/lib/priority-queue.js +1 -1
- package/lib/proxy/grpc.js +1 -1
- package/lib/reservoir.js +9 -3
- package/lib/sampler.js +12 -13
- package/lib/serverless/api-gateway.js +3 -3
- package/lib/serverless/aws-lambda.js +28 -37
- package/lib/shim/conglomerate-shim.js +4 -4
- package/lib/shim/datastore-shim.js +29 -38
- package/lib/shim/index.js +8 -9
- package/lib/shim/message-shim.js +111 -113
- package/lib/shim/promise-shim.js +18 -13
- package/lib/shim/shim.js +72 -66
- package/lib/shim/specs/index.js +18 -19
- package/lib/shim/transaction-shim.js +26 -36
- package/lib/shim/webframework-shim.js +25 -35
- package/lib/shimmer.js +184 -166
- package/lib/spans/create-span-event-aggregator.js +24 -44
- package/lib/spans/span-context.js +4 -10
- package/lib/spans/span-event-aggregator.js +68 -13
- package/lib/spans/span-event.js +5 -7
- package/lib/spans/span-streamer.js +10 -18
- package/lib/spans/streaming-span-event-aggregator.js +1 -1
- package/lib/spans/streaming-span-event.js +4 -4
- package/lib/stats/apdex.js +5 -11
- package/lib/stats/index.js +12 -17
- package/lib/system-info.js +7 -3
- package/lib/timer.js +30 -16
- package/lib/transaction/dt-payload.js +1 -1
- package/lib/transaction/handle.js +19 -19
- package/lib/transaction/index.js +94 -112
- package/lib/transaction/name-state.js +5 -6
- package/lib/transaction/trace/aggregator.js +78 -73
- package/lib/transaction/trace/exclusive-time-calculator.js +5 -9
- package/lib/transaction/trace/index.js +26 -24
- package/lib/transaction/trace/segment.js +39 -56
- package/lib/transaction/tracecontext.js +37 -45
- package/lib/transaction/tracer/index.js +79 -44
- package/lib/transaction/transaction-event-aggregator.js +29 -31
- package/lib/uninstrumented.js +4 -5
- package/lib/util/attribute-types.js +1 -5
- package/lib/util/byte-limit.js +0 -1
- package/lib/util/cat.js +5 -13
- package/lib/util/codec.js +8 -4
- package/lib/util/deep-equal.js +48 -18
- package/lib/util/flatten.js +5 -2
- package/lib/util/hashes.js +2 -2
- package/lib/util/label-parser.js +7 -13
- package/lib/util/logger.js +31 -13
- package/lib/util/process-version.js +1 -1
- package/lib/util/properties.js +1 -1
- package/lib/util/sql/obfuscate.js +7 -17
- package/lib/util/stream-sink.js +2 -3
- package/lib/util/urltils.js +9 -13
- package/lib/utilization/aws-info.js +2 -3
- package/lib/utilization/azure-info.js +32 -30
- package/lib/utilization/common.js +5 -4
- package/lib/utilization/docker-info.js +4 -6
- package/lib/utilization/gcp-info.js +36 -35
- package/lib/utilization/index.js +1 -1
- package/lib/utilization/kubernetes-info.js +2 -2
- package/lib/utilization/pcf-info.js +4 -4
- package/package.json +32 -18
- package/stub_api.js +8 -6
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
8
|
const shimmer = require('../../shimmer')
|
|
9
|
-
const logger = require('../../logger').child({component: 'http'})
|
|
9
|
+
const logger = require('../../logger').child({ component: 'http' })
|
|
10
10
|
const recordWeb = require('../../metrics/recorders/http')
|
|
11
11
|
const hashes = require('../../util/hashes')
|
|
12
12
|
const cat = require('../../util/cat')
|
|
@@ -32,7 +32,6 @@ const NEWRELIC_TRANSACTION_HEADER = 'x-newrelic-transaction'
|
|
|
32
32
|
const NEWRELIC_SYNTHETICS_HEADER = 'x-newrelic-synthetics'
|
|
33
33
|
const TRANSACTION_INFO_KEY = '__NR_transactionInfo'
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
// For incoming requests this instrumentation functions by wrapping
|
|
37
36
|
// `http.createServer` and `http.Server#addListener`. The former merely sets the
|
|
38
37
|
// agent dispatcher to 'http' and the latter wraps any event handlers bound to
|
|
@@ -49,7 +48,9 @@ function wrapEmitWithTransaction(agent, emit, isHTTPS) {
|
|
|
49
48
|
|
|
50
49
|
return tracer.transactionProxy(function wrappedHandler(evnt, request, response) {
|
|
51
50
|
var transaction = tracer.getTransaction()
|
|
52
|
-
if (!transaction)
|
|
51
|
+
if (!transaction) {
|
|
52
|
+
return emit.apply(this, arguments)
|
|
53
|
+
}
|
|
53
54
|
|
|
54
55
|
transaction.nameState.setPrefix(NAMES.NODEJS.PREFIX)
|
|
55
56
|
transaction.nameState.setDelimiter(NAMES.ACTION_DELIMITER)
|
|
@@ -73,10 +74,7 @@ function wrapEmitWithTransaction(agent, emit, isHTTPS) {
|
|
|
73
74
|
segment.start()
|
|
74
75
|
|
|
75
76
|
if (request.method != null) {
|
|
76
|
-
segment.addSpanAttribute(
|
|
77
|
-
'request.method',
|
|
78
|
-
request.method
|
|
79
|
-
)
|
|
77
|
+
segment.addSpanAttribute('request.method', request.method)
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
if (txInfo) {
|
|
@@ -106,10 +104,7 @@ function wrapEmitWithTransaction(agent, emit, isHTTPS) {
|
|
|
106
104
|
transaction.url
|
|
107
105
|
)
|
|
108
106
|
|
|
109
|
-
segment.addSpanAttribute(
|
|
110
|
-
'request.uri',
|
|
111
|
-
transaction.url
|
|
112
|
-
)
|
|
107
|
+
segment.addSpanAttribute('request.uri', transaction.url)
|
|
113
108
|
|
|
114
109
|
// store the port on which this transaction runs
|
|
115
110
|
if (this.address instanceof Function) {
|
|
@@ -121,8 +116,10 @@ function wrapEmitWithTransaction(agent, emit, isHTTPS) {
|
|
|
121
116
|
transaction.port = serverPort
|
|
122
117
|
|
|
123
118
|
// need to set any config-driven names early for RUM
|
|
124
|
-
logger.trace(
|
|
125
|
-
|
|
119
|
+
logger.trace(
|
|
120
|
+
{ url: request.url, transaction: transaction.id },
|
|
121
|
+
'Applying user naming rules for RUM.'
|
|
122
|
+
)
|
|
126
123
|
transaction.applyUserNamingRules(request.url)
|
|
127
124
|
|
|
128
125
|
const queueTimeStamp = headerProcessing.getQueueTime(logger, request.headers)
|
|
@@ -151,8 +148,7 @@ function wrapEmitWithTransaction(agent, emit, isHTTPS) {
|
|
|
151
148
|
if (agent.config.encoding_key) {
|
|
152
149
|
cat.handleCatHeaders(incomingCatId, obfTransaction, agent.config.encoding_key, transaction)
|
|
153
150
|
if (transaction.incomingCatId) {
|
|
154
|
-
logger.trace('Got inbound request CAT headers in transaction %s',
|
|
155
|
-
transaction.id)
|
|
151
|
+
logger.trace('Got inbound request CAT headers in transaction %s', transaction.id)
|
|
156
152
|
}
|
|
157
153
|
}
|
|
158
154
|
}
|
|
@@ -228,10 +224,7 @@ function storeTxInfo(transaction, request, response) {
|
|
|
228
224
|
request[TRANSACTION_INFO_KEY] = response[TRANSACTION_INFO_KEY] = txInfo
|
|
229
225
|
}
|
|
230
226
|
|
|
231
|
-
logger.trace(
|
|
232
|
-
'Stored transaction %s information on request and response',
|
|
233
|
-
transaction.id
|
|
234
|
-
)
|
|
227
|
+
logger.trace('Stored transaction %s information on request and response', transaction.id)
|
|
235
228
|
|
|
236
229
|
return txInfo
|
|
237
230
|
}
|
|
@@ -240,11 +233,7 @@ function initializeRequest(transaction, request) {
|
|
|
240
233
|
headerAttributes.collectRequestHeaders(request.headers, transaction)
|
|
241
234
|
|
|
242
235
|
if (request.method != null) {
|
|
243
|
-
transaction.trace.attributes.addAttribute(
|
|
244
|
-
DESTS.TRANS_COMMON,
|
|
245
|
-
'request.method',
|
|
246
|
-
request.method
|
|
247
|
-
)
|
|
236
|
+
transaction.trace.attributes.addAttribute(DESTS.TRANS_COMMON, 'request.method', request.method)
|
|
248
237
|
transaction.nameState.setVerb(request.method)
|
|
249
238
|
}
|
|
250
239
|
}
|
|
@@ -314,9 +303,7 @@ function wrapWriteHead(agent, writeHead) {
|
|
|
314
303
|
}
|
|
315
304
|
|
|
316
305
|
if (!agent.config.trusted_account_ids) {
|
|
317
|
-
logger.trace(
|
|
318
|
-
'No account IDs in config.trusted_account_ids - not adding response CAT headers'
|
|
319
|
-
)
|
|
306
|
+
logger.trace('No account IDs in config.trusted_account_ids - not adding response CAT headers')
|
|
320
307
|
return writeHead.apply(this, arguments)
|
|
321
308
|
}
|
|
322
309
|
|
|
@@ -346,10 +333,10 @@ function wrapWriteHead(agent, writeHead) {
|
|
|
346
333
|
// -1 means no content length header was sent. We should only send this
|
|
347
334
|
// value in the appData if the header is set.
|
|
348
335
|
var contentLength = -1
|
|
349
|
-
var
|
|
336
|
+
var newHeaders = arguments[arguments.length - 1]
|
|
350
337
|
|
|
351
|
-
if (typeof
|
|
352
|
-
contentLength = headerProcessing.getContentLengthFromHeaders(
|
|
338
|
+
if (typeof newHeaders === 'object') {
|
|
339
|
+
contentLength = headerProcessing.getContentLengthFromHeaders(newHeaders)
|
|
353
340
|
}
|
|
354
341
|
|
|
355
342
|
const currentHeaders = this.getHeaders()
|
|
@@ -395,9 +382,10 @@ function wrapWriteHead(agent, writeHead) {
|
|
|
395
382
|
function urlToOptions(_url) {
|
|
396
383
|
const options = {
|
|
397
384
|
protocol: _url.protocol,
|
|
398
|
-
hostname:
|
|
399
|
-
_url.hostname.
|
|
400
|
-
|
|
385
|
+
hostname:
|
|
386
|
+
typeof _url.hostname === 'string' && _url.hostname.startsWith('[')
|
|
387
|
+
? _url.hostname.slice(1, -1)
|
|
388
|
+
: _url.hostname,
|
|
401
389
|
hash: _url.hash,
|
|
402
390
|
search: _url.search,
|
|
403
391
|
pathname: _url.pathname,
|
|
@@ -437,7 +425,6 @@ function wrapRequest(agent, request) {
|
|
|
437
425
|
|
|
438
426
|
let reqArgs = [options, cb]
|
|
439
427
|
|
|
440
|
-
|
|
441
428
|
// Don't pollute metrics and calls with NR connections
|
|
442
429
|
const internalOnly = options && options[NR_CONNECTION_PROP]
|
|
443
430
|
if (internalOnly) {
|
|
@@ -477,8 +464,9 @@ module.exports = function initialize(agent, http, moduleName) {
|
|
|
477
464
|
const IS_HTTPS = moduleName === 'https'
|
|
478
465
|
|
|
479
466
|
// FIXME: will this ever not be called?
|
|
480
|
-
shimmer.wrapMethod(http, 'http', 'createServer', function
|
|
481
|
-
|
|
467
|
+
shimmer.wrapMethod(http, 'http', 'createServer', function wrapMethod(createServer) {
|
|
468
|
+
// eslint-disable-next-line no-unused-vars
|
|
469
|
+
return function setDispatcher(requestListener) {
|
|
482
470
|
agent.environment.setDispatcher('http')
|
|
483
471
|
return createServer.apply(this, arguments)
|
|
484
472
|
}
|
|
@@ -504,7 +492,6 @@ module.exports = function initialize(agent, http, moduleName) {
|
|
|
504
492
|
|
|
505
493
|
wrapResponseEnd(agent, http.ServerResponse && http.ServerResponse.prototype)
|
|
506
494
|
|
|
507
|
-
|
|
508
495
|
// If CAT is enabled we'll wrap `writeHead` to inject our headers.
|
|
509
496
|
if (agent.config.cross_application_tracer.enabled) {
|
|
510
497
|
shimmer.wrapMethod(
|
|
@@ -517,19 +504,9 @@ module.exports = function initialize(agent, http, moduleName) {
|
|
|
517
504
|
|
|
518
505
|
var agentProto = http && http.Agent && http.Agent.prototype
|
|
519
506
|
|
|
520
|
-
shimmer.wrapMethod(
|
|
521
|
-
http,
|
|
522
|
-
'http',
|
|
523
|
-
'request',
|
|
524
|
-
wrapRequest.bind(null, agent)
|
|
525
|
-
)
|
|
507
|
+
shimmer.wrapMethod(http, 'http', 'request', wrapRequest.bind(null, agent))
|
|
526
508
|
|
|
527
|
-
shimmer.wrapMethod(
|
|
528
|
-
http,
|
|
529
|
-
'http',
|
|
530
|
-
'get',
|
|
531
|
-
wrapRequest.bind(null, agent)
|
|
532
|
-
)
|
|
509
|
+
shimmer.wrapMethod(http, 'http', 'get', wrapRequest.bind(null, agent))
|
|
533
510
|
|
|
534
511
|
shimmer.wrapMethod(
|
|
535
512
|
agentProto,
|
|
@@ -597,24 +574,17 @@ function parseSyntheticsHeader(header, encKey, trustedIds) {
|
|
|
597
574
|
}
|
|
598
575
|
var synthData = null
|
|
599
576
|
try {
|
|
600
|
-
synthData = JSON.parse(
|
|
601
|
-
hashes.deobfuscateNameUsingKey(header, encKey)
|
|
602
|
-
)
|
|
577
|
+
synthData = JSON.parse(hashes.deobfuscateNameUsingKey(header, encKey))
|
|
603
578
|
} catch (e) {
|
|
604
579
|
logger.trace(e, 'Got unparsable synthetics header: %s', header)
|
|
605
580
|
return
|
|
606
581
|
}
|
|
607
582
|
|
|
608
583
|
if (!Array.isArray(synthData)) {
|
|
609
|
-
logger.trace(
|
|
610
|
-
'Synthetics data is not an array: %s (%s)',
|
|
611
|
-
synthData,
|
|
612
|
-
typeof synthData
|
|
613
|
-
)
|
|
584
|
+
logger.trace('Synthetics data is not an array: %s (%s)', synthData, typeof synthData)
|
|
614
585
|
return
|
|
615
586
|
}
|
|
616
587
|
|
|
617
|
-
|
|
618
588
|
if (synthData.length < Object.keys(parsedData).length) {
|
|
619
589
|
logger.trace(
|
|
620
590
|
'Synthetics header length is %s, expected at least %s',
|
|
@@ -625,11 +595,7 @@ function parseSyntheticsHeader(header, encKey, trustedIds) {
|
|
|
625
595
|
|
|
626
596
|
parsedData.version = synthData[0]
|
|
627
597
|
if (parsedData.version !== 1) {
|
|
628
|
-
logger.trace(
|
|
629
|
-
'Synthetics header version is not 1, got: %s (%s)',
|
|
630
|
-
parsedData.version,
|
|
631
|
-
synthData
|
|
632
|
-
)
|
|
598
|
+
logger.trace('Synthetics header version is not 1, got: %s (%s)', parsedData.version, synthData)
|
|
633
599
|
return
|
|
634
600
|
}
|
|
635
601
|
|
|
@@ -13,15 +13,11 @@ function initialize(agent, inspector, name, shim) {
|
|
|
13
13
|
return false
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
shim.wrap(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
var args = shim.argsToArray.apply(shim, arguments)
|
|
22
|
-
shim.bindCallbackSegment(args, shim.LAST)
|
|
23
|
-
return fn.apply(this, args)
|
|
24
|
-
}
|
|
16
|
+
shim.wrap(sessionProto, 'post', function wrapPost(shim, fn) {
|
|
17
|
+
return function wrappedPost() {
|
|
18
|
+
var args = shim.argsToArray.apply(shim, arguments)
|
|
19
|
+
shim.bindCallbackSegment(args, shim.LAST)
|
|
20
|
+
return fn.apply(this, args)
|
|
25
21
|
}
|
|
26
|
-
)
|
|
22
|
+
})
|
|
27
23
|
}
|
|
@@ -46,7 +46,9 @@ module.exports = function initialize(agent, net, moduleName, shim) {
|
|
|
46
46
|
const segment = shim.getActiveSegment()
|
|
47
47
|
const emit = this.emit
|
|
48
48
|
|
|
49
|
-
if (!segment || !emit)
|
|
49
|
+
if (!segment || !emit) {
|
|
50
|
+
return fn.apply(this, arguments)
|
|
51
|
+
}
|
|
50
52
|
|
|
51
53
|
this.emit = wrappedEmit
|
|
52
54
|
|
|
@@ -10,29 +10,25 @@ module.exports = initialize
|
|
|
10
10
|
function initialize(agent, timers, moduleName, shim) {
|
|
11
11
|
const processMethods = ['nextTick', '_nextDomainTick', '_tickDomainCallback']
|
|
12
12
|
|
|
13
|
-
shim.wrap(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!segment) {
|
|
20
|
-
return fn.apply(this, arguments)
|
|
21
|
-
}
|
|
13
|
+
shim.wrap(process, processMethods, function wrapProcess(shim, fn) {
|
|
14
|
+
return function wrappedProcess() {
|
|
15
|
+
const segment = shim.getActiveSegment()
|
|
16
|
+
if (!segment) {
|
|
17
|
+
return fn.apply(this, arguments)
|
|
18
|
+
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
// Manual copy because helper methods add significant overhead in some usages
|
|
21
|
+
var len = arguments.length
|
|
22
|
+
var args = new Array(len)
|
|
23
|
+
for (var i = 0; i < len; ++i) {
|
|
24
|
+
args[i] = arguments[i]
|
|
25
|
+
}
|
|
29
26
|
|
|
30
|
-
|
|
27
|
+
shim.bindSegment(args, shim.FIRST, segment)
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
}
|
|
29
|
+
return fn.apply(this, args)
|
|
34
30
|
}
|
|
35
|
-
)
|
|
31
|
+
})
|
|
36
32
|
|
|
37
33
|
instrumentTimerMethods(timers)
|
|
38
34
|
|
|
@@ -43,10 +39,7 @@ function initialize(agent, timers, moduleName, shim) {
|
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
function instrumentTimerMethods(nodule) {
|
|
46
|
-
const asynchronizers = [
|
|
47
|
-
'setTimeout',
|
|
48
|
-
'setInterval'
|
|
49
|
-
]
|
|
42
|
+
const asynchronizers = ['setTimeout', 'setInterval']
|
|
50
43
|
|
|
51
44
|
shim.record(nodule, asynchronizers, recordAsynchronizers)
|
|
52
45
|
|
|
@@ -87,7 +80,7 @@ function initialize(agent, timers, moduleName, shim) {
|
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
function recordAsynchronizers(shim, fn, name) {
|
|
90
|
-
return {name: 'timers.' + name, callback: shim.FIRST}
|
|
83
|
+
return { name: 'timers.' + name, callback: shim.FIRST }
|
|
91
84
|
}
|
|
92
85
|
}
|
|
93
86
|
|
|
@@ -9,15 +9,7 @@ const recorder = require('../../metrics/recorders/generic')
|
|
|
9
9
|
|
|
10
10
|
module.exports = initialize
|
|
11
11
|
|
|
12
|
-
var methods = [
|
|
13
|
-
'deflate',
|
|
14
|
-
'deflateRaw',
|
|
15
|
-
'gzip',
|
|
16
|
-
'gunzip',
|
|
17
|
-
'inflate',
|
|
18
|
-
'inflateRaw',
|
|
19
|
-
'unzip'
|
|
20
|
-
]
|
|
12
|
+
var methods = ['deflate', 'deflateRaw', 'gzip', 'gunzip', 'inflate', 'inflateRaw', 'unzip']
|
|
21
13
|
|
|
22
14
|
function initialize(agent, zlib, moduleName, shim) {
|
|
23
15
|
shim.record(zlib, methods, recordZLib)
|
|
@@ -34,7 +26,7 @@ function initialize(agent, zlib, moduleName, shim) {
|
|
|
34
26
|
}
|
|
35
27
|
|
|
36
28
|
function recordZLib(shim, fn, name) {
|
|
37
|
-
return {name: `zlib.${name}`, callback: shim.LAST, recorder}
|
|
29
|
+
return { name: `zlib.${name}`, callback: shim.LAST, recorder }
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
32
|
|
|
@@ -121,7 +121,7 @@ function wrapExpress3(shim, express) {
|
|
|
121
121
|
|
|
122
122
|
function wrapRouteMethods(shim, route, path) {
|
|
123
123
|
var methods = ['all', 'delete', 'get', 'head', 'opts', 'post', 'put', 'patch']
|
|
124
|
-
shim.wrapMiddlewareMounter(route, methods, {route: path, wrapper: wrapMiddleware})
|
|
124
|
+
shim.wrapMiddlewareMounter(route, methods, { route: path, wrapper: wrapMiddleware })
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
function wrapResponse(shim, response) {
|
|
@@ -139,7 +139,9 @@ function wrapResponse(shim, response) {
|
|
|
139
139
|
++cbIdx
|
|
140
140
|
cb = function defaultRenderCB(err, str) {
|
|
141
141
|
// https://github.com/expressjs/express/blob/4.x/lib/response.js#L961-L962
|
|
142
|
-
if (err)
|
|
142
|
+
if (err) {
|
|
143
|
+
return res.req.next(err)
|
|
144
|
+
}
|
|
143
145
|
res.send(str)
|
|
144
146
|
}
|
|
145
147
|
args.push(cb)
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
'use strict'
|
|
2
7
|
const semver = require('semver')
|
|
3
8
|
const {
|
|
4
9
|
buildMiddlewareSpecForRouteHandler,
|
|
5
10
|
buildMiddlewareSpecForMiddlewareFunction
|
|
6
|
-
} = require
|
|
11
|
+
} = require('./fastify/spec-builders')
|
|
7
12
|
/**
|
|
8
13
|
* Sets up fastify route handler
|
|
9
14
|
*
|
|
@@ -17,7 +22,7 @@ const {
|
|
|
17
22
|
* maintain code
|
|
18
23
|
*/
|
|
19
24
|
const setupRouteHandler = (shim, fastify) => {
|
|
20
|
-
fastify.addHook('onRoute', (routeOptions)=>{
|
|
25
|
+
fastify.addHook('onRoute', (routeOptions) => {
|
|
21
26
|
if (!routeOptions.handler) {
|
|
22
27
|
return
|
|
23
28
|
}
|
|
@@ -38,12 +43,6 @@ const setupRouteHandler = (shim, fastify) => {
|
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
const setupMiddlewareHandlers = (shim, fastify) => {
|
|
41
|
-
// Don't wrap use() in fastify v3+
|
|
42
|
-
const fastifyVersion = shim.require('./package.json').version
|
|
43
|
-
if (semver.satisfies(fastifyVersion, '>=3.0.0')) {
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
46
|
shim.wrap(fastify, 'use', function wrapFastifyUse(shim, fn) {
|
|
48
47
|
return function wrappedFastifyUser() {
|
|
49
48
|
const args = shim.argsToArray.apply(shim, arguments)
|
|
@@ -65,10 +64,14 @@ module.exports = function initialize(agent, fastify, moduleName, shim) {
|
|
|
65
64
|
return
|
|
66
65
|
}
|
|
67
66
|
shim.setFramework(shim.FASTIFY)
|
|
67
|
+
|
|
68
|
+
const fastifyVersion = shim.require('./package.json').version
|
|
69
|
+
const isv3Plus = semver.satisfies(fastifyVersion, '>=3.0.0')
|
|
70
|
+
|
|
68
71
|
/**
|
|
69
72
|
* Fastify exports a function, so we need to use wrapExport
|
|
70
73
|
*/
|
|
71
|
-
shim.wrapExport(fastify, function wrapFastifyModule(shim, fn) {
|
|
74
|
+
const wrappedExport = shim.wrapExport(fastify, function wrapFastifyModule(shim, fn) {
|
|
72
75
|
return function wrappedFastifyModule() {
|
|
73
76
|
// normalize arguments
|
|
74
77
|
const args = shim.argsToArray.apply(shim, arguments)
|
|
@@ -78,9 +81,33 @@ module.exports = function initialize(agent, fastify, moduleName, shim) {
|
|
|
78
81
|
|
|
79
82
|
setupRouteHandler(shim, fastifyForWrapping)
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
// Don't wrap use() in fastify v3+
|
|
85
|
+
if (!isv3Plus) {
|
|
86
|
+
setupMiddlewareHandlers(shim, fastifyForWrapping)
|
|
87
|
+
}
|
|
82
88
|
|
|
83
89
|
return fastifyForWrapping
|
|
84
90
|
}
|
|
85
91
|
})
|
|
92
|
+
|
|
93
|
+
if (isv3Plus) {
|
|
94
|
+
setupExports(fastify, wrappedExport)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* module.exports = fastify
|
|
100
|
+
* module.exports.fastify = fastify
|
|
101
|
+
* module.exports.default = fastify
|
|
102
|
+
*/
|
|
103
|
+
function setupExports(original, wrappedExport) {
|
|
104
|
+
wrappedExport.fastify = original.fastify
|
|
105
|
+
|
|
106
|
+
if (original.fastify) {
|
|
107
|
+
wrappedExport.fastify = wrappedExport
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (original.default) {
|
|
111
|
+
wrappedExport.default = wrappedExport
|
|
112
|
+
}
|
|
86
113
|
}
|
|
@@ -13,7 +13,7 @@ module.exports = function initialize(agent, hapi, moduleName, shim) {
|
|
|
13
13
|
// At this point, framework and error predicate have both already been set via ./hapi,
|
|
14
14
|
// so we only need to set the response predicate and wrap the server object
|
|
15
15
|
shim.setResponsePredicate(function hapiResponsePredicate(args, result) {
|
|
16
|
-
return !(result instanceof Error) &&
|
|
16
|
+
return !(result instanceof Error) && result !== args[1].continue
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
// 'Server' and 'server' both point to the same export,
|
|
@@ -61,9 +61,7 @@ function serverPostConstructor(shim) {
|
|
|
61
61
|
function wrappedHandler(route) {
|
|
62
62
|
var ret = fn.apply(this, arguments)
|
|
63
63
|
|
|
64
|
-
return
|
|
65
|
-
? wrapRouteHandler(shim, ret, route && route.path)
|
|
66
|
-
: ret
|
|
64
|
+
return typeof ret === 'function' ? wrapRouteHandler(shim, ret, route && route.path) : ret
|
|
67
65
|
}
|
|
68
66
|
})
|
|
69
67
|
|
|
@@ -80,11 +78,12 @@ function serverPostConstructor(shim) {
|
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
// If route is created via a plugin, pull prefix if it exists
|
|
83
|
-
const prefix =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
const prefix =
|
|
82
|
+
(this.realm &&
|
|
83
|
+
this.realm.modifiers &&
|
|
84
|
+
this.realm.modifiers.route &&
|
|
85
|
+
this.realm.modifiers.route.prefix) ||
|
|
86
|
+
''
|
|
88
87
|
|
|
89
88
|
_wrapRoute(shim, args[0])
|
|
90
89
|
|
|
@@ -170,7 +169,7 @@ function wrapPreHandlers(shim, container, path) {
|
|
|
170
169
|
|
|
171
170
|
function wrapPreHandler(shim, container, path) {
|
|
172
171
|
return shim.record(container, (shim) => {
|
|
173
|
-
return {name: [shim.HAPI, ' pre handler: ','(',path,')'].join(''), recorder: record}
|
|
172
|
+
return { name: [shim.HAPI, ' pre handler: ', '(', path, ')'].join(''), recorder: record }
|
|
174
173
|
})
|
|
175
174
|
}
|
|
176
175
|
|
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
var shared = require('./hapi/shared')
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
module.exports = function initialize(agent, hapi, moduleName, shim) {
|
|
12
11
|
if (!agent || !hapi || !shim) {
|
|
13
|
-
shim &&
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
shim &&
|
|
13
|
+
shim.logger.debug(
|
|
14
|
+
'Hapi instrumentation function called with incorrect arguments, not instrumenting.'
|
|
15
|
+
)
|
|
16
16
|
return false
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
shim.setFramework(shim.HAPI)
|
|
20
20
|
|
|
21
21
|
shim.setErrorPredicate(function hapiErrorPredicate(err) {
|
|
22
|
-
return
|
|
22
|
+
return err instanceof Error
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
if (hapi.createServer) {
|
|
@@ -83,11 +83,12 @@ function wrapServer(shim, Server) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// If route is created via a plugin, pull prefix if it exists
|
|
86
|
-
const prefix =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
const prefix =
|
|
87
|
+
(this.realm &&
|
|
88
|
+
this.realm.modifiers &&
|
|
89
|
+
this.realm.modifiers.route &&
|
|
90
|
+
this.realm.modifiers.route.prefix) ||
|
|
91
|
+
''
|
|
91
92
|
|
|
92
93
|
_wrapRoute(shim, args[0])
|
|
93
94
|
|
|
@@ -185,10 +186,7 @@ function wrapRouteHandler(shim, container, path) {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
function _wrapRouteHandler(handler) {
|
|
188
|
-
return shim.recordMiddleware(
|
|
189
|
-
wrapHapiHandler(shim, handler),
|
|
190
|
-
buildMiddlewareSpec(shim, path)
|
|
191
|
-
)
|
|
189
|
+
return shim.recordMiddleware(wrapHapiHandler(shim, handler), buildMiddlewareSpec(shim, path))
|
|
192
190
|
}
|
|
193
191
|
}
|
|
194
192
|
|
|
@@ -237,7 +235,9 @@ function wrapMiddleware(shim, middleware, event) {
|
|
|
237
235
|
type: event === 'onPreResponse' ? shim.ERRORWARE : shim.MIDDLEWARE,
|
|
238
236
|
next: function wrapNext(shim, fn, fnName, args, wrap) {
|
|
239
237
|
var reply = args[1]
|
|
240
|
-
if (!reply || !shim.isFunction(reply.continue))
|
|
238
|
+
if (!reply || !shim.isFunction(reply.continue)) {
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
241
|
wrap(reply, 'continue')
|
|
242
242
|
},
|
|
243
243
|
req: function getReq(shim, fn, fnName, args) {
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
var stringify = require('json-stringify-safe')
|
|
9
9
|
var urltils = require('../util/urltils.js')
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
13
12
|
var proto = redis && redis.prototype
|
|
14
13
|
if (!proto) {
|
|
@@ -40,7 +39,7 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
return {
|
|
43
|
-
name:
|
|
42
|
+
name: command.name || 'unknown',
|
|
44
43
|
parameters: parameters,
|
|
45
44
|
promise: true
|
|
46
45
|
}
|