newrelic 13.3.3 → 13.5.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 +54 -0
- package/THIRD_PARTY_NOTICES.md +11 -11
- package/api.js +1 -1
- package/esm-loader.mjs +2 -2
- package/lib/agent.js +2 -2
- package/lib/aggregators/event-aggregator.js +0 -2
- package/lib/attributes.js +6 -6
- package/lib/collector/api.js +1 -1
- package/lib/collector/facts.js +1 -1
- package/lib/collector/http-agents.js +2 -2
- package/lib/collector/parse-response.js +9 -12
- package/lib/collector/remote-method.js +4 -5
- package/lib/collector/serverless.js +1 -1
- package/lib/config/build-instrumentation-config.js +13 -3
- package/lib/config/default.js +21 -10
- package/lib/config/formatters.js +5 -6
- package/lib/config/index.js +37 -24
- package/lib/harvester.js +1 -1
- package/lib/header-processing.js +3 -3
- package/lib/health-reporter.js +2 -2
- package/lib/instrumentation/@node-redis/client.js +1 -1
- package/lib/instrumentation/@prisma/client.js +1 -1
- package/lib/instrumentation/aws-sdk/util.js +3 -3
- package/lib/instrumentation/aws-sdk/v2/instrumentation-helper.js +2 -2
- package/lib/instrumentation/aws-sdk/v3/bedrock.js +5 -5
- package/lib/instrumentation/aws-sdk/v3/common.js +14 -14
- package/lib/instrumentation/aws-sdk/v3/dynamodb.js +13 -13
- package/lib/instrumentation/aws-sdk/v3/lambda.js +3 -3
- package/lib/instrumentation/aws-sdk/v3/sns.js +12 -12
- package/lib/instrumentation/aws-sdk/v3/sqs.js +9 -9
- package/lib/instrumentation/core/http-outbound.js +1 -2
- package/lib/instrumentation/fastify/spec-builders.js +9 -29
- package/lib/instrumentation/fastify.js +23 -94
- package/lib/instrumentation/kafkajs/consumer.js +1 -1
- package/lib/instrumentation/koa/instrumentation.js +1 -1
- package/lib/instrumentation/langchain/runnable.js +1 -1
- package/lib/instrumentation/memcached.js +4 -4
- package/lib/instrumentation/mongodb.js +2 -2
- package/lib/instrumentation/nextjs/next-server.js +1 -3
- package/lib/instrumentation/nextjs/utils.js +2 -2
- package/lib/instrumentation/restify.js +2 -2
- package/lib/instrumentation/when/contextualizer.js +1 -1
- package/lib/instrumentation-descriptor.js +2 -11
- package/lib/instrumentations.js +1 -20
- package/lib/llm-events/aws-bedrock/bedrock-response.js +6 -6
- package/lib/llm-events/aws-bedrock/chat-completion-summary.js +2 -1
- package/lib/llm-events/aws-bedrock/converse-stream-handler.js +1 -1
- package/lib/llm-events/aws-bedrock/stream-handler.js +4 -4
- package/lib/metrics/index.js +2 -2
- package/lib/metrics/normalizer/rule.js +1 -1
- package/lib/metrics/normalizer.js +4 -5
- package/lib/metrics/recorders/database-operation.js +2 -3
- package/lib/metrics/recorders/message-transaction.js +3 -3
- package/lib/metrics/recorders/middleware.js +1 -2
- package/lib/otel/context-manager.js +4 -4
- package/lib/otel/trace-propagator.js +1 -1
- package/lib/otel/traces/segments/database.js +1 -1
- package/lib/otel/traces/utils.js +9 -9
- package/lib/prioritized-attributes.js +2 -2
- package/lib/{adaptive-sampler.js → samplers/adaptive-sampler.js} +8 -0
- package/lib/serverless/aws-lambda.js +4 -4
- package/lib/shim/datastore-shim.js +2 -2
- package/lib/shim/message-shim/consume.js +4 -4
- package/lib/shim/message-shim/subscribe-consume.js +1 -2
- package/lib/shim/promise-shim.js +1 -4
- package/lib/shim/shim.js +14 -29
- package/lib/shim/specs/class.js +3 -3
- package/lib/shim/specs/middleware-mounter.js +2 -2
- package/lib/shim/specs/middleware.js +3 -3
- package/lib/shim/specs/query.js +1 -1
- package/lib/shim/specs/recorder.js +1 -1
- package/lib/shim/specs/wrap.js +2 -2
- package/lib/shim/transaction-shim.js +0 -1
- package/lib/shim/webframework-shim/common.js +2 -4
- package/lib/shim/webframework-shim/index.js +10 -1
- package/lib/shim/webframework-shim/middleware.js +17 -21
- package/lib/shimmer.js +56 -103
- package/lib/spans/span-context.js +1 -1
- package/lib/spans/span-event-aggregator.js +2 -2
- package/lib/spans/span-event.js +6 -5
- package/lib/spans/streaming-span-attributes.js +1 -1
- package/lib/spans/streaming-span-event-aggregator.js +5 -3
- package/lib/spans/streaming-span-event.js +1 -1
- package/lib/stats/index.js +1 -1
- package/lib/subscriber-configs.js +6 -1
- package/lib/subscribers/amqplib/accept-message.js +14 -0
- package/lib/subscribers/amqplib/callback-model.js +39 -0
- package/lib/subscribers/amqplib/channel-model.js +39 -0
- package/lib/subscribers/amqplib/config.js +697 -0
- package/lib/subscribers/amqplib/connect.js +74 -0
- package/lib/subscribers/amqplib/consume.js +54 -0
- package/lib/subscribers/amqplib/get-cb.js +16 -0
- package/lib/subscribers/amqplib/get.js +50 -0
- package/lib/subscribers/amqplib/purge-queue-cb.js +16 -0
- package/lib/subscribers/amqplib/purge-queue.js +37 -0
- package/lib/subscribers/amqplib/send-message.js +44 -0
- package/lib/subscribers/amqplib/send-or-enqueue.js +18 -0
- package/lib/subscribers/amqplib/utils.js +53 -0
- package/lib/subscribers/application-logs.js +1 -1
- package/lib/subscribers/base.js +113 -29
- package/lib/subscribers/cassandra-driver/client-batch.js +49 -0
- package/lib/subscribers/cassandra-driver/client-connect.js +35 -0
- package/lib/subscribers/cassandra-driver/client-each-row.js +36 -0
- package/lib/subscribers/cassandra-driver/client-execute.js +36 -0
- package/lib/subscribers/cassandra-driver/client-shutdown.js +32 -0
- package/lib/subscribers/cassandra-driver/config.js +145 -0
- package/lib/subscribers/cassandra-driver/legacy-client-batch.js +22 -0
- package/lib/subscribers/cassandra-driver/legacy-client-connect.js +22 -0
- package/lib/subscribers/cassandra-driver/legacy-client-each-row.js +22 -0
- package/lib/subscribers/cassandra-driver/legacy-client-execute.js +21 -0
- package/lib/subscribers/cassandra-driver/legacy-client-shutdown.js +32 -0
- package/lib/subscribers/create-config.js +4 -6
- package/lib/subscribers/db-operation.js +12 -0
- package/lib/subscribers/db-query.js +5 -1
- package/lib/subscribers/dc-base.js +89 -0
- package/lib/subscribers/fastify/add-hook.js +46 -0
- package/lib/subscribers/fastify/common.js +121 -0
- package/lib/subscribers/fastify/config.js +39 -0
- package/lib/subscribers/fastify/decorate.js +35 -0
- package/lib/subscribers/fastify/index.js +31 -0
- package/lib/subscribers/mcp-sdk/client-request.js +1 -1
- package/lib/subscribers/mcp-sdk/config.js +2 -0
- package/lib/subscribers/message-consumer.js +146 -0
- package/lib/subscribers/message-producer.js +60 -0
- package/lib/subscribers/meta-subscriber.js +69 -0
- package/lib/subscribers/openai/base.js +27 -1
- package/lib/subscribers/openai/chat.js +0 -27
- package/lib/subscribers/openai/config.js +3 -3
- package/lib/subscribers/openai/utils.js +10 -11
- package/lib/subscribers/pg/config.js +91 -0
- package/lib/subscribers/pg/connect.js +28 -0
- package/lib/subscribers/pg/native-connect.js +25 -0
- package/lib/subscribers/pg/native-query.js +22 -0
- package/lib/subscribers/pg/query.js +66 -0
- package/lib/subscribers/pino/index.js +2 -2
- package/lib/subscribers/propagation.js +23 -0
- package/lib/subscribers/undici/config.js +11 -0
- package/lib/subscribers/undici/index.js +195 -0
- package/lib/synthetics.js +4 -4
- package/lib/timer.js +1 -1
- package/lib/tracking-packages.js +25 -0
- package/lib/transaction/dt-payload.js +1 -1
- package/lib/transaction/handle.js +8 -9
- package/lib/transaction/index.js +25 -21
- package/lib/transaction/name-state.js +11 -11
- package/lib/transaction/trace/segment.js +3 -4
- package/lib/transaction/tracer/index.js +1 -1
- package/lib/util/attribute-types.js +1 -1
- package/lib/util/byte-limit.js +1 -1
- package/lib/util/cat.js +13 -13
- package/lib/util/flatten.js +2 -3
- package/lib/util/is-absolute-path.js +1 -1
- package/lib/util/is-string.js +15 -0
- package/lib/util/llm-utils.js +3 -3
- package/lib/util/logger.js +8 -8
- package/lib/util/stream-sink.js +1 -1
- package/lib/utilization/docker-info.js +4 -3
- package/lib/utilization/ecs-info.js +1 -1
- package/lib/w3c/traceparent.js +3 -3
- package/lib/w3c/tracestate.js +1 -1
- package/package.json +2 -2
- package/lib/instrumentation/amqplib/amqplib.js +0 -122
- package/lib/instrumentation/amqplib/channel-model.js +0 -124
- package/lib/instrumentation/amqplib/channel.js +0 -72
- package/lib/instrumentation/amqplib/nr-hooks.js +0 -21
- package/lib/instrumentation/amqplib/utils.js +0 -143
- package/lib/instrumentation/cassandra-driver.js +0 -131
- package/lib/instrumentation/pg.js +0 -137
- package/lib/instrumentation/undici.js +0 -229
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
8
|
class AdaptiveSampler {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {object} opts Sampler options.
|
|
12
|
+
* @param {Agent} opts.agent - The New Relic agent instance.
|
|
13
|
+
* @param {number} opts.period - The time period over which to collect samples (ms).
|
|
14
|
+
* @param {number} opts.target - The target number of samples (transactions) to collect.
|
|
15
|
+
* @param {boolean} opts.serverless - Indicates if the environment is serverless.
|
|
16
|
+
*/
|
|
9
17
|
constructor(opts) {
|
|
10
18
|
this._serverless = opts.serverless
|
|
11
19
|
this._seen = 0
|
|
@@ -105,8 +105,8 @@ class AwsLambda {
|
|
|
105
105
|
/**
|
|
106
106
|
* Response-streaming handlers are identified by symbol properties on the function.
|
|
107
107
|
* We propagate any symbols if they're present, so that the handler keeps its signatue for any AWS features that rely on symbols
|
|
108
|
-
* @param handler
|
|
109
|
-
* @param nrHandler
|
|
108
|
+
* @param {object} handler original handler
|
|
109
|
+
* @param {object} nrHandler our copy of the handler
|
|
110
110
|
*/
|
|
111
111
|
propagateSymbols(handler, nrHandler) {
|
|
112
112
|
for (const symbol of Object.getOwnPropertySymbols(handler)) {
|
|
@@ -191,7 +191,7 @@ class AwsLambda {
|
|
|
191
191
|
* **Note**: AWS doesn't support response streaming with API gateway invoked lambdas.
|
|
192
192
|
* This means we do not handle that as it would require intercepting the stream to parse
|
|
193
193
|
* the response code and headers.
|
|
194
|
-
* @param {...any} args
|
|
194
|
+
* @param {...any} args Original arguments
|
|
195
195
|
*/
|
|
196
196
|
function wrappedStreamHandler(...args) {
|
|
197
197
|
const transaction = shim.tracer.getTransaction()
|
|
@@ -229,7 +229,7 @@ class AwsLambda {
|
|
|
229
229
|
* adds handlers if api gateway to wrap request/response
|
|
230
230
|
* wraps the callback(if present), wraps the context `done`, `succeed`, `fail methods`, intercepts promise
|
|
231
231
|
* and properly ends transaction
|
|
232
|
-
* @param {...any} args
|
|
232
|
+
* @param {...any} args Original arguments
|
|
233
233
|
*/
|
|
234
234
|
function wrappedHandler(...args) {
|
|
235
235
|
const transaction = shim.tracer.getTransaction()
|
|
@@ -500,7 +500,7 @@ function captureInstanceAttributes(host, port, database) {
|
|
|
500
500
|
/**
|
|
501
501
|
* Parses the database name from a `USE` SQL query.
|
|
502
502
|
*
|
|
503
|
-
* @
|
|
503
|
+
* @this DatastoreShim
|
|
504
504
|
* @param {string} query - The SQL query to parse the database name from.
|
|
505
505
|
* @returns {?string} The name of the database if it could be parsed, otherwise
|
|
506
506
|
* `null`.
|
|
@@ -584,7 +584,7 @@ function _recordQuery(suffix, nodule, properties, querySpec) {
|
|
|
584
584
|
* @param {object} params to function
|
|
585
585
|
* @param {QuerySpec|OperationSpec} params.spec spec for the given shim method
|
|
586
586
|
* @param {DatastoreShim} params.shim instance of shim
|
|
587
|
-
* @param {
|
|
587
|
+
* @param {Function} params.fn function being instrumented
|
|
588
588
|
* @param {string} params.fnName name of function being instrumented
|
|
589
589
|
* @param {Array} params.args arguments to function being instrumented
|
|
590
590
|
* @returns {QuerySpec|OperationSpec} compiled spec
|
|
@@ -19,9 +19,9 @@ module.exports = createRecorder
|
|
|
19
19
|
* @param {Function} params.fn consumer function
|
|
20
20
|
* @param {string} params.fnName name of function
|
|
21
21
|
* @param {Array} params.args arguments passed to original consume function
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {
|
|
24
|
-
* @returns {
|
|
22
|
+
* @param {object} params.ctx this binding of the original function
|
|
23
|
+
* @param {MessageSpec} params.spec spec for the wrapped consume function
|
|
24
|
+
* @returns {MessageSpec} new spec
|
|
25
25
|
*/
|
|
26
26
|
function updateSpecFromArgs({ shim, fn, fnName, args, spec, ctx }) {
|
|
27
27
|
let msgDesc = null
|
|
@@ -49,7 +49,7 @@ function updateSpecFromArgs({ shim, fn, fnName, args, spec, ctx }) {
|
|
|
49
49
|
* @param {MessageShim} params.shim instance of shim
|
|
50
50
|
* @param {Function} params.fn function that is being wrapped
|
|
51
51
|
* @param {string} params.fnName name of function
|
|
52
|
-
* @param params.args
|
|
52
|
+
* @param {Array} params.args arguments passed to original consume function
|
|
53
53
|
* @param {specs.MessageSpec} params.spec spec for the wrapped consume function
|
|
54
54
|
* @returns {specs.MessageSpec} updated spec with logic to name segment and apply the genericRecorder
|
|
55
55
|
*/
|
|
@@ -37,8 +37,7 @@ function _nameMessageTransaction(shim, msgDesc) {
|
|
|
37
37
|
* @param {MessageShim} params.shim instance of shim
|
|
38
38
|
* @param {Function} params.fn subscriber function
|
|
39
39
|
* @param {specs.MessageSubscribeSpec} params.spec spec for subscriber
|
|
40
|
-
* @param params.name
|
|
41
|
-
* @param {boolean} params.destNameIsArg flag to state if destination is an argument
|
|
40
|
+
* @param {string} params.name function name
|
|
42
41
|
* @returns {Function} wrapped subscribe function
|
|
43
42
|
*/
|
|
44
43
|
function createSubscriberWrapper({ shim, fn, spec, name }) {
|
package/lib/shim/promise-shim.js
CHANGED
|
@@ -366,9 +366,7 @@ function _wrapExecutorContext(shim, args) {
|
|
|
366
366
|
|
|
367
367
|
/**
|
|
368
368
|
*
|
|
369
|
-
* @param {
|
|
370
|
-
* @param {Function} reject function of promise
|
|
371
|
-
* @param {...any} args
|
|
369
|
+
* @param {object} args contains the `resolve` and `reject` functions of a promise
|
|
372
370
|
*/
|
|
373
371
|
function contextExporter(...args) {
|
|
374
372
|
const [resolve, reject] = args
|
|
@@ -384,7 +382,6 @@ function _wrapExecutorContext(shim, args) {
|
|
|
384
382
|
* @param {object} context context object
|
|
385
383
|
* @param {Function} fn function that is wrapped
|
|
386
384
|
* @returns {Function} wrapped function
|
|
387
|
-
* @private
|
|
388
385
|
*/
|
|
389
386
|
function _wrapResolver(context, fn) {
|
|
390
387
|
return function wrappedResolveReject(val) {
|
package/lib/shim/shim.js
CHANGED
|
@@ -242,12 +242,12 @@ Shim.prototype[symbols.unwrap] = unwrapAll
|
|
|
242
242
|
*/
|
|
243
243
|
|
|
244
244
|
/**
|
|
245
|
+
* Measures all the necessary metrics for the given segment. This functionality
|
|
246
|
+
* is meant to be used by Shim subclasses; instrumentations should never create
|
|
247
|
+
* their own recorders.
|
|
248
|
+
*
|
|
245
249
|
* @private
|
|
246
250
|
* @callback MetricFunction
|
|
247
|
-
* @summary
|
|
248
|
-
* Measures all the necessary metrics for the given segment. This functionality
|
|
249
|
-
* is meant to be used by Shim subclasses, instrumentations should never create
|
|
250
|
-
* their own recorders.
|
|
251
251
|
* @param {TraceSegment} segment - The segment to record.
|
|
252
252
|
* @param {string} [scope] - The scope of the recording.
|
|
253
253
|
*/
|
|
@@ -1075,7 +1075,7 @@ function bindCallbackSegment(spec, args, cbIdx, parentSegment) {
|
|
|
1075
1075
|
* It will also call an after hook with the arguments passed to callback
|
|
1076
1076
|
*
|
|
1077
1077
|
* @private
|
|
1078
|
-
* @param {
|
|
1078
|
+
* @param {object} params to function
|
|
1079
1079
|
* @param {Shim} params.shim instance of shim
|
|
1080
1080
|
* @param {Array | object} params.args
|
|
1081
1081
|
* The arguments array to pull the cb from.
|
|
@@ -1239,7 +1239,7 @@ function applyContext({ func, context, full, boundThis, args, inContextCB }) {
|
|
|
1239
1239
|
this.logger.trace('Applying segment %s', segment.name)
|
|
1240
1240
|
|
|
1241
1241
|
/**
|
|
1242
|
-
*
|
|
1242
|
+
* Callback to be run in the context of the segment.
|
|
1243
1243
|
*/
|
|
1244
1244
|
function runInContextCb() {
|
|
1245
1245
|
if (typeof inContextCB === 'function') {
|
|
@@ -1453,8 +1453,7 @@ function isPromise(obj) {
|
|
|
1453
1453
|
* promise or async function
|
|
1454
1454
|
*
|
|
1455
1455
|
* @memberof Shim.prototype
|
|
1456
|
-
* @param fn
|
|
1457
|
-
* @param (function) function to test if async
|
|
1456
|
+
* @param {Function} fn function to test if async
|
|
1458
1457
|
* @returns {boolean} True if the function is an async function
|
|
1459
1458
|
*/
|
|
1460
1459
|
function isAsyncFunction(fn) {
|
|
@@ -1871,8 +1870,8 @@ function _makeBindWrapper(shim, func, context, full) {
|
|
|
1871
1870
|
* (i.e. `bindRowCallbackSegment` for `rowCallback`), but will fall back to the
|
|
1872
1871
|
* generic callback binding method, `bindCallbackSegment`, otherwise.
|
|
1873
1872
|
*
|
|
1874
|
-
* @this *
|
|
1875
1873
|
* @private
|
|
1874
|
+
* @this *
|
|
1876
1875
|
* @param {Shim} shim
|
|
1877
1876
|
* The shim performing this binding.
|
|
1878
1877
|
* @param {Function} fn
|
|
@@ -2129,7 +2128,7 @@ function _es5WrapClass(shim, Base, fnName, spec, args) {
|
|
|
2129
2128
|
/**
|
|
2130
2129
|
* Wraps the es5 class in a function
|
|
2131
2130
|
*
|
|
2132
|
-
* @param {...any} cnstrctArgs
|
|
2131
|
+
* @param {...any} cnstrctArgs class constructor arguments
|
|
2133
2132
|
* @returns {Function|undefined} a function if not already wrapped in WrappedClass
|
|
2134
2133
|
*/
|
|
2135
2134
|
function WrappedClass(...cnstrctArgs) {
|
|
@@ -2162,28 +2161,14 @@ function _es5WrapClass(shim, Base, fnName, spec, args) {
|
|
|
2162
2161
|
}
|
|
2163
2162
|
|
|
2164
2163
|
/**
|
|
2165
|
-
*
|
|
2166
|
-
*
|
|
2167
|
-
*
|
|
2168
|
-
* updates those parameters names to be prefixed by `request.parameters.route`. This is to avoid collision with reserved
|
|
2169
|
-
* attribute names, as parameters used to be blindly stored on router span attributes (see https://github.com/newrelic/node-newrelic/issues/1574)
|
|
2170
|
-
* in addition to being prefixed by `request.parameters`.
|
|
2171
|
-
*
|
|
2172
|
-
* Route parameters used to be stored under `request.parameters.*` just like query parameters pre v10, but we
|
|
2173
|
-
* now prefix with `request.parameter.route` to avoid collision in the event an application uses the same name for a query and route
|
|
2174
|
-
* parameter. Additionally, we now store the same key on the attributes of the base segment, trace, and router span.
|
|
2175
|
-
*
|
|
2176
|
-
* Exported on shim to be used in our Next.js instrumentation, as that instrumentation does not follow the same pattern as all the other
|
|
2177
|
-
* web frameworks we support.
|
|
2164
|
+
* This method is no longer in use. It still exists to avoid crashing
|
|
2165
|
+
* applications. The logic of this method has been integrated into
|
|
2166
|
+
* finalizing a web transaction.
|
|
2178
2167
|
*
|
|
2179
2168
|
* @param {object} params - Object containing route/url parameter key/value pairs
|
|
2180
|
-
* @returns {
|
|
2169
|
+
* @returns {void} method is now stubbed and logic ported into `finalizeWebTransaction`
|
|
2181
2170
|
* @memberof Shim.prototype
|
|
2182
2171
|
*/
|
|
2183
2172
|
function prefixRouteParameters(params) {
|
|
2184
|
-
|
|
2185
|
-
return Object.fromEntries(
|
|
2186
|
-
Object.entries(params).map(([key, value]) => [`request.parameters.route.${key}`, value])
|
|
2187
|
-
)
|
|
2188
|
-
}
|
|
2173
|
+
logger.warnOnce('shim.prefixRouteParameters logic has been moved to when a web transaction ends. This method will be removed in the next upcoming major version v14.0.0.')
|
|
2189
2174
|
}
|
package/lib/shim/specs/class.js
CHANGED
|
@@ -12,14 +12,14 @@ const WrapSpec = require('./wrap')
|
|
|
12
12
|
* @typedef {object} ClassWrapSpecParams
|
|
13
13
|
* @mixes WrapSpecParams
|
|
14
14
|
* @property {boolean} [es6]
|
|
15
|
-
* @property {
|
|
16
|
-
* @property {
|
|
15
|
+
* @property {Function} [pre]
|
|
16
|
+
* @property {Function} [post]
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Pre/post constructor execution hook for wrapping classes.
|
|
21
21
|
*
|
|
22
|
-
* @typedef {
|
|
22
|
+
* @typedef {Function} ConstructorHookFunction
|
|
23
23
|
* @param {Shim} shim
|
|
24
24
|
* The shim performing the wrapping/binding.
|
|
25
25
|
* @param {Function} Base
|
|
@@ -11,7 +11,7 @@ const MiddlewareSpec = require('./middleware')
|
|
|
11
11
|
* Called whenever new middleware are mounted using the instrumented framework,
|
|
12
12
|
* this method should pull out a representation of the mounted path.
|
|
13
13
|
*
|
|
14
|
-
* @typedef {
|
|
14
|
+
* @typedef {Function} RouteParserFunction
|
|
15
15
|
* @param {WebFrameworkShim} shim
|
|
16
16
|
* The shim in use for this instrumentation.
|
|
17
17
|
* @param {Function} fn
|
|
@@ -27,7 +27,7 @@ const MiddlewareSpec = require('./middleware')
|
|
|
27
27
|
* Called for each middleware passed to a mounting method. Should perform the
|
|
28
28
|
* wrapping of the middleware.
|
|
29
29
|
*
|
|
30
|
-
* @typedef {
|
|
30
|
+
* @typedef {Function} MiddlewareWrapperFunction
|
|
31
31
|
* @param {WebFrameworkShim} shim
|
|
32
32
|
* The shim used for instrumentation.
|
|
33
33
|
* @param {Function} middleware
|
|
@@ -11,7 +11,7 @@ const RecorderSpec = require('./recorder')
|
|
|
11
11
|
/**
|
|
12
12
|
* Extracts the request object from the arguments to the middleware function.
|
|
13
13
|
*
|
|
14
|
-
* @typedef {
|
|
14
|
+
* @typedef {Function} RouteRequestFunction
|
|
15
15
|
* @param {WebFrameworkShim} shim The shim used for instrumentation.
|
|
16
16
|
* @param {Function} fn The middleware function.
|
|
17
17
|
* @param {string} fnName The name of the middleware function.
|
|
@@ -23,7 +23,7 @@ const RecorderSpec = require('./recorder')
|
|
|
23
23
|
* Used to wrap functions that users can call to continue to the next
|
|
24
24
|
* middleware.
|
|
25
25
|
*
|
|
26
|
-
* @typedef {
|
|
26
|
+
* @typedef {Function} RouteNextFunction
|
|
27
27
|
* @param {WebFrameworkShim} shim The shim used for instrumentation.
|
|
28
28
|
* @param {Function} fn The middleware function.
|
|
29
29
|
* @param {string} fnName The name of the middleware function.
|
|
@@ -34,7 +34,7 @@ const RecorderSpec = require('./recorder')
|
|
|
34
34
|
/**
|
|
35
35
|
* Extracts the route parameters from the arguments to the middleware function.
|
|
36
36
|
*
|
|
37
|
-
* @typedef {
|
|
37
|
+
* @typedef {Function} RouteParameterFunction
|
|
38
38
|
* @param {WebFrameworkShim} shim The shim used for instrumentation.
|
|
39
39
|
* @param {Function} fn The middleware function.
|
|
40
40
|
* @param {string} fnName The name of the middleware function.
|
package/lib/shim/specs/query.js
CHANGED
|
@@ -10,7 +10,7 @@ const OperationSpec = require('./operation')
|
|
|
10
10
|
/**
|
|
11
11
|
* Retrieves the query argument from an array of arguments.
|
|
12
12
|
*
|
|
13
|
-
* @typedef {
|
|
13
|
+
* @typedef {Function} QueryFunction
|
|
14
14
|
* @param {Shim} shim The shim this function was passed to.
|
|
15
15
|
* @param {Function} func The function being recorded.
|
|
16
16
|
* @param {string} name The name of the function.
|
|
@@ -24,7 +24,7 @@ const WrapSpec = require('./wrap')
|
|
|
24
24
|
* The instrumented function must have been invoked synchronously.
|
|
25
25
|
*
|
|
26
26
|
* @typedef {Function} SpecAfterFunction
|
|
27
|
-
* @param {
|
|
27
|
+
* @param {object} params params to function
|
|
28
28
|
* @param {object} params.shim The shim used to instrument the external library.
|
|
29
29
|
* @param {Function} params.fn The function/method from the external library being
|
|
30
30
|
* instrumented.
|
package/lib/shim/specs/wrap.js
CHANGED
|
@@ -12,7 +12,7 @@ const SegmentSpec = require('./segment')
|
|
|
12
12
|
* @typedef {object} WrapSpecParams
|
|
13
13
|
* @mixes SegmentSpecParams
|
|
14
14
|
* @property {boolean} [matchArity]
|
|
15
|
-
* @property {
|
|
15
|
+
* @property {Function} [wrapper]
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -40,7 +40,7 @@ class WrapSpec extends SegmentSpec {
|
|
|
40
40
|
/**
|
|
41
41
|
* A function that wraps another function.
|
|
42
42
|
*
|
|
43
|
-
* @type {
|
|
43
|
+
* @type {Function}
|
|
44
44
|
*/
|
|
45
45
|
wrapper
|
|
46
46
|
|
|
@@ -19,7 +19,6 @@ const TRANSACTION_TYPES_SET = Transaction.TYPES_SET
|
|
|
19
19
|
* @class
|
|
20
20
|
* @augments Shim
|
|
21
21
|
* @classdesc
|
|
22
|
-
* @param shimName
|
|
23
22
|
* A helper class for working with transactions.
|
|
24
23
|
* @param {Agent} agent - The agent the shim will use.
|
|
25
24
|
* @param {string} moduleName - The name of the module being instrumented.
|
|
@@ -46,8 +46,6 @@ common.getTransactionInfo = function getTransactionInfo(shim, req) {
|
|
|
46
46
|
* Adds the given error to the transaction information if it is actually an error.
|
|
47
47
|
*
|
|
48
48
|
* @private
|
|
49
|
-
* @param {WebFrameworkShim} shim
|
|
50
|
-
* The shim used for this web framework.
|
|
51
49
|
* @param {TransactionInfo} txInfo
|
|
52
50
|
* The transaction context information for the request.
|
|
53
51
|
* @param {*} err
|
|
@@ -73,8 +71,8 @@ common.isError = function isError(shim, err) {
|
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
|
-
* @param shim
|
|
77
|
-
* @param req
|
|
74
|
+
* @param {object} shim instance
|
|
75
|
+
* @param {object} req request
|
|
78
76
|
*/
|
|
79
77
|
common.makeGetReq = function makeGetReq(shim, req) {
|
|
80
78
|
return function getReqFromArgs(shim, fn, name, args) {
|
|
@@ -339,12 +339,21 @@ function savePossibleTransactionName(req) {
|
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Predicate used to determine whether a middleware invocation constitutes a response.
|
|
344
|
+
*
|
|
345
|
+
* @typedef {Function} ResponsePredicate
|
|
346
|
+
* @param {object[]} args - The arguments passed into the middleware.
|
|
347
|
+
* @param {object} res - The value returned from the middleware (if any).
|
|
348
|
+
* @returns {boolean} True if the invocation should be considered a response.
|
|
349
|
+
*/
|
|
350
|
+
|
|
342
351
|
/**
|
|
343
352
|
* Sets a function to call with the result of a middleware to determine if it has
|
|
344
353
|
* responded.
|
|
345
354
|
*
|
|
346
355
|
* @memberof WebFrameworkShim.prototype
|
|
347
|
-
* @param {
|
|
356
|
+
* @param {ResponsePredicate} pred
|
|
348
357
|
* Function which should return true if the object passed to it is considered
|
|
349
358
|
* a response.
|
|
350
359
|
*/
|
|
@@ -51,8 +51,10 @@ function getRoute(spec, shim) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Retrieves the parameters from the spec.params
|
|
55
|
-
*
|
|
54
|
+
* Retrieves the parameters from the spec.params.
|
|
55
|
+
* When a `transaction.finalizeNameFromWeb` is called, it takes these params
|
|
56
|
+
* and prefixes `request.parameters.route.` to every route param.
|
|
57
|
+
* Query params are handled in lib/transaction/index.js#initializeWeb
|
|
56
58
|
*
|
|
57
59
|
* @private
|
|
58
60
|
* @param {object} params object passed to fn
|
|
@@ -66,12 +68,9 @@ function getRoute(spec, shim) {
|
|
|
66
68
|
*/
|
|
67
69
|
function copyParams({ spec, shim, fn, fnName, args, req }) {
|
|
68
70
|
// Copy over route parameters onto the transaction root.
|
|
69
|
-
|
|
71
|
+
return shim.agent.config.high_security
|
|
70
72
|
? null
|
|
71
73
|
: spec.params.call(this, shim, fn, fnName, args, req)
|
|
72
|
-
|
|
73
|
-
// Route parameters are handled here, query parameters are handled in lib/transaction/index.js#finalizeNameFromWeb as part of finalization
|
|
74
|
-
return shim.prefixRouteParameters(params)
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
/**
|
|
@@ -81,15 +80,14 @@ function copyParams({ spec, shim, fn, fnName, args, req }) {
|
|
|
81
80
|
* @param {object} params object passed to fn
|
|
82
81
|
* @param {object} params.txInfo transaction
|
|
83
82
|
* @param {object} params.typeDetails metadata about the middleware type
|
|
84
|
-
* @param {Shim} params.shim instance of shim
|
|
85
83
|
* @param {string} params.metricName metric name for middleware function
|
|
86
84
|
* @returns {Function} recorder for middleware type
|
|
87
85
|
*/
|
|
88
|
-
function constructRecorder({ txInfo, typeDetails,
|
|
86
|
+
function constructRecorder({ txInfo, typeDetails, metricName }) {
|
|
89
87
|
let recorder = null
|
|
90
88
|
if (typeDetails.record) {
|
|
91
89
|
const stackPath = txInfo.transaction.nameState.getPath() || ''
|
|
92
|
-
recorder = makeMiddlewareRecorder(
|
|
90
|
+
recorder = makeMiddlewareRecorder(metricName + '/' + stackPath)
|
|
93
91
|
}
|
|
94
92
|
return recorder
|
|
95
93
|
}
|
|
@@ -166,7 +164,7 @@ function middlewareWithCallbackRecorder({ spec, typeDetails, metricName, isError
|
|
|
166
164
|
txInfo.transaction.nameState.appendPath(route, params)
|
|
167
165
|
}
|
|
168
166
|
|
|
169
|
-
const recorder = constructRecorder({ txInfo, typeDetails,
|
|
167
|
+
const recorder = constructRecorder({ txInfo, typeDetails, metricName })
|
|
170
168
|
|
|
171
169
|
const segmentName = getSegmentName(metricName, typeDetails, route)
|
|
172
170
|
|
|
@@ -176,7 +174,6 @@ function middlewareWithCallbackRecorder({ spec, typeDetails, metricName, isError
|
|
|
176
174
|
callback: nextWrapper,
|
|
177
175
|
parent: txInfo.segmentStack[txInfo.segmentStack.length - 1],
|
|
178
176
|
recorder,
|
|
179
|
-
parameters: params,
|
|
180
177
|
after: function afterExec({ shim, error }) {
|
|
181
178
|
const errIsError = isError(shim, error)
|
|
182
179
|
if (errIsError) {
|
|
@@ -224,7 +221,7 @@ function middlewareWithPromiseRecorder({ spec, typeDetails, metricName, isErrorW
|
|
|
224
221
|
txInfo.transaction.nameState.appendPath(route, params)
|
|
225
222
|
}
|
|
226
223
|
|
|
227
|
-
const recorder = constructRecorder({ txInfo, typeDetails,
|
|
224
|
+
const recorder = constructRecorder({ txInfo, typeDetails, metricName })
|
|
228
225
|
const nextWrapper = wrapNextHandler({
|
|
229
226
|
shim,
|
|
230
227
|
spec,
|
|
@@ -243,7 +240,6 @@ function middlewareWithPromiseRecorder({ spec, typeDetails, metricName, isErrorW
|
|
|
243
240
|
promise: spec.promise,
|
|
244
241
|
callback: nextWrapper,
|
|
245
242
|
recorder,
|
|
246
|
-
parameters: params,
|
|
247
243
|
after: function afterExec({ shim, error, result }) {
|
|
248
244
|
if (shim._responsePredicate(args, result)) {
|
|
249
245
|
txInfo.transaction.nameState.freeze()
|
|
@@ -331,14 +327,14 @@ module.exports._recordMiddleware = function _recordMiddleware(shim, middleware,
|
|
|
331
327
|
* push the name state if there is a next so that we can safely remove it
|
|
332
328
|
* if context leaves this middleware.
|
|
333
329
|
*
|
|
334
|
-
* @param
|
|
335
|
-
* @param
|
|
336
|
-
* @param
|
|
337
|
-
* @param
|
|
338
|
-
* @param
|
|
339
|
-
* @param
|
|
340
|
-
* @param
|
|
341
|
-
* @param
|
|
330
|
+
* @param {object} params params object
|
|
331
|
+
* @param {Shim} params.shim shim instance
|
|
332
|
+
* @param {object} params.spec middleware spec, should contain a next function
|
|
333
|
+
* @param {string} params.route route
|
|
334
|
+
* @param {Array} params.args arguments
|
|
335
|
+
* @param {boolean} params.isErrorWare is this error ware
|
|
336
|
+
* @param {boolean} params.isPromise is this a promise
|
|
337
|
+
* @param {object} params.txInfo transaction information
|
|
342
338
|
* @private
|
|
343
339
|
*/
|
|
344
340
|
function wrapNextHandler({ shim, spec, route, args, isErrorWare, isPromise, txInfo }) {
|