Skip to content

Commit 96f6c04

Browse files
committed
Runnables subscriber
1 parent 3b22dc1 commit 96f6c04

File tree

10 files changed

+228
-146
lines changed

10 files changed

+228
-146
lines changed

lib/instrumentation/langchain/callback-manager.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/instrumentation/langchain/nr-hooks.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

lib/instrumentation/langchain/tools.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/subscribers/base.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,11 @@ class Subscriber {
376376
subscribe() {
377377
if (!this.events || !Array.isArray(this.events)) {
378378
this.logger.debug('Subscriber does not have valid events to subscribe to.')
379+
return
379380
}
380381
this.subscriptions = this.events.reduce((events, curr) => {
381382
try { events[curr] = this[curr].bind(this) } catch {
382-
this.logger.debug(`Failed to bind subscriber event '${curr}'.`)
383+
this.logger.debug(`Failed to bind subscriber event '${curr}'. Is there a handler for this event?`)
383384
}
384385
return events
385386
}, {})
@@ -388,7 +389,7 @@ class Subscriber {
388389
}
389390

390391
/**
391-
* Unsubscribes from the events defined in the `events` array..
392+
* Unsubscribes from the events defined in the `events` array.
392393
*/
393394
unsubscribe() {
394395
this.channel.unsubscribe(this.subscriptions)

lib/subscribers/langchain/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LangchainSubscriber extends Subscriber {
1717

1818
get enabled() {
1919
if (!this.agent?.config?.ai_monitoring?.enabled) {
20-
this.logger.debug('langchain instrumentation is disabled. To enable set `config.ai_monitoring.enabled` to true')
20+
this.logger.debug('Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.')
2121
}
2222
return super.enabled && this.agent?.config?.ai_monitoring?.enabled
2323
}

lib/subscribers/langchain/config.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const chainCallbackManager = {
8383
channelName: 'nr_handleChainStart',
8484
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/callbacks/manager.cjs' },
8585
functionQuery: {
86+
className: 'CallbackManager',
8687
methodName: 'handleChainStart',
8788
kind: 'Async'
8889
}
@@ -92,13 +93,46 @@ const chainCallbackManager = {
9293
channelName: 'nr_handleChainStart',
9394
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/callbacks/manager.js' },
9495
functionQuery: {
96+
className: 'CallbackManager',
9597
methodName: 'handleChainStart',
9698
kind: 'Async'
9799
}
98100
},
99101
]
100102
}
101103

104+
const runnableInvoke = {
105+
path: './langchain/runnable.js',
106+
instrumentations: [
107+
// CommonJs
108+
{
109+
channelName: 'nr_invoke',
110+
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/runnables/base.cjs' },
111+
functionQuery: {
112+
className: 'RunnableSequence',
113+
methodName: 'invoke',
114+
kind: 'Async'
115+
}
116+
},
117+
// ESM
118+
{
119+
channelName: 'nr_invoke',
120+
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/runnables/base.js' },
121+
functionQuery: {
122+
className: 'RunnableSequence',
123+
methodName: 'invoke',
124+
kind: 'Async'
125+
}
126+
},
127+
]
128+
}
129+
102130
module.exports = {
103-
'@langchain/core': [similaritySearch, toolCall, toolCallbackManager, chainCallbackManager]
131+
'@langchain/core': [
132+
similaritySearch,
133+
toolCall,
134+
toolCallbackManager,
135+
chainCallbackManager,
136+
runnableInvoke
137+
]
104138
}

0 commit comments

Comments
 (0)