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
|
@@ -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
|
|
@@ -44,14 +22,15 @@ const REQUEST_HOOKS = [
|
|
|
44
22
|
* at them would require a lot of gymnastics and hard to
|
|
45
23
|
* maintain code
|
|
46
24
|
*
|
|
47
|
-
* @param shim
|
|
48
|
-
* @param fastify
|
|
25
|
+
* @param {WebFrameworkShim} shim instance
|
|
26
|
+
* @param {object} fastify Fastify instance
|
|
49
27
|
*/
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
72
|
+
setupRouteHandler(shim, fastifyForWrapping)
|
|
131
73
|
|
|
132
|
-
return
|
|
74
|
+
return fastifyForWrapping
|
|
133
75
|
}
|
|
134
76
|
})
|
|
135
|
-
} else {
|
|
136
|
-
shim.wrapMiddlewareMounter(fastify, 'use', mounterSpec)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
77
|
|
|
140
|
-
|
|
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 original
|
|
159
|
-
* @param wrappedExport
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
|
|
@@ -24,10 +24,10 @@ function wrapKeys(metacall) {
|
|
|
24
24
|
*
|
|
25
25
|
* instrument the memcached driver to intercept calls and keep stats on them.
|
|
26
26
|
*
|
|
27
|
-
* @param agent
|
|
28
|
-
* @param memcached
|
|
29
|
-
* @param moduleName
|
|
30
|
-
* @param shim
|
|
27
|
+
* @param {Agent} agent instance
|
|
28
|
+
* @param {object} memcached library
|
|
29
|
+
* @param {string} moduleName name of module
|
|
30
|
+
* @param {Shim} shim instance
|
|
31
31
|
*/
|
|
32
32
|
module.exports = function initialize(agent, memcached, moduleName, shim) {
|
|
33
33
|
const proto = memcached && memcached.prototype
|
|
@@ -22,10 +22,10 @@ module.exports = initialize
|
|
|
22
22
|
* Registers the query parser, and relevant instrumentation
|
|
23
23
|
* based on version of mongodb
|
|
24
24
|
*
|
|
25
|
-
* @param {Agent} agent
|
|
25
|
+
* @param {Agent} agent instance
|
|
26
26
|
* @param {object} mongodb resolved package
|
|
27
27
|
* @param {string} moduleName name of module
|
|
28
|
-
* @param {Shim} shim
|
|
28
|
+
* @param {Shim} shim instance
|
|
29
29
|
*/
|
|
30
30
|
function initialize(agent, mongodb, moduleName, shim) {
|
|
31
31
|
if (!mongodb) {
|
|
@@ -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('/',
|
|
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 {
|
|
18
|
+
* @param {object} config agent config
|
|
19
19
|
* @param {TraceSegment} segment active segment to add CLM attrs to
|
|
20
|
-
* @param {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 */
|
package/lib/instrumentations.js
CHANGED
|
@@ -19,11 +19,9 @@ module.exports = function instrumentations() {
|
|
|
19
19
|
'@node-redis/client': { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
20
20
|
'@prisma/client': { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
21
21
|
'@redis/client': { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
22
|
-
amqplib: { module: './instrumentation/amqplib' },
|
|
23
22
|
'aws-sdk': { module: './instrumentation/aws-sdk' },
|
|
24
23
|
bluebird: { type: InstrumentationDescriptor.TYPE_PROMISE },
|
|
25
24
|
bunyan: { type: InstrumentationDescriptor.TYPE_GENERIC },
|
|
26
|
-
'cassandra-driver': { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
27
25
|
connect: { type: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK },
|
|
28
26
|
express: { type: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK },
|
|
29
27
|
fastify: { type: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK },
|
|
@@ -35,28 +33,11 @@ module.exports = function instrumentations() {
|
|
|
35
33
|
mongodb: { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
36
34
|
mysql: { module: './instrumentation/mysql' },
|
|
37
35
|
next: { module: './instrumentation/nextjs' },
|
|
38
|
-
pg: { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
39
36
|
q: { type: null },
|
|
40
37
|
redis: { type: InstrumentationDescriptor.TYPE_DATASTORE },
|
|
41
38
|
restify: { type: InstrumentationDescriptor.TYPE_WEB_FRAMEWORK },
|
|
42
39
|
superagent: { type: InstrumentationDescriptor.TYPE_GENERIC },
|
|
43
40
|
when: { module: './instrumentation/when' },
|
|
44
|
-
winston: { type: InstrumentationDescriptor.TYPE_GENERIC }
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* The modules below are listed here purely to take
|
|
48
|
-
* advantage of the Supportability/Features/onRequire/<module>
|
|
49
|
-
* metrics for libraries we want to track for some reason or another.
|
|
50
|
-
* The big uses cases are:
|
|
51
|
-
* Logging libraries we want to instrument in the future
|
|
52
|
-
* Libraries that have OpenTelemetry instrumentation we want to register
|
|
53
|
-
* or have already registered.
|
|
54
|
-
*/
|
|
55
|
-
'@azure/openai': { type: InstrumentationDescriptor.TYPE_TRACKING },
|
|
56
|
-
'@langchain/community/llms/bedrock': { type: InstrumentationDescriptor.TYPE_TRACKING },
|
|
57
|
-
'fancy-log': { type: InstrumentationDescriptor.TYPE_TRACKING },
|
|
58
|
-
knex: { type: InstrumentationDescriptor.TYPE_TRACKING },
|
|
59
|
-
loglevel: { type: InstrumentationDescriptor.TYPE_TRACKING },
|
|
60
|
-
npmlog: { type: InstrumentationDescriptor.TYPE_TRACKING },
|
|
41
|
+
winston: { type: InstrumentationDescriptor.TYPE_GENERIC }
|
|
61
42
|
}
|
|
62
43
|
}
|
|
@@ -34,10 +34,10 @@ class BedrockResponse {
|
|
|
34
34
|
#isConverse
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* @param {object} params
|
|
38
|
-
* @param {AwsBedrockMiddlewareResponse} params.response
|
|
39
|
-
* @param {BedrockCommand} params.bedrockCommand
|
|
40
|
-
* @param {boolean} params.isError
|
|
37
|
+
* @param {object} params params object
|
|
38
|
+
* @param {AwsBedrockMiddlewareResponse} params.response AWS Bedrock middleware response
|
|
39
|
+
* @param {BedrockCommand} params.bedrockCommand AWS Bedrock command
|
|
40
|
+
* @param {boolean} params.isError is there an error
|
|
41
41
|
*/
|
|
42
42
|
constructor({ response, bedrockCommand, isError = false }) {
|
|
43
43
|
this.#originalResponse = response
|
|
@@ -146,8 +146,8 @@ class BedrockResponse {
|
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* Extracts and sets #completions and #id from the InvokeModel response body.
|
|
149
|
-
* @param {BedrockCommand} cmd
|
|
150
|
-
* @param {*} body
|
|
149
|
+
* @param {BedrockCommand} cmd AWS Bedrock Command
|
|
150
|
+
* @param {*} body InvokeModel response body
|
|
151
151
|
*/
|
|
152
152
|
#extractCompletionsAndId(cmd, body) {
|
|
153
153
|
if (cmd.isClaude() === true) {
|
|
@@ -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}
|
|
@@ -101,7 +101,7 @@ class ConverseStreamHandler {
|
|
|
101
101
|
* If the given event is the last event in the stream, update the response
|
|
102
102
|
* headers with the metrics data from the event.
|
|
103
103
|
*
|
|
104
|
-
* @param {object} parsedEvent
|
|
104
|
+
* @param {object} parsedEvent parsed stream event
|
|
105
105
|
*/
|
|
106
106
|
updateHeaders(parsedEvent) {
|
|
107
107
|
this.response.response.headers = {
|
|
@@ -145,8 +145,8 @@ class StreamHandler {
|
|
|
145
145
|
* Finds the reason for the end of the stream based upon the model's known
|
|
146
146
|
* stop reason key.
|
|
147
147
|
*
|
|
148
|
-
* @param {object} event
|
|
149
|
-
* @returns {string}
|
|
148
|
+
* @param {object} event stream event
|
|
149
|
+
* @returns {string} the stop reason
|
|
150
150
|
*/
|
|
151
151
|
getStopReason(event) {
|
|
152
152
|
if (this.stopReasonKey.includes('.')) {
|
|
@@ -164,7 +164,7 @@ class StreamHandler {
|
|
|
164
164
|
/**
|
|
165
165
|
* Decodes the Uint8Array that represents a model response.
|
|
166
166
|
*
|
|
167
|
-
* @param {object} event
|
|
167
|
+
* @param {object} event stream event
|
|
168
168
|
*
|
|
169
169
|
* @returns {object}
|
|
170
170
|
*/
|
|
@@ -177,7 +177,7 @@ class StreamHandler {
|
|
|
177
177
|
* If the given event is the last event in the stream, update the response
|
|
178
178
|
* headers with the metrics data from the event.
|
|
179
179
|
*
|
|
180
|
-
* @param {object} parsedEvent
|
|
180
|
+
* @param {object} parsedEvent the parsed stream event
|
|
181
181
|
*/
|
|
182
182
|
updateHeaders(parsedEvent) {
|
|
183
183
|
if (this.getStopReason(parsedEvent) === null) {
|
package/lib/metrics/index.js
CHANGED
|
@@ -44,7 +44,7 @@ const FROM_MILLIS = 1e-3
|
|
|
44
44
|
* @param {number} apdexT The apdex-tolerating value, for use in creating apdex
|
|
45
45
|
* statistics.
|
|
46
46
|
* @param {MetricMapper} mapper The mapper that turns metric names into IDs.
|
|
47
|
-
* @param normalizer
|
|
47
|
+
* @param {NameNormalizer} normalizer The normalizer that standardizes metric names.
|
|
48
48
|
*/
|
|
49
49
|
function Metrics(apdexT, mapper, normalizer) {
|
|
50
50
|
if (apdexT == null || apdexT === '') {
|
|
@@ -268,7 +268,7 @@ Metrics.prototype._getUnscopedData = function _getUnscopedData(name) {
|
|
|
268
268
|
* mappings along the way. Split from _getUnscopedData for performance.
|
|
269
269
|
*
|
|
270
270
|
* @param {string} name The string to look up.
|
|
271
|
-
* @param scope
|
|
271
|
+
* @param {string} scope The scope to map with.
|
|
272
272
|
*/
|
|
273
273
|
Metrics.prototype._getScopedData = function _getScopedData(name, scope) {
|
|
274
274
|
if (!this.scoped[scope][name]) {
|
|
@@ -10,7 +10,7 @@ const logger = require('../../logger').child({ component: 'normalizer_rule' })
|
|
|
10
10
|
/**
|
|
11
11
|
* JavaScript just has to do things slightly differently.
|
|
12
12
|
*
|
|
13
|
-
* @param input
|
|
13
|
+
* @param {string} input the input string
|
|
14
14
|
*/
|
|
15
15
|
const replaceReplacer = function replaceReplacer(input) {
|
|
16
16
|
return input.replace(/\\/g, '$')
|
|
@@ -48,7 +48,7 @@ function plain(normalized, path) {
|
|
|
48
48
|
* @param {object} config The agent's configuration blob, which has a parameter
|
|
49
49
|
* that indicates whether to enforce the normalization
|
|
50
50
|
* backstop.
|
|
51
|
-
* @param type
|
|
51
|
+
* @param {string} type The type of normalization to apply.
|
|
52
52
|
*/
|
|
53
53
|
function MetricNormalizer(config, type) {
|
|
54
54
|
if (!config) {
|
|
@@ -88,9 +88,8 @@ util.inherits(MetricNormalizer, EventEmitter)
|
|
|
88
88
|
* Convert the raw, de-serialized JSON response into a set of
|
|
89
89
|
* NormalizationRules.
|
|
90
90
|
*
|
|
91
|
-
* @param object json The de-serialized JSON response sent on collector
|
|
91
|
+
* @param {object} json The de-serialized JSON response sent on collector
|
|
92
92
|
* connection.
|
|
93
|
-
* @param json
|
|
94
93
|
*/
|
|
95
94
|
MetricNormalizer.prototype.load = function load(json) {
|
|
96
95
|
if (json) {
|
|
@@ -118,8 +117,8 @@ MetricNormalizer.prototype.load = function load(json) {
|
|
|
118
117
|
/**
|
|
119
118
|
* Helper for loadFromConfig
|
|
120
119
|
*
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
120
|
+
* @param {object} rule from this.config.rules
|
|
121
|
+
* @param {object} ctx context from the calling function
|
|
123
122
|
*/
|
|
124
123
|
function processNameRule(rule, ctx) {
|
|
125
124
|
if (!rule.pattern) {
|
|
@@ -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()
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
const NAMES = require('../../metrics/names.js')
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @param {TraceSegment} segment
|
|
12
|
-
* @param {object} scope
|
|
13
|
-
* @param {Transaction} tx
|
|
11
|
+
* @param {TraceSegment} segment segment
|
|
12
|
+
* @param {object} [scope] scope
|
|
13
|
+
* @param {Transaction} tx transaction
|
|
14
14
|
*/
|
|
15
15
|
function recordMessageTransaction(segment, scope, tx) {
|
|
16
16
|
if (tx.type !== 'message' || tx.baseSegment !== segment) {
|
|
@@ -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(
|
|
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,10 +31,10 @@ class ContextManager {
|
|
|
31
31
|
* Runs the callback within the provided context, optionally
|
|
32
32
|
* bound with a provided `this`.
|
|
33
33
|
*
|
|
34
|
-
* @param context
|
|
35
|
-
* @param callback
|
|
36
|
-
* @param thisRef
|
|
37
|
-
* @param args
|
|
34
|
+
* @param {object} context context
|
|
35
|
+
* @param {Function} callback callback
|
|
36
|
+
* @param {object} thisRef `this` reference
|
|
37
|
+
* @param {...any} args arguments
|
|
38
38
|
*/
|
|
39
39
|
with(context, callback, thisRef, ...args) {
|
|
40
40
|
return this.#ctxMgr.runInContext(context, callback, thisRef, args)
|
|
@@ -25,7 +25,7 @@ class TraceState {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Parses information from the [traceparent] span tag and converts it into {@link SpanContext}
|
|
28
|
-
* @param traceParent - A meta property that comes from server.
|
|
28
|
+
* @param {string} traceParent - A meta property that comes from server.
|
|
29
29
|
* It should be dynamically generated server side to have the server's request trace Id,
|
|
30
30
|
* a parent span Id that was set on the server's request span,
|
|
31
31
|
* and the trace flags to indicate the server's sampling decision
|
|
@@ -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 {
|
|
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) {
|
package/lib/otel/traces/utils.js
CHANGED
|
@@ -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 {
|
|
16
|
-
* @param {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
141
|
-
* @param {
|
|
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 {
|
|
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
|
*/
|
|
@@ -139,8 +139,8 @@ class PrioritizedAttributes {
|
|
|
139
139
|
* Returns true if a given key is valid for any of the
|
|
140
140
|
* provided destinations.
|
|
141
141
|
*
|
|
142
|
-
* @param {DESTINATIONS} destinations
|
|
143
|
-
* @param {string} key
|
|
142
|
+
* @param {DESTINATIONS} destinations destinations to check against
|
|
143
|
+
* @param {string} key key to check
|
|
144
144
|
*/
|
|
145
145
|
hasValidDestination(destinations, key) {
|
|
146
146
|
const validDestinations = this.filter(destinations, key)
|