Skip to content

Commit 51a3401

Browse files
committed
Cleanup
1 parent def00f0 commit 51a3401

File tree

7 files changed

+15
-35
lines changed

7 files changed

+15
-35
lines changed

lib/instrumentations.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = function instrumentations() {
2727
'generic-pool': { type: InstrumentationDescriptor.TYPE_GENERIC },
2828
kafkajs: { type: InstrumentationDescriptor.TYPE_MESSAGE },
2929
koa: { module: './instrumentation/koa' },
30-
// langchain: { module: './instrumentation/langchain' },
3130
memcached: { type: InstrumentationDescriptor.TYPE_DATASTORE },
3231
mongodb: { type: InstrumentationDescriptor.TYPE_DATASTORE },
3332
next: { module: './instrumentation/nextjs' },

lib/subscribers/langchain/base.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class LangchainSubscriber extends Subscriber {
2121
}
2222

2323
get enabled() {
24-
if (!this.agent?.config?.ai_monitoring?.enabled) {
25-
this.logger.debug('Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.')
26-
}
2724
return super.enabled && this.agent?.config?.ai_monitoring?.enabled
2825
}
2926

lib/subscribers/langchain/runnable-stream.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ class LangchainRunnableStreamSubscriber extends LangchainSubscriber {
1818

1919
handler(data, ctx) {
2020
const { agent, logger } = this
21+
// We need these checks inside the handler because it is possible for monitoring
22+
// to be disabled at the account level. In such a case, the value is set
23+
// after the instrumentation has been initialized.
24+
if (!agent?.config?.ai_monitoring?.enabled) {
25+
this.logger.debug('Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.')
26+
return ctx
27+
}
2128
if (!agent.config?.ai_monitoring?.streaming?.enabled) {
22-
// We need this check inside the handler because it is possible for monitoring
23-
// to be disabled at the account level. In such a case, the value is set
24-
// after the instrumentation has been initialized.
2529
logger.warn('`ai_monitoring.streaming.enabled` is set to `false`, stream will not be instrumented.')
2630
agent.metrics.getOrCreateMetric(STREAMING_DISABLED).incrementCallCount()
2731
agent.metrics
@@ -44,12 +48,6 @@ class LangchainRunnableStreamSubscriber extends LangchainSubscriber {
4448
if (transaction?.isActive() !== true) {
4549
return
4650
}
47-
if (!this?.agent?.config?.ai_monitoring?.streaming?.enabled) {
48-
// ideally, we'd never get here because `handler` this case,
49-
// but the config could possibly get changed in-between the two
50-
// logger warning and metric creation is handled by `handler` so just return here
51-
return
52-
}
5351

5452
const request = data?.arguments?.[0]
5553
const params = data?.arguments?.[1] || {}

lib/subscribers/langchain/runnable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class LangchainRunnableSubscriber extends LangchainSubscriber {
1313
}
1414

1515
handler(data, ctx) {
16-
if (!this.enabled) {
16+
if (!this?.agent?.config?.ai_monitoring?.enabled) {
1717
// We need this check inside the handler because it is possible for monitoring
1818
// to be disabled at the account level. In such a case, the value is set
1919
// after the instrumentation has been initialized.
20+
this.logger.debug('Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.')
2021
return ctx
2122
}
2223

lib/subscribers/langchain/tool.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ class LangchainToolSubscriber extends LangchainSubscriber {
2020
}
2121

2222
handler(data, ctx) {
23-
if (!this.enabled) {
24-
// We need this check inside the wrapper because it is possible for monitoring
23+
if (!this?.agent?.config?.ai_monitoring?.enabled) {
24+
// We need this check inside the handler because it is possible for monitoring
2525
// to be disabled at the account level. In such a case, the value is set
2626
// after the instrumentation has been initialized.
27+
this.logger.debug('Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.')
2728
return ctx
2829
}
2930
const tool = data?.self
@@ -53,14 +54,6 @@ class LangchainToolSubscriber extends LangchainSubscriber {
5354
}
5455
segment.end()
5556

56-
if (!this.enabled) {
57-
// We need this check inside the wrapper because it is possible for monitoring
58-
// to be disabled at the account level. In such a case, the value is set
59-
// after the instrumentation has been initialized.
60-
this.logger.debug('skipping sending of ai data')
61-
return
62-
}
63-
6457
const toolEvent = new LangChainTool({
6558
agent,
6659
description,

lib/subscribers/langchain/vectorstore.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ class LangchainVectorstoreSubscriber extends LangchainSubscriber {
8787
}
8888

8989
handler(data, ctx) {
90-
if (!this.enabled) {
91-
// We need this check inside the wrapper because it is possible for monitoring
90+
if (!this?.agent?.config?.ai_monitoring?.enabled) {
91+
// We need this check inside the handler because it is possible for monitoring
9292
// to be disabled at the account level. In such a case, the value is set
9393
// after the instrumentation has been initialized.
94+
this.logger.debug('Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.')
9495
return ctx
9596
}
9697

@@ -115,14 +116,6 @@ class LangchainVectorstoreSubscriber extends LangchainSubscriber {
115116
}
116117
ctx.segment.end()
117118

118-
if (!this.enabled) {
119-
// We need this check inside the wrapper because it is possible for monitoring
120-
// to be disabled at the account level. In such a case, the value is set
121-
// after the instrumentation has been initialized.
122-
this.logger.debug('skipping sending of ai data')
123-
return
124-
}
125-
126119
this.recordVectorSearch({
127120
request,
128121
k,

test/versioned/langchain/vectorstore.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ test.beforeEach(async (ctx) => {
4242
node: `http://${params.elastic_host}:${params.elastic_port}`
4343
})
4444
}
45-
4645
const { ElasticVectorSearch } = require('@langchain/community/vectorstores/elasticsearch')
4746

4847
ctx.nr.embedding = new OpenAIEmbeddings({

0 commit comments

Comments
 (0)