newrelic 9.6.0 → 9.7.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 +4 -0
- package/api.js +2 -0
- package/bin/test-naming-rules.js +1 -1
- package/esm-loader.mjs +1 -3
- package/lib/adaptive-sampler.js +1 -2
- package/lib/agent.js +2 -0
- package/lib/aggregators/event-aggregator.js +2 -2
- package/lib/attributes.js +2 -4
- package/lib/collector/api.js +20 -12
- package/lib/collector/facts.js +1 -3
- package/lib/collector/parse-response.js +3 -1
- package/lib/collector/remote-method.js +8 -9
- package/lib/config/attribute-filter.js +14 -16
- package/lib/config/default.js +17 -0
- package/lib/config/harvest-config-validator.js +3 -5
- package/lib/config/index.js +7 -4
- package/lib/environment.js +6 -5
- package/lib/errors/error-collector.js +6 -3
- package/lib/errors/helper.js +10 -18
- package/lib/errors/index.js +12 -6
- package/lib/grpc/connection.js +12 -5
- package/lib/header-attributes.js +4 -2
- package/lib/header-processing.js +2 -2
- package/lib/instrumentation/@hapi/hapi.js +2 -0
- package/lib/instrumentation/@node-redis/client.js +2 -0
- package/lib/instrumentation/amqplib.js +2 -0
- package/lib/instrumentation/core/async_hooks.js +2 -0
- package/lib/instrumentation/core/globals.js +11 -8
- package/lib/instrumentation/core/http-outbound.js +14 -12
- package/lib/instrumentation/core/http.js +10 -8
- package/lib/instrumentation/core/timers.js +2 -0
- package/lib/instrumentation/fastify.js +1 -3
- package/lib/instrumentation/grpc-js/grpc.js +14 -3
- package/lib/instrumentation/memcached.js +5 -0
- package/lib/instrumentation/mongodb/common.js +3 -0
- package/lib/instrumentation/mongodb/v2-mongo.js +6 -3
- package/lib/instrumentation/mongodb.js +1 -1
- package/lib/instrumentation/nr-winston-transport.js +3 -4
- package/lib/instrumentation/promise.js +7 -4
- package/lib/instrumentation/redis.js +2 -0
- package/lib/instrumentation/undici.js +2 -0
- package/lib/metrics/mapper.js +2 -3
- package/lib/metrics/metric-aggregator.js +1 -3
- package/lib/metrics/names.js +19 -15
- package/lib/metrics/normalizer/rule.js +6 -7
- package/lib/metrics/normalizer/tx_segment.js +3 -2
- package/lib/metrics/normalizer.js +5 -3
- package/lib/parse-proc-cpuinfo.js +11 -6
- package/lib/serverless/api-gateway.js +3 -4
- package/lib/serverless/aws-lambda.js +3 -3
- package/lib/shim/conglomerate-shim.js +2 -3
- package/lib/shim/datastore-shim.js +22 -104
- package/lib/shim/index.js +7 -0
- package/lib/shim/message-shim.js +2 -0
- package/lib/shim/promise-shim.js +48 -42
- package/lib/shim/shim.js +7 -7
- package/lib/shim/webframework-shim.js +2 -0
- package/lib/spans/map-to-streaming-type.js +0 -2
- package/lib/spans/span-context.js +2 -0
- package/lib/spans/span-event-aggregator.js +2 -2
- package/lib/spans/span-event.js +2 -2
- package/lib/spans/span-streamer.js +4 -0
- package/lib/spans/streaming-span-event-aggregator.js +2 -4
- package/lib/spans/streaming-span-event.js +3 -2
- package/lib/system-info.js +3 -5
- package/lib/timer.js +8 -6
- package/lib/transaction/dt-payload.js +4 -3
- package/lib/transaction/handle.js +12 -2
- package/lib/transaction/index.js +19 -18
- package/lib/transaction/name-state.js +17 -2
- package/lib/transaction/trace/aggregator.js +4 -12
- package/lib/transaction/trace/index.js +7 -5
- package/lib/transaction/trace/segment.js +6 -11
- package/lib/transaction/tracecontext.js +10 -6
- package/lib/transaction/tracer/index.js +23 -25
- package/lib/transaction/transaction-event-aggregator.js +1 -3
- package/lib/util/attribute-types.js +1 -2
- package/lib/util/byte-limit.js +1 -3
- package/lib/util/cat.js +16 -13
- package/lib/util/codec.js +0 -2
- package/lib/util/copy.js +1 -2
- package/lib/util/deep-equal.js +7 -0
- package/lib/util/flatten.js +4 -6
- package/lib/util/hashes.js +1 -3
- package/lib/util/process-version.js +2 -3
- package/lib/util/properties.js +2 -5
- package/lib/util/stream-sink.js +2 -0
- package/lib/util/urltils.js +4 -10
- package/newrelic.js +1 -1
- package/package.json +2 -1
package/lib/errors/index.js
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 22] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
8
10
|
const DESTINATIONS = require('../config/attribute-filter').DESTINATIONS
|
|
9
11
|
const NAMES = require('../metrics/names')
|
|
10
12
|
const props = require('../util/properties')
|
|
11
13
|
const urltils = require('../util/urltils')
|
|
12
14
|
const errorHelper = require('../errors/helper')
|
|
15
|
+
const ERROR_EXPECTED_PATH = 'error.expected'
|
|
13
16
|
|
|
14
17
|
class Exception {
|
|
15
18
|
constructor({ error, timestamp, customAttributes, agentAttributes }) {
|
|
@@ -101,9 +104,9 @@ function createError(transaction, exception, config) {
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
params.intrinsics[
|
|
107
|
+
params.intrinsics[ERROR_EXPECTED_PATH] = false
|
|
105
108
|
if (errorHelper.isExpected(type, message, transaction, config, urltils)) {
|
|
106
|
-
params.intrinsics[
|
|
109
|
+
params.intrinsics[ERROR_EXPECTED_PATH] = true
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
const res = [0, name, message, type, params]
|
|
@@ -116,6 +119,11 @@ function createError(transaction, exception, config) {
|
|
|
116
119
|
/**
|
|
117
120
|
* Creates a structure for error event that is sent to the collector.
|
|
118
121
|
* The error parameter is an output of the createError() function for a given exception.
|
|
122
|
+
*
|
|
123
|
+
* @param transaction
|
|
124
|
+
* @param error
|
|
125
|
+
* @param timestamp
|
|
126
|
+
* @param config
|
|
119
127
|
*/
|
|
120
128
|
function createEvent(transaction, error, timestamp, config) {
|
|
121
129
|
const message = error[2]
|
|
@@ -126,7 +134,7 @@ function createEvent(transaction, error, timestamp, config) {
|
|
|
126
134
|
transaction,
|
|
127
135
|
errorClass,
|
|
128
136
|
message,
|
|
129
|
-
errorParams.intrinsics[
|
|
137
|
+
errorParams.intrinsics[ERROR_EXPECTED_PATH],
|
|
130
138
|
timestamp,
|
|
131
139
|
config
|
|
132
140
|
)
|
|
@@ -136,9 +144,7 @@ function createEvent(transaction, error, timestamp, config) {
|
|
|
136
144
|
const userAttributes = Object.assign(Object.create(null), errorParams.userAttributes)
|
|
137
145
|
const agentAttributes = Object.assign(Object.create(null), errorParams.agentAttributes)
|
|
138
146
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return errorEvent
|
|
147
|
+
return [intrinsicAttributes, userAttributes, agentAttributes]
|
|
142
148
|
}
|
|
143
149
|
|
|
144
150
|
// eslint-disable-next-line max-params
|
package/lib/grpc/connection.js
CHANGED
|
@@ -41,9 +41,9 @@ class GrpcConnection extends EventEmitter {
|
|
|
41
41
|
* Standard property setting/initialization, and sets an initial
|
|
42
42
|
* connection state of disconnected
|
|
43
43
|
*
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {object} traceObserverConfig config item config.infinite_tracing.trace_observer
|
|
45
45
|
* @param {MetricAggregator} metrics metric aggregator, for supportability metrics
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {number} [reconnectDelayMs=15000] number of milliseconds to wait before reconnecting
|
|
47
47
|
* for error states that require a reconnect delay.
|
|
48
48
|
*/
|
|
49
49
|
constructor(traceObserverConfig, metrics, reconnectDelayMs) {
|
|
@@ -97,6 +97,7 @@ class GrpcConnection extends EventEmitter {
|
|
|
97
97
|
*
|
|
98
98
|
* @param {int} state The connection state (See connectionStates above)
|
|
99
99
|
* @param {ClientDuplexStreamImpl} state The GRPC stream, when defined
|
|
100
|
+
* @param stream
|
|
100
101
|
*/
|
|
101
102
|
_setState(state, stream = null) {
|
|
102
103
|
this._state = state
|
|
@@ -146,6 +147,8 @@ class GrpcConnection extends EventEmitter {
|
|
|
146
147
|
*
|
|
147
148
|
* @param {string} licenseKey
|
|
148
149
|
* @param {string} runId
|
|
150
|
+
* @param requestHeadersMap
|
|
151
|
+
* @param env
|
|
149
152
|
*/
|
|
150
153
|
_getMetadata(licenseKey, runId, requestHeadersMap, env) {
|
|
151
154
|
const metadata = new grpc.Metadata()
|
|
@@ -170,6 +173,7 @@ class GrpcConnection extends EventEmitter {
|
|
|
170
173
|
* when appropriate env vars are set
|
|
171
174
|
*
|
|
172
175
|
* @param {Metadata} metadata
|
|
176
|
+
* @param env
|
|
173
177
|
*/
|
|
174
178
|
_setTestMetadata(metadata, env) {
|
|
175
179
|
for (const [key, envVar] of Object.entries(GRPC_TEST_META)) {
|
|
@@ -183,6 +187,7 @@ class GrpcConnection extends EventEmitter {
|
|
|
183
187
|
|
|
184
188
|
/**
|
|
185
189
|
* Disconnects from gRPC endpoint and schedules establishing a new connection.
|
|
190
|
+
*
|
|
186
191
|
* @param {number} reconnectDelayMs number of milliseconds to wait before reconnecting.
|
|
187
192
|
*/
|
|
188
193
|
_reconnect(reconnectDelayMs = 0) {
|
|
@@ -291,6 +296,8 @@ class GrpcConnection extends EventEmitter {
|
|
|
291
296
|
|
|
292
297
|
/**
|
|
293
298
|
* Creates the GRPC credentials needed
|
|
299
|
+
*
|
|
300
|
+
* @param grpcApi
|
|
294
301
|
*/
|
|
295
302
|
_generateCredentials(grpcApi) {
|
|
296
303
|
let certBuffer = null
|
|
@@ -349,6 +356,8 @@ class GrpcConnection extends EventEmitter {
|
|
|
349
356
|
* ChannelImplementation and related objects will stay in memory even after
|
|
350
357
|
* the stream is closed and we do not have a handle to the client. Currently
|
|
351
358
|
* impacting grpc-js@1.2.11 and several earlier versions.
|
|
359
|
+
*
|
|
360
|
+
* @param endpoint
|
|
352
361
|
*/
|
|
353
362
|
_createClient(endpoint) {
|
|
354
363
|
logger.trace('Creating gRPC client for: ', endpoint)
|
|
@@ -360,9 +369,7 @@ class GrpcConnection extends EventEmitter {
|
|
|
360
369
|
const traceApi = protoDescriptor.com.newrelic.trace.v1
|
|
361
370
|
|
|
362
371
|
const credentials = this._generateCredentials(grpc)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return client
|
|
372
|
+
return new traceApi.IngestService(endpoint, credentials)
|
|
366
373
|
}
|
|
367
374
|
}
|
|
368
375
|
|
package/lib/header-attributes.js
CHANGED
|
@@ -139,7 +139,8 @@ function _collectHeaders(headers, nameMap, prefix, transaction) {
|
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Adds request headers as request.headers.* attributes to the given transaction.
|
|
142
|
-
*
|
|
142
|
+
*
|
|
143
|
+
* @param {Object<string, string>} headers - Request headers to add attributes for.
|
|
143
144
|
* @param {Transaction} transaction - Transaction to add header attributes to.
|
|
144
145
|
*/
|
|
145
146
|
function collectRequestHeaders(headers, transaction) {
|
|
@@ -148,7 +149,8 @@ function collectRequestHeaders(headers, transaction) {
|
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* Adds response headers as response.headers.* attributes to the given transaction.
|
|
151
|
-
*
|
|
152
|
+
*
|
|
153
|
+
* @param {Object<string, string>} headers - Response headers to add attributes for.
|
|
152
154
|
* @param {Transaction} transaction - Transaction to add header attributes to.
|
|
153
155
|
*/
|
|
154
156
|
function collectResponseHeaders(headers, transaction) {
|
package/lib/header-processing.js
CHANGED
|
@@ -14,6 +14,7 @@ const CONTENT_LENGTH_REGEX = /^Content-Length$/i
|
|
|
14
14
|
*
|
|
15
15
|
* Queue time is provided by certain providers by stamping the request
|
|
16
16
|
* header with the time the request arrived at the router.
|
|
17
|
+
*
|
|
17
18
|
* @param {*} logger
|
|
18
19
|
* @param {*} requestHeaders
|
|
19
20
|
*/
|
|
@@ -37,8 +38,7 @@ function getQueueTime(logger, requestHeaders) {
|
|
|
37
38
|
return null
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
return convertedQueueTime
|
|
41
|
+
return convertUnit(parsedQueueTime)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function convertUnit(time) {
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 68] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
8
10
|
const record = require('../../metrics/recorders/generic')
|
|
9
11
|
// This object defines all the events that we want to wrap extensions
|
|
10
12
|
// for, as they are the only ones associated with requests.
|
|
@@ -38,14 +38,17 @@ function initialize(agent, nodule, name, shim) {
|
|
|
38
38
|
return function wrappedEmit(ev, error, promise) {
|
|
39
39
|
// Check for unhandledRejections here so we don't change the behavior of
|
|
40
40
|
// the event.
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
if (
|
|
42
|
+
ev === 'unhandledRejection' &&
|
|
43
|
+
error &&
|
|
44
|
+
!process.domain &&
|
|
45
|
+
process.listenerCount('unhandledRejection') === 0
|
|
46
|
+
) {
|
|
47
|
+
// If there are no unhandledRejection handlers report the error.
|
|
48
|
+
const segment = promise[symbols.context] && promise[symbols.context].getSegment()
|
|
49
|
+
const tx = segment && segment.transaction
|
|
50
|
+
shim.logger.trace('Captured unhandled rejection for transaction %s', tx && tx.id)
|
|
51
|
+
agent.errors.add(tx, error)
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
return original.apply(this, arguments)
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 40] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
8
10
|
const recordExternal = require('../../metrics/recorders/http_external')
|
|
9
11
|
const cat = require('../../util/cat')
|
|
10
12
|
const urltils = require('../../util/urltils')
|
|
@@ -25,10 +27,10 @@ const NEWRELIC_SYNTHETICS_HEADER = 'x-newrelic-synthetics'
|
|
|
25
27
|
/**
|
|
26
28
|
* Instruments an outbound HTTP request.
|
|
27
29
|
*
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {object} opts
|
|
30
|
-
* @param {Function} makeRequest
|
|
31
|
-
* @returns {
|
|
30
|
+
* @param {object} agent instantiation of lib/agent.js
|
|
31
|
+
* @param {object} opts HTTP request options
|
|
32
|
+
* @param {Function} makeRequest function for issuing actual HTTP request
|
|
33
|
+
* @returns {object} The instrumented outbound HTTP request.
|
|
32
34
|
*/
|
|
33
35
|
module.exports = function instrumentOutbound(agent, opts, makeRequest) {
|
|
34
36
|
if (typeof opts === 'string') {
|
|
@@ -151,10 +153,10 @@ module.exports = function instrumentOutbound(agent, opts, makeRequest) {
|
|
|
151
153
|
* Notices the given error if there is no listener for the `error` event on the
|
|
152
154
|
* request object.
|
|
153
155
|
*
|
|
154
|
-
* @param {
|
|
155
|
-
* @param {http.ClientRequest
|
|
156
|
-
* @param {Error} error
|
|
157
|
-
* @returns {
|
|
156
|
+
* @param {object} segment TraceSegment instance
|
|
157
|
+
* @param {object} req http.ClientRequest
|
|
158
|
+
* @param {Error} error If provided, unhandled error that occurred during request
|
|
159
|
+
* @returns {boolean} True if the error will be collected by New Relic.
|
|
158
160
|
*/
|
|
159
161
|
function handleError(segment, req, error) {
|
|
160
162
|
if (req.listenerCount('error') > 0) {
|
|
@@ -171,10 +173,10 @@ function handleError(segment, req, error) {
|
|
|
171
173
|
/**
|
|
172
174
|
* Ties the response object to the request segment.
|
|
173
175
|
*
|
|
174
|
-
* @param {
|
|
175
|
-
* @param {string} hostname
|
|
176
|
-
* @param {http.ClientRequest
|
|
177
|
-
* @param {http.IncomingMessage
|
|
176
|
+
* @param {object} segment TraceSegment instance
|
|
177
|
+
* @param {string} hostname host of the HTTP request
|
|
178
|
+
* @param {object} req http.ClientRequest
|
|
179
|
+
* @param {object} res http.IncomingMessage
|
|
178
180
|
*/
|
|
179
181
|
function handleResponse(segment, hostname, req, res) {
|
|
180
182
|
// Add response attributes for spans
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 42] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
8
10
|
const shimmer = require('../../shimmer')
|
|
9
11
|
const logger = require('../../logger').child({ component: 'http' })
|
|
10
12
|
const recordWeb = require('../../metrics/recorders/http')
|
|
@@ -243,10 +245,11 @@ function wrapResponseEnd(agent, proto) {
|
|
|
243
245
|
}
|
|
244
246
|
|
|
245
247
|
// If an error happened, add it to the aggregator.
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
if (
|
|
249
|
+
txInfo.error &&
|
|
250
|
+
(!txInfo.errorHandled || urltils.isError(agent.config, this.statusCode))
|
|
251
|
+
) {
|
|
252
|
+
agent.errors.add(txInfo.transaction, txInfo.error)
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
// End all the segments leading up to and including this one.
|
|
@@ -479,8 +482,7 @@ module.exports = function initialize(agent, http, moduleName) {
|
|
|
479
482
|
args[1] = agent.tracer.bindFunction(args[1], segment, true)
|
|
480
483
|
}
|
|
481
484
|
|
|
482
|
-
|
|
483
|
-
return sock
|
|
485
|
+
return agent.tracer.bindFunction(original, segment, true).apply(this, args)
|
|
484
486
|
}
|
|
485
487
|
}
|
|
486
488
|
)
|
|
@@ -494,7 +496,7 @@ module.exports = function initialize(agent, http, moduleName) {
|
|
|
494
496
|
* @param {string} header - The raw X-NewRelic-Synthetics header
|
|
495
497
|
* @param {string} encKey - Encoding key handed down from the server
|
|
496
498
|
* @param {Array.<number>} trustedIds - Array of accounts to trust the header from.
|
|
497
|
-
* @param {
|
|
499
|
+
* @param {object} transaction - Where the synthetics data is attached to.
|
|
498
500
|
*/
|
|
499
501
|
function handleSyntheticsHeader(header, encKey, trustedIds, transaction) {
|
|
500
502
|
const synthData = parseSyntheticsHeader(header, encKey, trustedIds)
|
|
@@ -512,7 +514,7 @@ function handleSyntheticsHeader(header, encKey, trustedIds, transaction) {
|
|
|
512
514
|
* @param {string} header - The raw X-NewRelic-Synthetics header
|
|
513
515
|
* @param {string} encKey - Encoding key handed down from the server
|
|
514
516
|
* @param {Array.<number>} trustedIds - Array of accounts to trust the header from.
|
|
515
|
-
* @
|
|
517
|
+
* @returns {object | null} - On successful parse and verification an object of
|
|
516
518
|
* synthetics data is returned, otherwise null is
|
|
517
519
|
* returned.
|
|
518
520
|
*/
|
|
@@ -148,9 +148,7 @@ function wrapMiddleware(shim, middleware, name, route) {
|
|
|
148
148
|
const segmentName = `onRequest/${name}`
|
|
149
149
|
const spec = buildMiddlewareSpecForMiddlewareFunction(shim, segmentName, route)
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return newMiddlewareFunction
|
|
151
|
+
return shim.recordMiddleware(middleware, spec)
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
/**
|
|
@@ -78,8 +78,10 @@ function wrapStart(shim, original) {
|
|
|
78
78
|
segment.addAttribute('grpc.statusCode', code)
|
|
79
79
|
segment.addAttribute('grpc.statusText', details)
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const agent = shim.agent
|
|
82
|
+
const config = agent.config
|
|
83
|
+
|
|
84
|
+
if (shouldTrackError(code, config)) {
|
|
83
85
|
shim.agent.errors.add(segment.transaction, details)
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -184,9 +186,10 @@ function wrapRegister(shim, original) {
|
|
|
184
186
|
|
|
185
187
|
function instrumentEventListeners(stream, transaction) {
|
|
186
188
|
const agent = shim.agent
|
|
189
|
+
const config = agent.config
|
|
187
190
|
stream.call.once('callEnd', (statusCode) => {
|
|
188
191
|
transaction.trace.attributes.addAttribute(DESTINATION, 'response.status', statusCode)
|
|
189
|
-
if (statusCode
|
|
192
|
+
if (shouldTrackError(statusCode, config)) {
|
|
190
193
|
const status = constants.Status[statusCode]
|
|
191
194
|
const error = new Error(`gRPC status code ${statusCode}: ${status}`)
|
|
192
195
|
agent.errors.add(transaction, error)
|
|
@@ -202,6 +205,14 @@ function wrapRegister(shim, original) {
|
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
|
|
208
|
+
function shouldTrackError(statusCode, config) {
|
|
209
|
+
return (
|
|
210
|
+
statusCode > 0 &&
|
|
211
|
+
config.grpc.record_errors &&
|
|
212
|
+
!config.grpc.ignore_status_codes.includes(statusCode)
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
205
216
|
module.exports = function instrument(shim) {
|
|
206
217
|
const genericShim = shim.makeSpecializedShim(shim.GENERIC, 'call-stream')
|
|
207
218
|
const callStream = genericShim.require('./build/src/call-stream')
|
|
@@ -21,6 +21,11 @@ function wrapKeys(metacall) {
|
|
|
21
21
|
* Thanks to Hernan Silberman!
|
|
22
22
|
*
|
|
23
23
|
* instrument the memcached driver to intercept calls and keep stats on them.
|
|
24
|
+
*
|
|
25
|
+
* @param agent
|
|
26
|
+
* @param memcached
|
|
27
|
+
* @param moduleName
|
|
28
|
+
* @param shim
|
|
24
29
|
*/
|
|
25
30
|
module.exports = function initialize(agent, memcached, moduleName, shim) {
|
|
26
31
|
const proto = memcached && memcached.prototype
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
|
+
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 18] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
7
10
|
const { CURSOR_OPS, COLLECTION_OPS, DB_OPS } = require('./constants')
|
|
8
11
|
const common = module.exports
|
|
9
12
|
common.NR_ATTRS = Symbol('NR_ATTRS')
|
|
@@ -11,7 +11,7 @@ const { captureAttributesOnStarted, makeQueryDescFunc } = require('./common')
|
|
|
11
11
|
* parser used to grab the collection and operation
|
|
12
12
|
* from a running query
|
|
13
13
|
*
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {object} operation
|
|
15
15
|
*/
|
|
16
16
|
function queryParser(operation) {
|
|
17
17
|
let collection = this.collectionName || 'unknown'
|
|
@@ -29,7 +29,7 @@ function queryParser(operation) {
|
|
|
29
29
|
* add necessary attributes to segments
|
|
30
30
|
*
|
|
31
31
|
* @param {Shim} shim
|
|
32
|
-
* @param {
|
|
32
|
+
* @param {object} mongodb resolved package
|
|
33
33
|
*/
|
|
34
34
|
module.exports = function instrument(shim, mongodb) {
|
|
35
35
|
shim.setParser(queryParser)
|
|
@@ -65,6 +65,9 @@ module.exports = function instrument(shim, mongodb) {
|
|
|
65
65
|
* Iterate over permutations and properly
|
|
66
66
|
* wrap depending on the `recordDesc` above
|
|
67
67
|
* See: https://github.com/mongodb/node-mongodb-native/blob/v3.0.5/lib/collection.js#L384
|
|
68
|
+
*
|
|
69
|
+
* @param _
|
|
70
|
+
* @param modules
|
|
68
71
|
*/
|
|
69
72
|
function instrumentModules(_, modules) {
|
|
70
73
|
modules.forEach((module) => {
|
|
@@ -80,7 +83,7 @@ module.exports = function instrument(shim, mongodb) {
|
|
|
80
83
|
* if it needs to be wrapped as an operation or query
|
|
81
84
|
*
|
|
82
85
|
* @param {string} objectName name of class getting instrumented
|
|
83
|
-
* @param {
|
|
86
|
+
* @param {object} object reference to the class getting instrumented
|
|
84
87
|
* @param {Define} meta describes the methods and if they are callbacks
|
|
85
88
|
* promises, and return values
|
|
86
89
|
*/
|
|
@@ -25,7 +25,7 @@ module.exports = initialize
|
|
|
25
25
|
* based on version of mongodb
|
|
26
26
|
*
|
|
27
27
|
* @param {Agent} agent
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {object} mongodb resolved package
|
|
29
29
|
* @param {string} moduleName name of module
|
|
30
30
|
* @param {Shim} shim
|
|
31
31
|
*/
|
|
@@ -36,7 +36,7 @@ class NrTransport extends TransportStream {
|
|
|
36
36
|
*/
|
|
37
37
|
log(logLine, callback) {
|
|
38
38
|
const metadata = this.agent.getLinkingMetadata()
|
|
39
|
-
const formattedLine = reformatLogLine(logLine, metadata
|
|
39
|
+
const formattedLine = reformatLogLine(logLine, metadata)
|
|
40
40
|
this.agent.logs.add(formattedLine)
|
|
41
41
|
callback()
|
|
42
42
|
}
|
|
@@ -52,10 +52,9 @@ module.exports = NrTransport
|
|
|
52
52
|
*
|
|
53
53
|
* @param {object} logLine log line
|
|
54
54
|
* @param {object} metadata linking metadata
|
|
55
|
-
* @param {object} agent NR agent
|
|
56
55
|
* @returns {object} copy of log line with NR linking metadata
|
|
57
56
|
*/
|
|
58
|
-
function reformatLogLine(logLine, metadata
|
|
57
|
+
function reformatLogLine(logLine, metadata) {
|
|
59
58
|
// Add the metadata to a copy of the logLine
|
|
60
59
|
const formattedLine = Object.assign({}, logLine, metadata)
|
|
61
60
|
|
|
@@ -63,7 +62,7 @@ function reformatLogLine(logLine, metadata, agent) {
|
|
|
63
62
|
reformatError(formattedLine)
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
reformatTimestamp(formattedLine
|
|
65
|
+
reformatTimestamp(formattedLine)
|
|
67
66
|
|
|
68
67
|
return formattedLine
|
|
69
68
|
}
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 101] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
8
10
|
const util = require('util')
|
|
9
11
|
const properties = require('../util/properties')
|
|
10
12
|
const shimmer = require('../shimmer')
|
|
11
13
|
const symbols = require('../symbols')
|
|
14
|
+
const ANONYMOUS = '<anonymous>'
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* @namespace Library.Spec
|
|
@@ -144,7 +147,7 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
144
147
|
cnstrctArgs.unshift(Promise) // `unshift` === `push_front`
|
|
145
148
|
promise = new (Promise.bind.apply(Promise, cnstrctArgs))()
|
|
146
149
|
} else {
|
|
147
|
-
const segmentName = 'Promise ' + (executor.name ||
|
|
150
|
+
const segmentName = 'Promise ' + (executor.name || ANONYMOUS)
|
|
148
151
|
const context = {
|
|
149
152
|
promise: null,
|
|
150
153
|
self: null,
|
|
@@ -215,12 +218,12 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
215
218
|
args: null
|
|
216
219
|
}
|
|
217
220
|
if (!this[symbols.context]) {
|
|
218
|
-
const segmentName = 'Promise ' + executor.name ||
|
|
221
|
+
const segmentName = 'Promise ' + executor.name || ANONYMOUS
|
|
219
222
|
const segment = _createSegment(segmentName)
|
|
220
223
|
Contextualizer.link(null, this, segment, spec.useFinally)
|
|
221
224
|
}
|
|
222
225
|
const args = [].slice.call(arguments)
|
|
223
|
-
args[0] = wrapExecutorContext(context
|
|
226
|
+
args[0] = wrapExecutorContext(context)
|
|
224
227
|
const ret = caller.apply(this, args)
|
|
225
228
|
|
|
226
229
|
// Bluebird catches executor errors and auto-rejects when it catches them,
|
|
@@ -339,7 +342,7 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
339
342
|
}
|
|
340
343
|
|
|
341
344
|
let promSegment = next[symbols.context].getSegment()
|
|
342
|
-
const segmentName = segmentNamePrefix + (fn.name ||
|
|
345
|
+
const segmentName = segmentNamePrefix + (fn.name || ANONYMOUS)
|
|
343
346
|
const segment = _createSegment(segmentName, promSegment)
|
|
344
347
|
if (segment && segment !== promSegment) {
|
|
345
348
|
next[symbols.context].setSegment(segment)
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
+
/* eslint sonarjs/cognitive-complexity: ["error", 53] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
|
|
9
|
+
|
|
8
10
|
const cat = require('../util/cat')
|
|
9
11
|
const recordExternal = require('../metrics/recorders/http_external')
|
|
10
12
|
const logger = require('../logger').child({ component: 'undici' })
|
package/lib/metrics/mapper.js
CHANGED
|
@@ -67,9 +67,8 @@ MetricMapper.prototype.load = function load(raw) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* @param {
|
|
71
|
-
* @param {
|
|
72
|
-
*
|
|
70
|
+
* @param {string} name The metric name.
|
|
71
|
+
* @param {string} scope The scope for the metric, if set.
|
|
73
72
|
* @returns {object} Either a metric spec based on the parameters, or the
|
|
74
73
|
* server-sent ID.
|
|
75
74
|
*/
|
|
@@ -43,9 +43,7 @@ class MetricAggregator extends Aggregator {
|
|
|
43
43
|
const beginSeconds = this._metrics.started * FROM_MILLIS
|
|
44
44
|
const endSeconds = Date.now() * FROM_MILLIS
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return payload
|
|
46
|
+
return [this.runId, beginSeconds, endSeconds, this._metrics.toJSON()]
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
_getMergeData() {
|