Skip to content

Commit cda56cc

Browse files
authored
chore: Updated @apm-js-collab/tracing-hooks to latest to take advantage of wasm optimizations (newrelic#3398)
1 parent 56d3c95 commit cda56cc

File tree

8 files changed

+92
-95
lines changed

8 files changed

+92
-95
lines changed

THIRD_PARTY_NOTICES.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
9898

9999
### @apm-js-collab/tracing-hooks
100100

101-
This product includes source derived from [@apm-js-collab/tracing-hooks](https://github.com/apm-js-collab/tracing-hooks) ([v0.1.1](https://github.com/apm-js-collab/tracing-hooks/tree/v0.1.1)), distributed under the [Apache-2.0 License](https://github.com/apm-js-collab/tracing-hooks/blob/v0.1.1/LICENSE):
101+
This product includes source derived from [@apm-js-collab/tracing-hooks](https://github.com/apm-js-collab/tracing-hooks) ([v0.3.1](https://github.com/apm-js-collab/tracing-hooks/tree/v0.3.1)), distributed under the [Apache-2.0 License](https://github.com/apm-js-collab/tracing-hooks/blob/v0.3.1/LICENSE):
102102

103103
```
104104
@@ -308,7 +308,7 @@ This product includes source derived from [@apm-js-collab/tracing-hooks](https:/
308308

309309
### @grpc/grpc-js
310310

311-
This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.13.4](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.13.4)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.13.4/LICENSE):
311+
This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.14.0](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.14.0)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.14.0/LICENSE):
312312

313313
```
314314
Apache License
@@ -726,7 +726,7 @@ This product includes source derived from [@grpc/proto-loader](https://github.co
726726

727727
### @newrelic/security-agent
728728

729-
This product includes source derived from [@newrelic/security-agent](https://github.com/newrelic/csec-node-agent) ([v2.4.3](https://github.com/newrelic/csec-node-agent/tree/v2.4.3)), distributed under the [UNKNOWN License](https://github.com/newrelic/csec-node-agent/blob/v2.4.3/LICENSE):
729+
This product includes source derived from [@newrelic/security-agent](https://github.com/newrelic/csec-node-agent) ([v2.4.4](https://github.com/newrelic/csec-node-agent/tree/v2.4.4)), distributed under the [UNKNOWN License](https://github.com/newrelic/csec-node-agent/blob/v2.4.4/LICENSE):
730730

731731
```
732732
## New Relic Software License v1.0
@@ -1190,7 +1190,7 @@ This product includes source derived from [@opentelemetry/api](https://github.co
11901190

11911191
### @opentelemetry/core
11921192

1193-
This product includes source derived from [@opentelemetry/core](https://github.com/open-telemetry/opentelemetry-js) ([v2.0.1](https://github.com/open-telemetry/opentelemetry-js/tree/v2.0.1)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.0.1/LICENSE):
1193+
This product includes source derived from [@opentelemetry/core](https://github.com/open-telemetry/opentelemetry-js) ([v2.1.0](https://github.com/open-telemetry/opentelemetry-js/tree/v2.1.0)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.1.0/LICENSE):
11941194

11951195
```
11961196
Apache License
@@ -1608,7 +1608,7 @@ This product includes source derived from [@opentelemetry/exporter-metrics-otlp-
16081608

16091609
### @opentelemetry/resources
16101610

1611-
This product includes source derived from [@opentelemetry/resources](https://github.com/open-telemetry/opentelemetry-js) ([v2.0.1](https://github.com/open-telemetry/opentelemetry-js/tree/v2.0.1)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.0.1/LICENSE):
1611+
This product includes source derived from [@opentelemetry/resources](https://github.com/open-telemetry/opentelemetry-js) ([v2.1.0](https://github.com/open-telemetry/opentelemetry-js/tree/v2.1.0)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.1.0/LICENSE):
16121612

16131613
```
16141614
Apache License
@@ -2026,7 +2026,7 @@ This product includes source derived from [@opentelemetry/sdk-logs](https://gith
20262026

20272027
### @opentelemetry/sdk-metrics
20282028

2029-
This product includes source derived from [@opentelemetry/sdk-metrics](https://github.com/open-telemetry/opentelemetry-js) ([v2.0.1](https://github.com/open-telemetry/opentelemetry-js/tree/v2.0.1)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.0.1/LICENSE):
2029+
This product includes source derived from [@opentelemetry/sdk-metrics](https://github.com/open-telemetry/opentelemetry-js) ([v2.1.0](https://github.com/open-telemetry/opentelemetry-js/tree/v2.1.0)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.1.0/LICENSE):
20302030

20312031
```
20322032
Apache License
@@ -2235,7 +2235,7 @@ This product includes source derived from [@opentelemetry/sdk-metrics](https://g
22352235

22362236
### @opentelemetry/sdk-trace-base
22372237

2238-
This product includes source derived from [@opentelemetry/sdk-trace-base](https://github.com/open-telemetry/opentelemetry-js) ([v2.0.1](https://github.com/open-telemetry/opentelemetry-js/tree/v2.0.1)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.0.1/LICENSE):
2238+
This product includes source derived from [@opentelemetry/sdk-trace-base](https://github.com/open-telemetry/opentelemetry-js) ([v2.1.0](https://github.com/open-telemetry/opentelemetry-js/tree/v2.1.0)), distributed under the [Apache-2.0 License](https://github.com/open-telemetry/opentelemetry-js/blob/v2.1.0/LICENSE):
22392239

22402240
```
22412241
Apache License
@@ -2533,7 +2533,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25332533

25342534
### import-in-the-middle
25352535

2536-
This product includes source derived from [import-in-the-middle](https://github.com/nodejs/import-in-the-middle) ([v1.14.2](https://github.com/nodejs/import-in-the-middle/tree/v1.14.2)), distributed under the [Apache-2.0 License](https://github.com/nodejs/import-in-the-middle/blob/v1.14.2/LICENSE):
2536+
This product includes source derived from [import-in-the-middle](https://github.com/nodejs/import-in-the-middle) ([v1.14.4](https://github.com/nodejs/import-in-the-middle/tree/v1.14.4)), distributed under the [Apache-2.0 License](https://github.com/nodejs/import-in-the-middle/blob/v1.14.4/LICENSE):
25372537

25382538
```
25392539
Apache License
@@ -2964,7 +2964,7 @@ SOFTWARE.
29642964

29652965
### @aws-sdk/client-s3
29662966

2967-
This product includes source derived from [@aws-sdk/client-s3](https://github.com/aws/aws-sdk-js-v3) ([v3.872.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.872.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.872.0/LICENSE):
2967+
This product includes source derived from [@aws-sdk/client-s3](https://github.com/aws/aws-sdk-js-v3) ([v3.896.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.896.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.896.0/LICENSE):
29682968

29692969
```
29702970
Apache License
@@ -3173,7 +3173,7 @@ This product includes source derived from [@aws-sdk/client-s3](https://github.co
31733173

31743174
### @aws-sdk/s3-request-presigner
31753175

3176-
This product includes source derived from [@aws-sdk/s3-request-presigner](https://github.com/aws/aws-sdk-js-v3) ([v3.872.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.872.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.872.0/LICENSE):
3176+
This product includes source derived from [@aws-sdk/s3-request-presigner](https://github.com/aws/aws-sdk-js-v3) ([v3.896.0](https://github.com/aws/aws-sdk-js-v3/tree/v3.896.0)), distributed under the [Apache-2.0 License](https://github.com/aws/aws-sdk-js-v3/blob/v3.896.0/LICENSE):
31773177

31783178
```
31793179
Apache License
@@ -5033,7 +5033,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50335033

50345034
### eslint
50355035

5036-
This product includes source derived from [eslint](https://github.com/eslint/eslint) ([v9.33.0](https://github.com/eslint/eslint/tree/v9.33.0)), distributed under the [MIT License](https://github.com/eslint/eslint/blob/v9.33.0/LICENSE):
5036+
This product includes source derived from [eslint](https://github.com/eslint/eslint) ([v9.36.0](https://github.com/eslint/eslint/tree/v9.36.0)), distributed under the [MIT License](https://github.com/eslint/eslint/blob/v9.36.0/LICENSE):
50375037

50385038
```
50395039
Copyright OpenJS Foundation and other contributors, <www.openjsf.org>

esm-loader.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import subscriptions from './lib/subscriber-configs.js'
99
import createSubscriberConfigs from './lib/subscribers/create-config.js'
1010
// Exclusions must be regexes
1111
const exclusions = [/@openai\/agents.*/]
12-
const { packages, instrumentations } = createSubscriberConfigs(subscriptions)
12+
const { instrumentations } = createSubscriberConfigs(subscriptions)
1313

1414
register('@apm-js-collab/tracing-hooks/hook.mjs', import.meta.url, {
15-
data: { instrumentations, packages }
15+
data: { instrumentations }
1616
})
1717
register('import-in-the-middle/hook.mjs', import.meta.url, {
1818
data: { exclude: exclusions }

lib/subscribers/create-config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
* @returns {Object} An object containing a Set of unique package names and an array of instrumentations.
1313
*/
1414
function createSubscribersConfig (subscribers = []) {
15-
const packages = new Set()
1615
const instrumentations = []
17-
for (const [packageName, subscriberList] of Object.entries(subscribers)) {
18-
packages.add(packageName)
16+
for (const subscriberList of Object.values(subscribers)) {
1917
for (const subscriber of subscriberList) {
2018
instrumentations.push(...subscriber.instrumentations)
2119
}
2220
}
2321

24-
return { packages, instrumentations }
22+
return { instrumentations }
2523
}
2624

2725
module.exports = createSubscribersConfig

lib/subscribers/openai/base.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,38 @@ const Subscriber = require('../base')
1010
class OpenAISubscriber extends Subscriber {
1111
constructor({ agent, logger, channelName }) {
1212
super({ agent, logger, packageName: 'openai', channelName })
13-
this.events = ['asyncEnd']
13+
this.events = ['asyncEnd', 'end']
1414
}
1515

1616
get enabled() {
1717
return super.enabled && this.config.ai_monitoring?.enabled
1818
}
19+
20+
/**
21+
* Temporary fix as `tracePromise` wraps the promise in a native one.
22+
* We are now wrapping all openai functions in a `traceSync` call.
23+
* Then we wrap the promise here so it returns the custom promise.
24+
* OpenAI has a [custom promise](https://github.com/openai/openai-node/blob/master/src/core/api-promise.ts).
25+
* see: https://github.com/newrelic/node-newrelic/issues/3379
26+
* see: https://github.com/nodejs/node/issues/59936
27+
* @param data
28+
*/
29+
end(data) {
30+
const promise = data?.result
31+
if (!promise.then) {
32+
return promise
33+
}
34+
35+
return promise.then((result) => {
36+
data.result = result
37+
this.channel.asyncEnd.publish(data)
38+
return result
39+
}).catch((err) => {
40+
data.error = err
41+
this.channel.asyncEnd.publish(data)
42+
return err
43+
})
44+
}
1945
}
2046

2147
module.exports = OpenAISubscriber

lib/subscribers/openai/chat.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const MIN_STREAM_VERSION = '4.12.2'
2323
class OpenAIChatCompletions extends OpenAISubscriber {
2424
constructor({ agent, logger, channelName = 'nr_completionsCreate' }) {
2525
super({ agent, logger, channelName })
26-
this.events = ['asyncEnd', 'end']
2726
}
2827

2928
handler(data, ctx) {
@@ -43,32 +42,6 @@ class OpenAIChatCompletions extends OpenAISubscriber {
4342
return newCtx
4443
}
4544

46-
/**
47-
* Temporary fix as `tracePromise` wraps the promise in a native one.
48-
* We are now wrapping `openai.chat.completions.parse` in a traceSync call
49-
* and then wrapping the promise here so it returns the custom promise.
50-
* OpenAI has a [custom promise](https://github.com/openai/openai-node/blob/master/src/core/api-promise.ts) that crashes applications using `openai.chat.completions.parse`
51-
* see: https://github.com/newrelic/node-newrelic/issues/3379
52-
* see: https://github.com/nodejs/node/issues/59936
53-
* @param data
54-
*/
55-
end(data) {
56-
const promise = data?.result
57-
if (!promise.then) {
58-
return promise
59-
}
60-
61-
return promise.then((result) => {
62-
data.result = result
63-
this.channel.asyncEnd.publish(data)
64-
return result
65-
}).catch((err) => {
66-
data.error = err
67-
this.channel.asyncEnd.publish(data)
68-
return err
69-
})
70-
}
71-
7245
asyncEnd(data) {
7346
const ctx = this.agent.tracer.getContext()
7447
if (!ctx?.segment || !ctx?.transaction) {

lib/subscribers/openai/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = {
5353
functionQuery: {
5454
className: 'APIClient',
5555
methodName: 'makeRequest',
56-
kind: 'Async'
56+
kind: 'Sync'
5757
}
5858
},
5959
{
@@ -62,7 +62,7 @@ module.exports = {
6262
functionQuery: {
6363
className: 'OpenAI',
6464
methodName: 'makeRequest',
65-
kind: 'Async'
65+
kind: 'Sync'
6666
}
6767
}
6868
]
@@ -76,7 +76,7 @@ module.exports = {
7676
functionQuery: {
7777
className: 'Embeddings',
7878
methodName: 'create',
79-
kind: 'Async'
79+
kind: 'Sync'
8080
}
8181
}
8282
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"#test/assert": "./test/lib/custom-assertions/index.js"
202202
},
203203
"dependencies": {
204-
"@apm-js-collab/tracing-hooks": "^0.1.0",
204+
"@apm-js-collab/tracing-hooks": "^0.3.1",
205205
"@grpc/grpc-js": "^1.13.2",
206206
"@grpc/proto-loader": "^0.7.5",
207207
"@newrelic/security-agent": "^2.4.2",

0 commit comments

Comments
 (0)