newrelic 13.0.0 → 13.2.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 (68) hide show
  1. package/NEWS.md +92 -0
  2. package/README.md +2 -4
  3. package/THIRD_PARTY_NOTICES.md +429 -9
  4. package/esm-loader.mjs +9 -1
  5. package/index.js +38 -3
  6. package/lib/agent.js +8 -2
  7. package/lib/config/build-instrumentation-config.js +3 -0
  8. package/lib/config/default.js +1397 -1383
  9. package/lib/config/index.js +15 -19
  10. package/lib/context-manager/context.js +13 -4
  11. package/lib/harvester.js +11 -13
  12. package/lib/instrumentation/@google/genai.js +8 -3
  13. package/lib/instrumentation/@hapi/hapi.js +4 -6
  14. package/lib/instrumentation/@nestjs/core.js +12 -14
  15. package/lib/instrumentation/aws-sdk/v3/bedrock.js +2 -2
  16. package/lib/instrumentation/core/http-outbound.js +11 -26
  17. package/lib/instrumentation/kafkajs/producer.js +13 -19
  18. package/lib/instrumentation/openai.js +2 -2
  19. package/lib/instrumentation/undici.js +48 -40
  20. package/lib/instrumentations.js +14 -5
  21. package/lib/llm-events/aws-bedrock/utils.js +1 -1
  22. package/lib/metrics/names.js +8 -0
  23. package/lib/metrics/normalizer.js +1 -3
  24. package/lib/otel/context.js +18 -14
  25. package/lib/otel/logs/bootstrap-logs.js +84 -0
  26. package/lib/otel/logs/no-op-exporter.js +25 -0
  27. package/lib/otel/logs/normalize-timestamp.js +59 -0
  28. package/lib/otel/logs/proxying-provider.js +46 -0
  29. package/lib/otel/logs/severity-to-string.js +56 -0
  30. package/lib/otel/metrics/bootstrap-metrics.js +1 -1
  31. package/lib/otel/setup.js +21 -8
  32. package/lib/patch-module.js +70 -0
  33. package/lib/serverless/aws-lambda.js +1 -3
  34. package/lib/shim/webframework-shim/middleware-mounter.js +1 -3
  35. package/lib/shimmer.js +56 -8
  36. package/lib/subscriber-configs.js +17 -0
  37. package/lib/subscribers/application-logs.js +55 -0
  38. package/lib/subscribers/base.js +177 -0
  39. package/lib/subscribers/create-config.js +27 -0
  40. package/lib/subscribers/db-operation.js +21 -0
  41. package/lib/subscribers/db-query.js +54 -0
  42. package/lib/subscribers/db.js +57 -0
  43. package/lib/subscribers/elasticsearch/config.js +49 -0
  44. package/lib/subscribers/elasticsearch/elasticsearch.js +42 -0
  45. package/lib/subscribers/elasticsearch/opensearch.js +15 -0
  46. package/lib/subscribers/elasticsearch/transport.js +14 -0
  47. package/lib/subscribers/ioredis/config.js +37 -0
  48. package/lib/subscribers/ioredis/index.js +48 -0
  49. package/lib/subscribers/mcp-sdk/client-prompt.js +23 -0
  50. package/lib/subscribers/mcp-sdk/client-resource.js +24 -0
  51. package/lib/subscribers/mcp-sdk/client-tool.js +23 -0
  52. package/lib/subscribers/mcp-sdk/client.js +29 -0
  53. package/lib/subscribers/mcp-sdk/config.js +104 -0
  54. package/lib/subscribers/pino/config.js +20 -0
  55. package/lib/subscribers/pino/index.js +102 -0
  56. package/lib/transaction/index.js +4 -1
  57. package/lib/transaction/trace/aggregator.js +7 -9
  58. package/lib/util/camel-case.js +1 -3
  59. package/lib/util/get-package-version.js +34 -0
  60. package/lib/util/urltils.js +19 -13
  61. package/lib/w3c/tracestate.js +3 -3
  62. package/newrelic.js +10 -0
  63. package/package.json +9 -5
  64. package/lib/instrumentation/@elastic/elasticsearch.js +0 -62
  65. package/lib/instrumentation/@opensearch-project/opensearch.js +0 -66
  66. package/lib/instrumentation/ioredis.js +0 -50
  67. package/lib/instrumentation/pino/nr-hooks.js +0 -19
  68. package/lib/instrumentation/pino/pino.js +0 -168
@@ -1,50 +0,0 @@
1
- /*
2
- * Copyright 2020 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- 'use strict'
7
-
8
- const stringify = require('json-stringify-safe')
9
- const urltils = require('../util/urltils.js')
10
- const {
11
- OperationSpec,
12
- params: { DatastoreParameters }
13
- } = require('../../lib/shim/specs')
14
-
15
- module.exports = function initialize(agent, redis, moduleName, shim) {
16
- const proto = redis && redis.prototype
17
- if (!proto) {
18
- return false
19
- }
20
-
21
- shim.setDatastore(shim.REDIS)
22
- shim.recordOperation(proto, 'sendCommand', wrapSendCommand)
23
-
24
- function wrapSendCommand(shim, original, name, args) {
25
- const command = args[0]
26
-
27
- const parameters = new DatastoreParameters({
28
- host: this.connector.options.host,
29
- port_path_or_id: this.connector.options.port
30
- })
31
-
32
- const keys = command.args
33
- if (keys && typeof keys !== 'function') {
34
- const src = Object.create(null)
35
- try {
36
- src.key = stringify(keys[0])
37
- } catch (err) {
38
- shim.logger.debug(err, 'Failed to stringify ioredis key')
39
- src.key = '<unknown>'
40
- }
41
- urltils.copyParameters(src, parameters)
42
- }
43
-
44
- return new OperationSpec({
45
- name: command.name || 'unknown',
46
- parameters,
47
- promise: true
48
- })
49
- }
50
- }
@@ -1,19 +0,0 @@
1
- /*
2
- * Copyright 2022 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- 'use strict'
7
- const pino = require('./pino')
8
- const InstrumentationDescriptor = require('../../instrumentation-descriptor')
9
-
10
- /**
11
- * Need to use nr-hooks style because we are instrumenting a submodule.
12
- */
13
- module.exports = [
14
- {
15
- type: InstrumentationDescriptor.TYPE_GENERIC,
16
- moduleName: 'pino/lib/tools',
17
- onRequire: pino
18
- }
19
- ]
@@ -1,168 +0,0 @@
1
- /*
2
- * Copyright 2022 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- 'use strict'
7
- const {
8
- createModuleUsageMetric,
9
- isApplicationLoggingEnabled,
10
- isLogForwardingEnabled,
11
- isMetricsEnabled,
12
- isLocalDecoratingEnabled,
13
- incrementLoggingLinesMetrics,
14
- truncate
15
- } = require('../../util/application-logging')
16
- const semver = require('semver')
17
-
18
- module.exports = function instrument(shim, tools) {
19
- const pinoVersion = shim.pkgVersion
20
-
21
- if (semver.lt(pinoVersion, '7.0.0')) {
22
- shim.logger.debug('Instrumentation only supported on pino >=7.0.0.')
23
- return
24
- }
25
-
26
- const agent = shim.agent
27
- const config = agent.config
28
-
29
- if (!isApplicationLoggingEnabled(config)) {
30
- shim.logger.debug('Application logging not enabled. Not instrumenting pino.')
31
- return
32
- }
33
-
34
- const metrics = agent.metrics
35
- createModuleUsageMetric('pino', metrics)
36
-
37
- wrapAsJson({ shim, tools })
38
- }
39
-
40
- /**
41
- * Wraps `asJson` to properly decorate and forward logs
42
- *
43
- * @param {object} params to function
44
- * @param {Shim} params.shim instance of shim
45
- * @param {object} params.tools exported `pino/lib/tools`
46
- */
47
- function wrapAsJson({ shim, tools }) {
48
- const { agent } = shim
49
- const { config, metrics } = agent
50
-
51
- shim.wrap(tools, 'asJson', function wrapJson(shim, asJson) {
52
- /**
53
- * Wraps function in pino that is used to construct/serialize a log
54
- * line to json
55
- *
56
- * @param {object} obj data from mixins
57
- * @param {string} msg message of log line
58
- * @param {number} num log level as number
59
- * @param {string} time formatted snippet of json with time(`,"time":<unix time>`)
60
- * @param {...any} args
61
- * @returns {string} serialized log line
62
- */
63
- return function wrappedAsJson(...args) {
64
- const level = this?.levels?.labels?.[args[2]]
65
- // Pino log methods accept a singular object (a merging object) that can
66
- // have a `msg` property for the log message. In such cases, we need to
67
- // update that log property instead of the second parameter.
68
- const useMergeObj = args[1] === undefined && Object.hasOwn(args[0], 'msg')
69
-
70
- if (isMetricsEnabled(config)) {
71
- incrementLoggingLinesMetrics(level, metrics)
72
- }
73
-
74
- if (isLocalDecoratingEnabled(config)) {
75
- if (useMergeObj === true) {
76
- args[0].msg += agent.getNRLinkingMetadata()
77
- } else {
78
- args[1] += agent.getNRLinkingMetadata()
79
- }
80
- }
81
-
82
- /**
83
- * must call original asJson to allow pino
84
- * to construct the entire log line before we
85
- * add to the log aggregator
86
- */
87
- const logLine = asJson.apply(this, args)
88
-
89
- if (isLogForwardingEnabled(config, agent)) {
90
- const formatLogLine = reformatLogLine({
91
- msg: useMergeObj === true ? args[0].msg : args[1],
92
- logLine,
93
- agent,
94
- level,
95
- logger: shim.logger
96
- })
97
-
98
- agent.logs.add(formatLogLine)
99
- }
100
-
101
- return logLine
102
- }
103
- })
104
- }
105
-
106
- /**
107
- * reformats error and assigns NR context data
108
- * to log line
109
- *
110
- * @param {object} params to function
111
- * @param {object} params.logLine log line
112
- * @param {string} params.msg message of log line
113
- * @param {object} params.agent instance of agent
114
- * @param {string} params.level log level
115
- * @param {object} params.logger instance of agent logger
116
- * @returns {function} wrapped log formatter function
117
- */
118
- function reformatLogLine({ logLine, msg, agent, level, logger }) {
119
- const metadata = agent.getLinkingMetadata(true)
120
-
121
- const agentMeta = Object.assign({}, { timestamp: Date.now() }, metadata)
122
- // eslint-disable-next-line eqeqeq
123
- if (msg != undefined) {
124
- // The spec lists `message` as "MUST" under the required column, but then
125
- // details that it "MUST be omitted" if the value is "empty". Additionally,
126
- // if someone has logged only a merging object, and that object contains a
127
- // message key, we do not want to overwrite their value. See issue 2595.
128
- agentMeta.message = msg
129
- }
130
-
131
- /**
132
- * A function that gets executed in `_toPayloadSync` of log aggregator.
133
- * This will parse the serialized log line and then add the relevant NR
134
- * context metadata and rename the time/msg keys to timestamp/message
135
- */
136
- return function formatLogLine() {
137
- let formattedLog
138
- try {
139
- formattedLog = JSON.parse(logLine)
140
- } catch (err) {
141
- logger.error('Failed to parse log line as json: %s', err.message)
142
- return
143
- }
144
-
145
- if (formattedLog.err) {
146
- reformatError(formattedLog)
147
- }
148
- Object.assign(formattedLog, agentMeta)
149
- formattedLog.level = level
150
- delete formattedLog.time
151
- delete formattedLog.msg
152
- return formattedLog
153
- }
154
- }
155
-
156
- /**
157
- * Truncates the message, stack and class of error
158
- * and reassigns to a `error.*` keyspace. Also removes the `err`
159
- * key on a log line
160
- *
161
- * @param {object} logLine log line
162
- */
163
- function reformatError(logLine) {
164
- logLine['error.message'] = truncate(logLine.err.message)
165
- logLine['error.stack'] = truncate(logLine.err.stack)
166
- logLine['error.class'] = logLine.err.type
167
- delete logLine.err
168
- }