Skip to content

Commit 984148e

Browse files
committed
Merge branch 'main' of https://github.com/amychisholm03/node-newrelic into NR-362185/response-streaming
2 parents 4a55b7a + f404585 commit 984148e

25 files changed

+982
-737
lines changed

THIRD_PARTY_NOTICES.md

Lines changed: 29 additions & 478 deletions
Large diffs are not rendered by default.

lib/config/build-instrumentation-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
const { boolean } = require('./formatters')
88
const instrumentedLibraries = require('../instrumentations')()
99
const pkgNames = Object.keys(instrumentedLibraries)
10+
const coreLibraries = require('../core-instrumentation')
11+
const corePkgs = Object.keys(coreLibraries)
12+
// Manually adding undici as it is registered separately in shimmer
13+
corePkgs.push('undici')
14+
// Manually adding domain as it is registered separately in shimmer
15+
corePkgs.push('domain')
16+
pkgNames.push(...corePkgs)
1017

1118
/**
1219
* Builds the stanza for config.instrumentation.*

lib/config/default.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,9 +1553,9 @@ defaultConfig.definition = () => ({
15531553
}
15541554
},
15551555
/**
1556-
* Stanza that contains all keys to disable 3rd party package instrumentation(i.e. mongodb, pg, redis, etc)
1557-
* Note: Disabling a given 3rd party library may affect the instrumentation of 3rd party libraries used after
1558-
* the disabled library.
1556+
* Stanza that contains all keys to disable core & 3rd party package instrumentation(i.e. dns, http, mongodb, pg, redis, etc)
1557+
* **Note**: Disabling a given library may affect the instrumentation of libraries used after
1558+
* the disabled library. Use at your own risk.
15591559
*/
15601560
instrumentation: pkgInstrumentation
15611561
})

lib/core-instrumentation.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
8+
const InstrumentationDescriptor = require('./instrumentation-descriptor')
9+
10+
module.exports = {
11+
child_process: {
12+
type: InstrumentationDescriptor.TYPE_GENERIC,
13+
file: 'child_process.js'
14+
},
15+
crypto: {
16+
type: InstrumentationDescriptor.TYPE_GENERIC,
17+
file: 'crypto.js'
18+
},
19+
dns: {
20+
type: InstrumentationDescriptor.TYPE_GENERIC,
21+
file: 'dns.js'
22+
},
23+
fs: {
24+
type: InstrumentationDescriptor.TYPE_GENERIC,
25+
file: 'fs.js'
26+
},
27+
http: {
28+
type: InstrumentationDescriptor.TYPE_TRANSACTION,
29+
file: 'http.js'
30+
},
31+
https: {
32+
type: InstrumentationDescriptor.TYPE_TRANSACTION,
33+
file: 'http.js'
34+
},
35+
inspector: {
36+
type: InstrumentationDescriptor.TYPE_GENERIC,
37+
file: 'inspector.js'
38+
},
39+
net: {
40+
type: InstrumentationDescriptor.TYPE_GENERIC,
41+
file: 'net.js'
42+
},
43+
timers: {
44+
type: InstrumentationDescriptor.TYPE_GENERIC,
45+
file: 'timers.js'
46+
},
47+
zlib: {
48+
type: InstrumentationDescriptor.TYPE_GENERIC,
49+
file: 'zlib.js'
50+
}
51+
}

lib/otel/constants.js

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/*
2+
* Copyright 2025 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
8+
// Attribute values are found at:
9+
// https://opentelemetry.io/docs/specs/semconv/attributes-registry/
10+
// Attribute constant names are found at:
11+
// https://github.com/open-telemetry/opentelemetry-js/tree/e744798957ac6d980673262a61634f066d9f66a3/semantic-conventions/src
12+
13+
/**
14+
* Provides a hash of constant attribute names to attribute values as defined
15+
* by the OTEL semantic conventions. The values and names are still very much
16+
* in flux (2025-02). As a result, it is easier for us to copy the ones we need
17+
* here.
18+
*
19+
* 1. Everything should be listed in alphabetical order.
20+
* 2. If an attribute can have multiple names, but all have a common value,
21+
* only list one constant for us to standardize on internally. Make notes of
22+
* the other possible upstream names within the jsdoc for the attribute. If they
23+
* have different values, include multiple attributes with documentation
24+
* referencing which should be favored.
25+
*
26+
* @see https://opentelemetry.io/docs/specs/semconv/
27+
*
28+
* @type {object}
29+
*/
30+
module.exports = {
31+
/**
32+
* Name of the database (schema) being accessed.
33+
*/
34+
ATTR_DB_NAME: 'db.name',
35+
36+
/**
37+
* The name of the database operation being performed.
38+
*
39+
* @example select
40+
* @example findAndModify
41+
*/
42+
ATTR_DB_OPERATION: 'db.operation',
43+
44+
/**
45+
* The table name that is targeted in the operation.
46+
*/
47+
ATTR_DB_SQL_TABLE: 'db.sql.table',
48+
49+
/**
50+
* The database statement being executed.
51+
*
52+
* @example select * from foo
53+
*/
54+
ATTR_DB_STATEMENT: 'db.statement',
55+
56+
/**
57+
* Name of the remote database technology being accessed.
58+
*
59+
* @example mysql
60+
* @see https://opentelemetry.io/docs/specs/semconv/database/sql/
61+
*/
62+
ATTR_DB_SYSTEM: 'db.system',
63+
64+
/**
65+
* The full resource URL.
66+
*
67+
* @example https://example.com/foo?bar=baz
68+
*/
69+
ATTR_FULL_URL: 'url.full',
70+
71+
/**
72+
* Value of the HTTP `host` header.
73+
*
74+
* {@link ATTR_HTTP_REQUEST_METHOD} is newer and should be used instead.
75+
*/
76+
ATTR_HTTP_HOST: 'http.host',
77+
78+
/**
79+
* The HTTP request method, e.g. `GET` or `POST`.
80+
*/
81+
ATTR_HTTP_METHOD: 'http.method',
82+
83+
/**
84+
* HTTP method used for the request, e.g. `GET` or `POST`.
85+
*/
86+
ATTR_HTTP_REQUEST_METHOD: 'http.request.method',
87+
88+
/**
89+
* Framework representation for a route, may include parameter tokens.
90+
*
91+
* @example /orders/:order_id
92+
*/
93+
ATTR_HTTP_ROUTE: 'http.route',
94+
95+
/**
96+
* The full resource URL.
97+
*
98+
* {@link ATTR_FULL_URL} is newer and should be used instead.
99+
*
100+
* @example https://example.com/foo?bar=baz
101+
*/
102+
ATTR_HTTP_URL: 'http.url',
103+
104+
/**
105+
* The message destination name.
106+
*
107+
* {@link ATTR_MESSAGING_DESTINATION_NAME} is newer and should be used.
108+
*/
109+
ATTR_MESSAGING_DESTINATION: 'messaging.destination',
110+
111+
/**
112+
* The kind of message destination (don't really know, this is what the
113+
* otel code calls it).
114+
*/
115+
ATTR_MESSAGING_DESTINATION_KIND: 'messaging.destination_kind',
116+
117+
/**
118+
* The target queue name for the message to be delivered to.
119+
*
120+
* @example MyQueue
121+
* @example MyTopic
122+
*/
123+
ATTR_MESSAGING_DESTINATION_NAME: 'messaging.destination.name',
124+
125+
/**
126+
* Target messaging system name.
127+
*
128+
* @example kafka
129+
* @see https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/
130+
*/
131+
ATTR_MESSAGING_SYSTEM: 'messaging.system',
132+
133+
/**
134+
* The collection being accessed.
135+
*/
136+
ATTR_MONGODB_COLLECTION: 'db.mongodb.collection',
137+
138+
/**
139+
* Remote host name.
140+
*/
141+
ATTR_NET_PEER_NAME: 'net.peer.name',
142+
143+
/**
144+
* Remote port number.
145+
*/
146+
ATTR_NET_PEER_PORT: 'net.peer.port',
147+
148+
/**
149+
* The name of the remote method being invoked.
150+
*/
151+
ATTR_RPC_METHOD: 'rpc.method',
152+
153+
/**
154+
* The logical name of the service being called.
155+
*
156+
* @example myservice.EchoService
157+
*/
158+
ATTR_RPC_SERVICE: 'rpc.service',
159+
160+
/**
161+
* Defines the RPC technology being instrumented. Will be a string name
162+
* for a known RPC system.
163+
*
164+
* @example grpc
165+
* @see https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/
166+
*/
167+
ATTR_RPC_SYSTEM: 'rpc.system',
168+
169+
/**
170+
* Server domain name, IP address, or Unix domain socket.
171+
*
172+
* @example example.com
173+
* @example 10.1.2.80
174+
* @example /tmp/my.sock
175+
*/
176+
ATTR_SERVER_ADDRESS: 'server.address',
177+
178+
/**
179+
* Logical name of the local service being instrumented.
180+
*/
181+
ATTR_SERVICE_NAME: 'service.name',
182+
183+
/**
184+
* URL path component, e.g. `/foo` in `http://example.com/foo`. This is
185+
* the fully realized path. See {@link ATTR_HTTP_ROUTE} for the framework
186+
* representation.
187+
*/
188+
ATTR_URL_PATH: 'url.path',
189+
190+
/**
191+
* The scheme value for the URL.
192+
*
193+
* @example https
194+
*/
195+
ATTR_URL_SCHEME: 'url.scheme',
196+
197+
/* !!! Miscellaneous !!! */
198+
/**
199+
* Database system names.
200+
*
201+
* @example mysql
202+
*/
203+
DB_SYSTEM_VALUES: {
204+
ADABAS: 'adabas',
205+
CACHE: 'cache',
206+
CASSANDRA: 'cassandra',
207+
CLOUDSCAPE: 'cloudscape',
208+
COCKROACHDB: 'cockroachdb',
209+
COLDFUSION: 'coldfusion',
210+
COSMOSDB: 'cosmosdb',
211+
COUCHBASE: 'couchbase',
212+
COUCHDB: 'couchdb',
213+
DB2: 'DB2',
214+
DERBY: 'derby',
215+
DYNAMODB: 'dynamodb',
216+
EDB: 'edb',
217+
ELASTICSEARCH: 'elasticsearch',
218+
FILEMAKER: 'filemaker',
219+
FIREBIRD: 'firebird',
220+
FIRSTSQL: 'firstsql',
221+
GEODE: 'geode',
222+
H2: 'h2',
223+
HANADB: 'handadb',
224+
HBASE: 'hbase',
225+
HIVE: 'hive',
226+
HSQLDB: 'hsqldb',
227+
INFORMIX: 'informix',
228+
INGRESS: 'ingres',
229+
INSTANTDB: 'instantdb',
230+
INTERBASE: 'interbase',
231+
MARIADB: 'mariadb',
232+
MAXDB: 'maxdb',
233+
MEMCACHED: 'memcached',
234+
MONGODB: 'mongodb',
235+
MSSQL: 'mssql',
236+
MYSQL: 'mysql',
237+
NEO4J: 'neo4j',
238+
NETEZZA: 'netezza',
239+
ORACLE: 'oracle',
240+
OTHER_SQL: 'other_sql',
241+
PERVASIVE: 'pervasive',
242+
POINTBASE: 'pointbase',
243+
POSTGRESQL: 'postgresql',
244+
PROGRESS: 'progress',
245+
REDIS: 'redis',
246+
REDSHIFT: 'redshift',
247+
SQLITE: 'sqlite',
248+
SYBASE: 'sybase',
249+
TERADATA: 'teradata',
250+
VERTICA: 'vertica',
251+
},
252+
253+
/**
254+
* Kinds of messaging system destinations.
255+
*/
256+
MESSAGING_SYSTEM_KIND_VALUES: {
257+
QUEUE: 'queue',
258+
TOPIC: 'topic'
259+
}
260+
}

lib/otel/segments/consumer.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ const Transaction = require('../../transaction/')
1616
const { DESTINATIONS, TYPES } = Transaction
1717

1818
const {
19-
SEMATTRS_MESSAGING_SYSTEM,
20-
SEMATTRS_MESSAGING_DESTINATION,
21-
SEMATTRS_MESSAGING_DESTINATION_KIND
22-
} = require('@opentelemetry/semantic-conventions')
19+
ATTR_MESSAGING_DESTINATION,
20+
ATTR_MESSAGING_DESTINATION_KIND,
21+
ATTR_MESSAGING_SYSTEM
22+
} = require('../constants')
2323

2424
function createConsumerSegment(agent, otelSpan) {
2525
const transaction = new Transaction(agent)
2626
transaction.type = TYPES.BG
2727

28-
const system = otelSpan.attributes[SEMATTRS_MESSAGING_SYSTEM] ?? 'unknown'
29-
const destination = otelSpan.attributes[SEMATTRS_MESSAGING_DESTINATION] ?? 'unknown'
30-
const destKind = otelSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] ?? 'unknown'
28+
const system = otelSpan.attributes[ATTR_MESSAGING_SYSTEM] ?? 'unknown'
29+
const destination = otelSpan.attributes[ATTR_MESSAGING_DESTINATION] ?? 'unknown'
30+
const destKind = otelSpan.attributes[ATTR_MESSAGING_DESTINATION_KIND] ?? 'unknown'
3131
const segmentName = `OtherTransaction/Message/${system}/${destKind}/Named/${destination}`
3232

3333
const txAttrs = transaction.trace.attributes

0 commit comments

Comments
 (0)