newrelic 13.4.0 → 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.
Files changed (105) hide show
  1. package/NEWS.md +32 -0
  2. package/api.js +1 -1
  3. package/lib/agent.js +2 -2
  4. package/lib/aggregators/event-aggregator.js +0 -2
  5. package/lib/attributes.js +2 -2
  6. package/lib/collector/api.js +1 -1
  7. package/lib/collector/http-agents.js +2 -2
  8. package/lib/collector/serverless.js +1 -1
  9. package/lib/config/build-instrumentation-config.js +13 -3
  10. package/lib/config/default.js +21 -10
  11. package/lib/config/formatters.js +3 -3
  12. package/lib/config/index.js +33 -20
  13. package/lib/harvester.js +1 -1
  14. package/lib/header-processing.js +3 -3
  15. package/lib/health-reporter.js +2 -2
  16. package/lib/instrumentation/@prisma/client.js +1 -1
  17. package/lib/instrumentation/aws-sdk/util.js +3 -3
  18. package/lib/instrumentation/aws-sdk/v2/instrumentation-helper.js +1 -1
  19. package/lib/instrumentation/aws-sdk/v3/bedrock.js +5 -5
  20. package/lib/instrumentation/aws-sdk/v3/common.js +11 -11
  21. package/lib/instrumentation/aws-sdk/v3/dynamodb.js +10 -10
  22. package/lib/instrumentation/aws-sdk/v3/lambda.js +3 -3
  23. package/lib/instrumentation/aws-sdk/v3/sns.js +7 -7
  24. package/lib/instrumentation/aws-sdk/v3/sqs.js +6 -6
  25. package/lib/instrumentation/fastify/spec-builders.js +3 -23
  26. package/lib/instrumentation/fastify.js +22 -93
  27. package/lib/instrumentation/kafkajs/consumer.js +1 -1
  28. package/lib/instrumentation/koa/instrumentation.js +1 -1
  29. package/lib/instrumentation/langchain/runnable.js +1 -1
  30. package/lib/instrumentation/memcached.js +1 -1
  31. package/lib/instrumentation/nextjs/next-server.js +1 -3
  32. package/lib/instrumentation/nextjs/utils.js +2 -2
  33. package/lib/instrumentation/restify.js +2 -2
  34. package/lib/instrumentation/when/contextualizer.js +1 -1
  35. package/lib/instrumentation-descriptor.js +2 -11
  36. package/lib/instrumentations.js +1 -18
  37. package/lib/llm-events/aws-bedrock/chat-completion-summary.js +2 -1
  38. package/lib/metrics/recorders/database-operation.js +2 -3
  39. package/lib/metrics/recorders/middleware.js +1 -2
  40. package/lib/otel/context-manager.js +3 -3
  41. package/lib/otel/traces/segments/database.js +1 -1
  42. package/lib/otel/traces/utils.js +9 -9
  43. package/lib/{adaptive-sampler.js → samplers/adaptive-sampler.js} +8 -0
  44. package/lib/serverless/aws-lambda.js +2 -2
  45. package/lib/shim/datastore-shim.js +1 -1
  46. package/lib/shim/message-shim/consume.js +3 -3
  47. package/lib/shim/promise-shim.js +1 -2
  48. package/lib/shim/shim.js +12 -26
  49. package/lib/shim/specs/class.js +3 -3
  50. package/lib/shim/specs/middleware-mounter.js +2 -2
  51. package/lib/shim/specs/middleware.js +3 -3
  52. package/lib/shim/specs/query.js +1 -1
  53. package/lib/shim/specs/recorder.js +1 -1
  54. package/lib/shim/specs/wrap.js +2 -2
  55. package/lib/shim/webframework-shim/common.js +2 -2
  56. package/lib/shim/webframework-shim/index.js +10 -1
  57. package/lib/shim/webframework-shim/middleware.js +12 -16
  58. package/lib/shimmer.js +56 -103
  59. package/lib/spans/span-context.js +1 -1
  60. package/lib/spans/span-event.js +1 -1
  61. package/lib/spans/streaming-span-event-aggregator.js +4 -1
  62. package/lib/spans/streaming-span-event.js +1 -1
  63. package/lib/subscriber-configs.js +4 -1
  64. package/lib/subscribers/amqplib/config.js +2 -0
  65. package/lib/subscribers/amqplib/connect.js +2 -2
  66. package/lib/subscribers/amqplib/send-or-enqueue.js +0 -2
  67. package/lib/subscribers/base.js +50 -32
  68. package/lib/subscribers/create-config.js +2 -2
  69. package/lib/subscribers/db-operation.js +12 -0
  70. package/lib/subscribers/dc-base.js +89 -0
  71. package/lib/subscribers/fastify/add-hook.js +46 -0
  72. package/lib/subscribers/fastify/common.js +121 -0
  73. package/lib/subscribers/fastify/config.js +39 -0
  74. package/lib/subscribers/fastify/decorate.js +35 -0
  75. package/lib/subscribers/fastify/index.js +31 -0
  76. package/lib/subscribers/mcp-sdk/client-request.js +1 -1
  77. package/lib/subscribers/mcp-sdk/config.js +2 -0
  78. package/lib/subscribers/openai/utils.js +1 -0
  79. package/lib/subscribers/pg/config.js +91 -0
  80. package/lib/subscribers/pg/connect.js +28 -0
  81. package/lib/subscribers/pg/native-connect.js +25 -0
  82. package/lib/subscribers/pg/native-query.js +22 -0
  83. package/lib/subscribers/pg/query.js +66 -0
  84. package/lib/subscribers/pino/index.js +2 -2
  85. package/lib/subscribers/propagation.js +1 -21
  86. package/lib/subscribers/undici/config.js +11 -0
  87. package/lib/subscribers/undici/index.js +195 -0
  88. package/lib/synthetics.js +4 -4
  89. package/lib/tracking-packages.js +25 -0
  90. package/lib/transaction/dt-payload.js +1 -1
  91. package/lib/transaction/index.js +25 -21
  92. package/lib/transaction/name-state.js +2 -2
  93. package/lib/transaction/trace/segment.js +1 -1
  94. package/lib/transaction/tracer/index.js +1 -1
  95. package/lib/util/cat.js +2 -2
  96. package/lib/util/llm-utils.js +3 -3
  97. package/lib/util/logger.js +3 -3
  98. package/lib/util/stream-sink.js +1 -1
  99. package/lib/utilization/docker-info.js +1 -1
  100. package/lib/utilization/ecs-info.js +1 -1
  101. package/lib/w3c/traceparent.js +2 -2
  102. package/lib/w3c/tracestate.js +1 -1
  103. package/package.json +1 -1
  104. package/lib/instrumentation/pg.js +0 -137
  105. package/lib/instrumentation/undici.js +0 -229
@@ -18,10 +18,10 @@ const InstrumentationDescriptor = require('../../../instrumentation-descriptor')
18
18
  * when command is `PublishCommand`
19
19
  *
20
20
  * @param {Shim} shim instance
21
- * @param {Object} config configuration options
22
- * @param {function} next middleware function
23
- * @param {Object} context context
24
- * @returns {function}
21
+ * @param {object} config configuration options
22
+ * @param {Function} next middleware function
23
+ * @param {object} context context
24
+ * @returns {Function}
25
25
  */
26
26
  function sqsMiddleware(shim, config, next, context) {
27
27
  if (SEND_COMMANDS.includes(context.commandName)) {
@@ -38,10 +38,10 @@ function sqsMiddleware(shim, config, next, context) {
38
38
  * Returns the spec for PublishCommand
39
39
  *
40
40
  * @param {Shim} shim instance
41
- * @param {function} original original middleware function
41
+ * @param {Function} original original middleware function
42
42
  * @param {string} name function name
43
43
  * @param {Array} args to the middleware function
44
- * @returns {Object}
44
+ * @returns {object}
45
45
  */
46
46
  function getSqsSpec(shim, original, name, args) {
47
47
  const [command] = args
@@ -79,10 +79,10 @@ function buildMiddlewareSpecForRouteHandler(shim, path) {
79
79
  * that is actually handling the request, the path is actually left on)
80
80
  *
81
81
  * @param {WebFrameworkShim} shim instance
82
- * @param {function} fn function
82
+ * @param {Function} fn function
83
83
  * @param {string} fnName function name
84
84
  * @param {Array} args arguments
85
- * @param {function} bindSegment the bindSegment function
85
+ * @param {Function} bindSegment the bindSegment function
86
86
  */
87
87
  next: function wrapNext(shim, fn, fnName, args, bindSegment) {
88
88
  const reply = args[1]
@@ -98,26 +98,6 @@ function buildMiddlewareSpecForRouteHandler(shim, path) {
98
98
  })
99
99
  }
100
100
 
101
- /**
102
- * Spec for all Fastify middleware (excluding route handlers)
103
- *
104
- * @param {WebFrameworkShim} shim instance
105
- * @param {string} name metric name for middleware being executed
106
- * @param {number|string|null} route route
107
- * @returns {object} spec for Fastify middleware
108
- */
109
- function buildMiddlewareSpecForMiddlewareFunction(shim, name, route) {
110
- return new MiddlewareSpec({
111
- name,
112
- route,
113
- next: shim.LAST,
114
- params: getParamsFromFastifyRequest,
115
- req: getRequestFromFastify,
116
- type: shim.MIDDLEWARE
117
- })
118
- }
119
-
120
101
  module.exports = {
121
- buildMiddlewareSpecForRouteHandler,
122
- buildMiddlewareSpecForMiddlewareFunction
102
+ buildMiddlewareSpecForRouteHandler
123
103
  }
@@ -7,30 +7,8 @@
7
7
 
8
8
  const semver = require('semver')
9
9
  const {
10
- buildMiddlewareSpecForRouteHandler,
11
- buildMiddlewareSpecForMiddlewareFunction
10
+ buildMiddlewareSpecForRouteHandler
12
11
  } = require('./fastify/spec-builders')
13
- const { MiddlewareMounterSpec } = require('../shim/specs')
14
-
15
- /**
16
- * These are the events that occur during a fastify
17
- * request
18
- * see: https://www.fastify.io/docs/latest/Lifecycle/
19
- *
20
- * Note: preSerialization and onSend happen after the route handler
21
- * executes. `onResponse` does not execute until after the client
22
- * sends the response so it'll never be in scope of the transaction
23
- */
24
- const REQUEST_HOOKS = [
25
- 'onRequest',
26
- 'preParsing',
27
- 'preValidation',
28
- 'preHandler',
29
- 'preSerialization',
30
- 'onSend',
31
- 'onResponse',
32
- 'onError'
33
- ]
34
12
 
35
13
  /**
36
14
  * Sets up fastify route handler
@@ -45,13 +23,14 @@ const REQUEST_HOOKS = [
45
23
  * maintain code
46
24
  *
47
25
  * @param {WebFrameworkShim} shim instance
48
- * @param {Object} fastify Fastify instance
26
+ * @param {object} fastify Fastify instance
49
27
  */
50
- const setupRouteHandler = (shim, fastify) => {
28
+ function setupRouteHandler(shim, fastify) {
51
29
  fastify.addHook('onRoute', (routeOptions) => {
52
30
  if (!routeOptions.handler) {
53
31
  return
54
32
  }
33
+
55
34
  /**
56
35
  * recordMiddleware handler call
57
36
  *
@@ -66,88 +45,38 @@ const setupRouteHandler = (shim, fastify) => {
66
45
 
67
46
  routeOptions.handler = newRouteHandler
68
47
  })
69
-
70
- shim.wrap(fastify, 'addHook', function addWrapHook(shim, fn) {
71
- return function wrappedAddHook(...args) {
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)
78
-
79
- args[1] = newMiddlewareFunction
80
- }
81
- return fn.apply(this, args)
82
- }
83
- })
84
48
  }
85
49
 
86
50
  module.exports = function initialize(agent, fastify, moduleName, shim) {
87
51
  shim.setFramework(shim.FASTIFY)
88
52
 
89
53
  const fastifyVersion = shim.pkgVersion
54
+ const noDiagChannel = semver.lt(fastifyVersion, '3.21.0')
90
55
  const isv3Plus = semver.satisfies(fastifyVersion, '>=3.0.0')
91
56
 
92
- /**
93
- * Fastify exports a function, so we need to use wrapExport
94
- */
95
- const wrappedExport = shim.wrapExport(fastify, function wrapFastifyModule(shim, fn) {
96
- return function wrappedFastifyModule() {
97
- // call original function to get the fastify object (which is singleton-ish)
98
- const fastifyForWrapping = fn.apply(this, arguments)
99
-
100
- setupRouteHandler(shim, fastifyForWrapping)
101
-
102
- setupMiddlewareHandlers(shim, fastifyForWrapping, isv3Plus)
103
-
104
- return fastifyForWrapping
105
- }
106
- })
107
-
108
- if (isv3Plus) {
109
- setupExports(fastify, wrappedExport)
57
+ if (!isv3Plus) {
58
+ shim.logger.warn('Fastify version: %s is unsupported, minimum supported version is `3.0.0`', fastifyVersion)
59
+ return
110
60
  }
111
- }
112
-
113
- function setupMiddlewareHandlers(shim, fastify, isv3Plus) {
114
- const mounterSpec = new MiddlewareMounterSpec({
115
- route: shim.FIRST,
116
- wrapper: wrapMiddleware
117
- })
118
61
 
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(...args) {
125
- const name = args[0]
126
- if (name !== 'use') {
127
- return fn.apply(this, args)
128
- }
62
+ // In 3.21.0+ fastify emits events via diagnostics channel.
63
+ // we are subscribing to one of those events in `lib/subscribers/fastify/index.js`.
64
+ // This code is for any customers using <3.21.0, which hopefully should be very few.
65
+ // TODO: Remove <3.21.0 support in 14.0.0 of Node.js agent
66
+ if (noDiagChannel) {
67
+ const wrappedExport = shim.wrapExport(fastify, function wrapFastifyModule(shim, fn) {
68
+ return function wrappedFastifyModule() {
69
+ // call original function to get the fastify object (which is singleton-ish)
70
+ const fastifyForWrapping = fn.apply(this, arguments)
129
71
 
130
- args[1] = shim.wrapMiddlewareMounter(args[1], mounterSpec)
72
+ setupRouteHandler(shim, fastifyForWrapping)
131
73
 
132
- return fn.apply(this, args)
74
+ return fastifyForWrapping
133
75
  }
134
76
  })
135
- } else {
136
- shim.wrapMiddlewareMounter(fastify, 'use', mounterSpec)
137
- }
138
- }
139
77
 
140
- function wrapMiddleware(shim, middleware, name, route) {
141
- if (shim.isWrapped(middleware)) {
142
- return middleware
78
+ setupExports(fastify, wrappedExport)
143
79
  }
144
-
145
- // prefixing the segment name for middleware execution
146
- // with the Fastify lifecycle hook
147
- const segmentName = `onRequest/${name}`
148
- const spec = buildMiddlewareSpecForMiddlewareFunction(shim, segmentName, route)
149
-
150
- return shim.recordMiddleware(middleware, spec)
151
80
  }
152
81
 
153
82
  /**
@@ -155,8 +84,8 @@ function wrapMiddleware(shim, middleware, name, route) {
155
84
  * module.exports.fastify = fastify
156
85
  * module.exports.default = fastify
157
86
  *
158
- * @param {Object} original original exports
159
- * @param {Object} wrappedExport wrapped exports
87
+ * @param {object} original original fastify export
88
+ * @param {object} wrappedExport wrapped fastify export
160
89
  */
161
90
  function setupExports(original, wrappedExport) {
162
91
  wrappedExport.fastify = original.fastify
@@ -87,7 +87,7 @@ function wrapRun(shim, fn) {
87
87
  *
88
88
  * @param {object} params to function
89
89
  * @param {object} params.consumer consumer being instrumented
90
- * @returns {function} message handler for setting metrics and spec for the consumer transaction
90
+ * @returns {Function} message handler for setting metrics and spec for the consumer transaction
91
91
  */
92
92
  function handler({ consumer }) {
93
93
  /**
@@ -79,7 +79,7 @@ function wrapMiddleware(shim, middleware) {
79
79
  * See: https://github.com/koajs/koa/blob/master/lib/context.js#L186-L241
80
80
  *
81
81
  * @param {Shim} shim instance of shim
82
- * @param {function} _fn createContext function
82
+ * @param {Function} _fn createContext function
83
83
  * @param {string} _fnName name of function
84
84
  * @param {object} context koa ctx object
85
85
  */
@@ -129,7 +129,7 @@ function instrumentStream({ langchain, shim }) {
129
129
  * @param {object} params function params
130
130
  * @param {Shim} params.shim shim instance
131
131
  * @param {TraceSegment} params.segment active segment
132
- * @param {function} params.output IterableReadableStream
132
+ * @param {Function} params.output IterableReadableStream
133
133
  * @param {string} params.request the prompt message
134
134
  * @param {object} params.metadata metadata for the call
135
135
  * @param {Array} params.tags tags for the call
@@ -25,7 +25,7 @@ function wrapKeys(metacall) {
25
25
  * instrument the memcached driver to intercept calls and keep stats on them.
26
26
  *
27
27
  * @param {Agent} agent instance
28
- * @param {Object} memcached library
28
+ * @param {object} memcached library
29
29
  * @param {string} moduleName name of module
30
30
  * @param {Shim} shim instance
31
31
  */
@@ -124,12 +124,10 @@ module.exports = function initialize(shim, nextServer) {
124
124
  function assignParameters(shim, parameters) {
125
125
  const transaction = shim.tracer.getTransaction()
126
126
  if (transaction) {
127
- const prefixedParameters = shim.prefixRouteParameters(parameters)
128
-
129
127
  // We have to add params because this framework doesn't
130
128
  // follow the traditional middleware/middleware mounter pattern
131
129
  // where we'd pull these from middleware.
132
- transaction.nameState.appendPath('/', prefixedParameters)
130
+ transaction.nameState.appendPath('/', parameters)
133
131
  }
134
132
  }
135
133
 
@@ -15,9 +15,9 @@ const utils = module.exports
15
15
  * with its file structure and function names. We're providing relative paths to Next.js files
16
16
  * based on the Next.js page. The function is also hardcoded to align with the conventions of Next.js.
17
17
  *
18
- * @param {Object} config agent config
18
+ * @param {object} config agent config
19
19
  * @param {TraceSegment} segment active segment to add CLM attrs to
20
- * @param {Object} attrs list of CLM attrs to add to segment
20
+ * @param {object} attrs list of CLM attrs to add to segment
21
21
  */
22
22
  utils.assignCLMAttrs = function assignCLMAttrs(config, segment, attrs) {
23
23
  // config is optionally accessed because agent could be older than
@@ -76,10 +76,10 @@ module.exports = function initialize(_agent, restify, _moduleName, shim) {
76
76
  * route is not defined.
77
77
  *
78
78
  * @param {object} shim instance of shim
79
- * @param {function} middleware function to record
79
+ * @param {Function} middleware function to record
80
80
  * @param {string} _name name of middleware
81
81
  * @param {object|null} route name of route
82
- * @returns {function} wrapped middleware function
82
+ * @returns {Function} wrapped middleware function
83
83
  */
84
84
  function wrapMiddleware(shim, middleware, _name, route) {
85
85
  if (shim.isWrapped(middleware)) {
@@ -160,7 +160,7 @@ Contextualizer.prototype.setSegment = function setSegment(segment) {
160
160
  * Propagates the segment to the finally function
161
161
  *
162
162
  * @param {Function} prom current promise
163
- * @returns {Function} current promise or wrapped finally that will propagate the segment
163
+ * @returns {Function|undefined} current promise or wrapped finally that will propagate the segment
164
164
  */
165
165
  Contextualizer.prototype.continue = function continueContext(prom) {
166
166
  const self = this
@@ -9,7 +9,7 @@ const IdGen = require('./util/idgen')
9
9
  const idGen = new IdGen()
10
10
 
11
11
  /**
12
- * @typedef {function} InstrumentationOnRequire
12
+ * @typedef {Function} InstrumentationOnRequire
13
13
  * @param {Shim} shim The shim instance to use for the instrumentation.
14
14
  * @param {object} resolvedNodule The module being instrumented as returned by
15
15
  * Node's `require` function.
@@ -19,7 +19,7 @@ const idGen = new IdGen()
19
19
  */
20
20
 
21
21
  /**
22
- * @typedef {function} InstrumentationOnError
22
+ * @typedef {Function} InstrumentationOnError
23
23
  * @param {Error|object} error The error thrown by `onRequire` when there was
24
24
  * an issue registering the instrumentation.
25
25
  */
@@ -86,14 +86,6 @@ class InstrumentationDescriptor {
86
86
  */
87
87
  static TYPE_WEB_FRAMEWORK = 'web-framework'
88
88
 
89
- /**
90
- * Used to load supportability metrics on installed versions of packages
91
- * that the Node.js agent does not instrument (e.g. OTEL instrumentation or
92
- * top logging libraries).
93
- * @type {string}
94
- */
95
- static TYPE_TRACKING = 'tracking'
96
-
97
89
  /**
98
90
  * The type of the module being instrumented. See the static `TYPE_` fields.
99
91
  * @type {string|null}
@@ -207,7 +199,6 @@ module.exports.TYPES = {
207
199
  PROMISE: InstrumentationDescriptor.TYPE_PROMISE,
208
200
 
209
201
  WEB_FRAMEWORK: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK,
210
- TRACKING: InstrumentationDescriptor.TYPE_TRACKING,
211
202
  /** @private */
212
203
  CONGLOMERATE: InstrumentationDescriptor.TYPE_CONGLOMERATE,
213
204
  /** @private */
@@ -33,28 +33,11 @@ module.exports = function instrumentations() {
33
33
  mongodb: { type: InstrumentationDescriptor.TYPE_DATASTORE },
34
34
  mysql: { module: './instrumentation/mysql' },
35
35
  next: { module: './instrumentation/nextjs' },
36
- pg: { type: InstrumentationDescriptor.TYPE_DATASTORE },
37
36
  q: { type: null },
38
37
  redis: { type: InstrumentationDescriptor.TYPE_DATASTORE },
39
38
  restify: { type: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK },
40
39
  superagent: { type: InstrumentationDescriptor.TYPE_GENERIC },
41
40
  when: { module: './instrumentation/when' },
42
- winston: { type: InstrumentationDescriptor.TYPE_GENERIC },
43
-
44
- /**
45
- * The modules below are listed here purely to take
46
- * advantage of the Supportability/Features/onRequire/<module>
47
- * metrics for libraries we want to track for some reason or another.
48
- * The big uses cases are:
49
- * Logging libraries we want to instrument in the future
50
- * Libraries that have OpenTelemetry instrumentation we want to register
51
- * or have already registered.
52
- */
53
- '@azure/openai': { type: InstrumentationDescriptor.TYPE_TRACKING },
54
- '@langchain/community/llms/bedrock': { type: InstrumentationDescriptor.TYPE_TRACKING },
55
- 'fancy-log': { type: InstrumentationDescriptor.TYPE_TRACKING },
56
- knex: { type: InstrumentationDescriptor.TYPE_TRACKING },
57
- loglevel: { type: InstrumentationDescriptor.TYPE_TRACKING },
58
- npmlog: { type: InstrumentationDescriptor.TYPE_TRACKING },
41
+ winston: { type: InstrumentationDescriptor.TYPE_GENERIC }
59
42
  }
60
43
  }
@@ -10,7 +10,8 @@ const LlmEvent = require('./event')
10
10
  /**
11
11
  * @typedef {object} LlmChatCompletionSummaryParams
12
12
  * @augments LlmEventParams
13
- * @property
13
+ * @property {string} segment the segment associated with this LlmChatCompletionSummary
14
+ * @property {boolean} isError whether this event represents an error
14
15
  */
15
16
  /**
16
17
  * @type {LlmChatCompletionSummaryParams}
@@ -12,13 +12,12 @@ const metrics = require('../names')
12
12
  *
13
13
  * - `recordOperationMetrics(segment [, scope])`
14
14
  *
15
+ * This function is an implementation of {@link MetricFunction} (see #agentlib/shim/shim.js)
15
16
  * @private
16
- * @this DatastoreShim
17
- * @implements {MetricFunction}
18
17
  * @param {TraceSegment} segment - The segment being recorded.
19
18
  * @param {string} [scope] - The scope of the segment.
19
+ * @param {Transaction} transaction - The transaction associated with the segment.
20
20
  * @see DatastoreShim#recordOperation
21
- * @see MetricFunction
22
21
  */
23
22
  function recordOperationMetrics(segment, scope, transaction) {
24
23
  const duration = segment.getDurationInMillis()
@@ -9,11 +9,10 @@
9
9
  * Creates a recorder for middleware metrics.
10
10
  *
11
11
  * @private
12
- * @param {object} _shim instance of shim
13
12
  * @param {string} metricName name of metric
14
13
  * @returns {Function} recorder for middleware
15
14
  */
16
- function makeMiddlewareRecorder(_shim, metricName) {
15
+ function makeMiddlewareRecorder(metricName) {
17
16
  return function middlewareMetricRecorder(segment, scope, transaction) {
18
17
  const duration = segment.getDurationInMillis()
19
18
  const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)
@@ -31,9 +31,9 @@ class ContextManager {
31
31
  * Runs the callback within the provided context, optionally
32
32
  * bound with a provided `this`.
33
33
  *
34
- * @param {Object} context context
35
- * @param {function} callback callback
36
- * @param {Object} thisRef `this` reference
34
+ * @param {object} context context
35
+ * @param {Function} callback callback
36
+ * @param {object} thisRef `this` reference
37
37
  * @param {...any} args arguments
38
38
  */
39
39
  with(context, callback, thisRef, ...args) {
@@ -68,7 +68,7 @@ module.exports = function createDbSegment(agent, otelSpan, rule) {
68
68
  * @param {ParsedStatement} params.parsed parsed statement of call
69
69
  * @param {boolean} params.operation if span is an operation
70
70
  * @param {string} params.system `db.system` value of otel span
71
- * @returns {function} returns a timeslice metrics recorder function based on span
71
+ * @returns {Function} returns a timeslice metrics recorder function based on span
72
72
  */
73
73
  function getRecorder({ parsed, operation, system }) {
74
74
  if (operation) {
@@ -12,8 +12,8 @@ const { DESTINATIONS } = require('#agentlib/config/attribute-filter.js')
12
12
  * If a key is not found in the data object, it returns 'unknown'.
13
13
  * If a key is found in the rules object, it applies the corresponding function to the value.
14
14
  * @param {string} template - The template string containing placeholders in the format ${key}.
15
- * @param {Object} data - An object containing key-value pairs to replace in the template.
16
- * @param {Object} rules - An optional object containing functions to apply to specific keys.
15
+ * @param {object} data - An object containing key-value pairs to replace in the template.
16
+ * @param {object} rules - An optional object containing functions to apply to specific keys.
17
17
  * @returns {string} - The transformed string with placeholders replaced by corresponding values.
18
18
  */
19
19
  function transformTemplate(template, data, rules = {}) {
@@ -35,7 +35,7 @@ function transformTemplate(template, data, rules = {}) {
35
35
  * Each mapping should have a key, arguments, and body.
36
36
  * The body should be a string that can be evaluated as a function.
37
37
  * @param {Array} mappings - Array of mappings with key, arguments, and body.
38
- * @returns {Object} - An object where each key maps to a function.
38
+ * @returns {object} - An object where each key maps to a function.
39
39
  */
40
40
  function buildRuleMappings(mappings = []) {
41
41
  return mappings.reduce((acc, attr) => {
@@ -111,11 +111,11 @@ function processRegexGroups({ segment, transaction, groups = [], regexMatch }) {
111
111
  * If the attribute has a key, it will be used to get the value from the span's attributes.
112
112
  * If the attribute has a value, it will be used directly.
113
113
  * If the attribute has a template, it will be transformed using the span's attributes and any provided mappings.
114
- * @param {Object} params - The parameters for extracting the attribute value.
114
+ * @param {object} params - The parameters for extracting the attribute value.
115
115
  * @param {string} params.accountId - The value of agent.config.cloud.account_id
116
- * @param {Object} params.attribute - The attribute object containing key, value, or template.
116
+ * @param {object} params.attribute - The attribute object containing key, value, or template.
117
117
  * @param {Set} params.excludeAttributes - A set to keep track of excluded attributes.
118
- * @param {Object} params.span - The span object containing attributes.
118
+ * @param {object} params.span - The span object containing attributes.
119
119
  * @returns {string} - The extracted value of the attribute.
120
120
  */
121
121
  function extractAttributeValue({ accountId, attribute, excludeAttributes, span }) {
@@ -137,10 +137,10 @@ function extractAttributeValue({ accountId, attribute, excludeAttributes, span }
137
137
 
138
138
  /**
139
139
  * Assigns a value to a target based on the specified target type.
140
- * @param {Object} params - The parameters for assigning the value.
141
- * @param {Object} params.segment - The segment to add the attribute to.
140
+ * @param {object} params - The parameters for assigning the value.
141
+ * @param {object} params.segment - The segment to add the attribute to.
142
142
  * @param {string} params.target - The target type ('transaction', 'trace', or 'segment').
143
- * @param {Object} params.transaction - The transaction object.
143
+ * @param {object} params.transaction - The transaction object.
144
144
  * @param {string} params.name - The name of the attribute.
145
145
  * @param {string} params.value - The value of the attribute.
146
146
  */
@@ -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 {Object} handler original handler
109
- * @param {Object} nrHandler our copy of the handler
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)) {
@@ -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 {function} params.fn function being instrumented
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 {Object} params.ctx this binding of the original function
23
- * @param {specs.MessageSpec} params.spec spec for the wrapped consume function
24
- * @returns {specs.MessageSpec} new spec
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
@@ -366,7 +366,7 @@ function _wrapExecutorContext(shim, args) {
366
366
 
367
367
  /**
368
368
  *
369
- * @param {Object} args contains the `resolve` and `reject` functions of a promise
369
+ * @param {object} args contains the `resolve` and `reject` functions of a promise
370
370
  */
371
371
  function contextExporter(...args) {
372
372
  const [resolve, reject] = args
@@ -382,7 +382,6 @@ function _wrapExecutorContext(shim, args) {
382
382
  * @param {object} context context object
383
383
  * @param {Function} fn function that is wrapped
384
384
  * @returns {Function} wrapped function
385
- * @private
386
385
  */
387
386
  function _wrapResolver(context, fn) {
388
387
  return function wrappedResolveReject(val) {