Skip to content

Commit d77239e

Browse files
chore: Change Langchain to LangChain, expand version range (newrelic#3629)
1 parent b4f0010 commit d77239e

File tree

9 files changed

+44
-42
lines changed

9 files changed

+44
-42
lines changed

lib/metrics/names.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ AI.BEDROCK = {
191191
}
192192

193193
AI.LANGCHAIN = {
194-
TRACKING_PREFIX: `${AI.TRACKING_PREFIX}/Langchain`,
195-
EMBEDDING: `${AI.EMBEDDING}/Langchain`,
196-
COMPLETION: `${AI.COMPLETION}/Langchain`,
197-
TOOL: `${AI.TOOL}/Langchain`,
198-
CHAIN: `${AI.CHAIN}/Langchain`,
199-
VECTORSTORE: `${AI.VECTORSTORE}/Langchain`
194+
TRACKING_PREFIX: `${AI.TRACKING_PREFIX}/LangChain`,
195+
EMBEDDING: `${AI.EMBEDDING}/LangChain`,
196+
COMPLETION: `${AI.COMPLETION}/LangChain`,
197+
TOOL: `${AI.TOOL}/LangChain`,
198+
CHAIN: `${AI.CHAIN}/LangChain`,
199+
VECTORSTORE: `${AI.VECTORSTORE}/LangChain`
200200
}
201201

202202
const MCP = {

lib/subscribers/langchain/config.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const similaritySearch = {
99
// CommonJs
1010
{
1111
channelName: 'nr_similaritySearch',
12-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/vectorstores.cjs' },
12+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/vectorstores.cjs' },
1313
functionQuery: {
1414
methodName: 'similaritySearch',
1515
kind: 'Async'
@@ -18,7 +18,7 @@ const similaritySearch = {
1818
// ESM
1919
{
2020
channelName: 'nr_similaritySearch',
21-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/vectorstores.js' },
21+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/vectorstores.js' },
2222
functionQuery: {
2323
methodName: 'similaritySearch',
2424
kind: 'Async'
@@ -33,7 +33,7 @@ const toolCall = {
3333
// CommonJs
3434
{
3535
channelName: 'nr_call',
36-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/tools/index.cjs' },
36+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/tools/index.cjs' },
3737
functionQuery: {
3838
methodName: 'call',
3939
kind: 'Async'
@@ -42,7 +42,7 @@ const toolCall = {
4242
// ESM
4343
{
4444
channelName: 'nr_call',
45-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/tools/index.js' },
45+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/tools/index.js' },
4646
functionQuery: {
4747
methodName: 'call',
4848
kind: 'Async'
@@ -57,7 +57,7 @@ const toolCallbackManager = {
5757
// CommonJs
5858
{
5959
channelName: 'nr_handleToolStart',
60-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/callbacks/manager.cjs' },
60+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/callbacks/manager.cjs' },
6161
functionQuery: {
6262
methodName: 'handleToolStart',
6363
kind: 'Async'
@@ -66,7 +66,7 @@ const toolCallbackManager = {
6666
// ESM
6767
{
6868
channelName: 'nr_handleToolStart',
69-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/callbacks/manager.js' },
69+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/callbacks/manager.js' },
7070
functionQuery: {
7171
methodName: 'handleToolStart',
7272
kind: 'Async'
@@ -81,7 +81,7 @@ const chainCallbackManager = {
8181
// CommonJs
8282
{
8383
channelName: 'nr_handleChainStart',
84-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/callbacks/manager.cjs' },
84+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/callbacks/manager.cjs' },
8585
functionQuery: {
8686
className: 'CallbackManager',
8787
methodName: 'handleChainStart',
@@ -91,7 +91,7 @@ const chainCallbackManager = {
9191
// ESM
9292
{
9393
channelName: 'nr_handleChainStart',
94-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/callbacks/manager.js' },
94+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/callbacks/manager.js' },
9595
functionQuery: {
9696
className: 'CallbackManager',
9797
methodName: 'handleChainStart',
@@ -107,7 +107,7 @@ const runnableInvoke = {
107107
// CommonJs
108108
{
109109
channelName: 'nr_invoke',
110-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/runnables/base.cjs' },
110+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/runnables/base.cjs' },
111111
functionQuery: {
112112
className: 'RunnableSequence',
113113
methodName: 'invoke',
@@ -117,7 +117,7 @@ const runnableInvoke = {
117117
// ESM
118118
{
119119
channelName: 'nr_invoke',
120-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/runnables/base.js' },
120+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/runnables/base.js' },
121121
functionQuery: {
122122
className: 'RunnableSequence',
123123
methodName: 'invoke',
@@ -133,7 +133,7 @@ const runnableStream = {
133133
// CommonJs
134134
{
135135
channelName: 'nr_stream',
136-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/runnables/base.cjs' },
136+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/runnables/base.cjs' },
137137
functionQuery: {
138138
methodName: 'stream',
139139
kind: 'Async'
@@ -142,7 +142,7 @@ const runnableStream = {
142142
// ESM
143143
{
144144
channelName: 'nr_stream',
145-
module: { name: '@langchain/core', versionRange: '>=1.0.0', filePath: 'dist/runnables/base.js' },
145+
module: { name: '@langchain/core', versionRange: '>=0.0.0', filePath: 'dist/runnables/base.js' },
146146
functionQuery: {
147147
methodName: 'stream',
148148
kind: 'Async'

test/versioned/langchain-aws/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
"engines": {
1818
"node": ">=20"
1919
},
20+
"comment": "because @langchain/core and @langchain/aws need to be same major version, we will only test >=1.0.0 for both of them",
2021
"dependencies": {
21-
"@langchain/aws": ">=1.1.0",
22+
"@langchain/aws": ">=1.0.0",
2223
"@langchain/core": ">=1.0.0",
2324
"@langchain/community": ">=1.0.0",
2425
"@elastic/elasticsearch": "8.13.1"

test/versioned/langchain-openai/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"engines": {
1818
"node": ">=20"
1919
},
20+
"comment": "because @langchain/core and @langchain/openai need to be same major version, we will only test >=1.0.0 for both of them",
2021
"dependencies": {
2122
"@langchain/core": ">=1.0.0",
2223
"@langchain/community": ">=1.0.0",

test/versioned/langchain/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"node": ">=20"
1919
},
2020
"dependencies": {
21-
"@langchain/core": ">=1.0.0"
21+
"@langchain/core": ">=0.0.0"
2222
},
2323
"files": [
2424
"tools.test.js"

test/versioned/langchain/runnables-streaming.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function runStreamingEnabledTests(config) {
102102
}
103103

104104
const metrics = agent.metrics.getOrCreateMetric(
105-
`Supportability/Nodejs/ML/Langchain/${langchainCoreVersion}`
105+
`Supportability/Nodejs/ML/LangChain/${langchainCoreVersion}`
106106
)
107107
assert.equal(metrics.callCount > 0, true)
108108

@@ -419,9 +419,9 @@ function runStreamingEnabledTests(config) {
419419
consumeStreamChunk(chunk)
420420
}
421421

422-
assertSegments(tx.trace, tx.trace.root, ['Llm/chain/Langchain/stream'], { exact: false })
422+
assertSegments(tx.trace, tx.trace.root, ['Llm/chain/LangChain/stream'], { exact: false })
423423
tx.end()
424-
assertSpanKind({ agent, segments: [{ name: 'Llm/chain/Langchain/stream', kind: 'internal' }] })
424+
assertSpanKind({ agent, segments: [{ name: 'Llm/chain/LangChain/stream', kind: 'internal' }] })
425425
end()
426426
})
427427
})
@@ -590,7 +590,7 @@ function runStreamingEnabledTests(config) {
590590
const stream = await chain.stream(input)
591591

592592
const [segment] = tx.trace.getChildren(tx.trace.root.id)
593-
assert.equal(segment.name, 'Llm/chain/Langchain/stream', 'should find the Langchain stream segment')
593+
assert.equal(segment.name, 'Llm/chain/LangChain/stream', 'should find the Langchain stream segment')
594594

595595
let chunkCount = 0
596596
for await (const chunk of stream) {
@@ -648,7 +648,7 @@ function runStreamingDisabledTest(config) {
648648
const events = agent.customEventAggregator.events.toArray()
649649
assert.equal(events.length, 0, 'should not create llm events when streaming is disabled')
650650
const metrics = agent.metrics.getOrCreateMetric(
651-
`Supportability/Nodejs/ML/Langchain/${langchainCoreVersion}`
651+
`Supportability/Nodejs/ML/LangChain/${langchainCoreVersion}`
652652
)
653653
assert.equal(metrics.callCount > 0, true)
654654
const attributes = tx.trace.attributes.get(DESTINATIONS.TRANS_EVENT)
@@ -683,8 +683,8 @@ function runStreamingDisabledTest(config) {
683683
consumeStreamChunk(chunk)
684684
}
685685

686-
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/chain/Langchain/stream')
687-
assert.equal(segment, undefined, 'should not create Llm/chain/Langchain/stream segment when ai_monitoring is disabled')
686+
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/chain/LangChain/stream')
687+
assert.equal(segment, undefined, 'should not create Llm/chain/LangChain/stream segment when ai_monitoring is disabled')
688688

689689
tx.end()
690690
end()
@@ -753,8 +753,8 @@ function runAiMonitoringDisabledTests(config) {
753753
consumeStreamChunk(chunk)
754754
}
755755

756-
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/chain/Langchain/stream')
757-
assert.equal(segment, undefined, 'should not create Llm/chain/Langchain/stream segment when ai_monitoring is disabled')
756+
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/chain/LangChain/stream')
757+
assert.equal(segment, undefined, 'should not create Llm/chain/LangChain/stream segment when ai_monitoring is disabled')
758758

759759
tx.end()
760760
end()

test/versioned/langchain/runnables.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function runRunnablesTests(config) {
8282
await chain.invoke(input, options)
8383

8484
const metrics = agent.metrics.getOrCreateMetric(
85-
`Supportability/Nodejs/ML/Langchain/${langchainCoreVersion}`
85+
`Supportability/Nodejs/ML/LangChain/${langchainCoreVersion}`
8686
)
8787
assert.equal(metrics.callCount > 0, true)
8888

@@ -389,9 +389,9 @@ function runRunnablesTests(config) {
389389
const result = await chain.invoke(input, options)
390390

391391
assert.ok(result)
392-
assertSegments(tx.trace, tx.trace.root, ['Llm/chain/Langchain/invoke'], { exact: false })
392+
assertSegments(tx.trace, tx.trace.root, ['Llm/chain/LangChain/invoke'], { exact: false })
393393
tx.end()
394-
assertSpanKind({ agent, segments: [{ name: 'Llm/chain/Langchain/invoke', kind: 'internal' }] })
394+
assertSpanKind({ agent, segments: [{ name: 'Llm/chain/LangChain/invoke', kind: 'internal' }] })
395395
end()
396396
})
397397
})
@@ -491,8 +491,8 @@ function runRunnablesTests(config) {
491491
const result = await chain.invoke(input)
492492
assert.ok(result, 'should not mess up result')
493493

494-
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/chain/Langchain/stream')
495-
assert.equal(segment, undefined, 'should not create Llm/chain/Langchain/stream segment when ai_monitoring is disabled')
494+
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/chain/LangChain/stream')
495+
assert.equal(segment, undefined, 'should not create Llm/chain/LangChain/stream segment when ai_monitoring is disabled')
496496

497497
tx.end()
498498
end()

test/versioned/langchain/tools.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ test('should create span on successful tools create', (t, end) => {
5050
helper.runInTransaction(agent, async (tx) => {
5151
const result = await tool.call(input)
5252
assert.ok(result)
53-
assertSegments(tx.trace, tx.trace.root, ['Llm/tool/Langchain/node-agent-test-tool'], {
53+
assertSegments(tx.trace, tx.trace.root, ['Llm/tool/LangChain/node-agent-test-tool'], {
5454
exact: false
5555
})
5656
tx.end()
57-
assertSpanKind({ agent, segments: [{ name: 'Llm/tool/Langchain/node-agent-test-tool', kind: 'internal' }] })
57+
assertSpanKind({ agent, segments: [{ name: 'Llm/tool/LangChain/node-agent-test-tool', kind: 'internal' }] })
5858
end()
5959
})
6060
})
@@ -65,7 +65,7 @@ test('should increment tracking metric for each tool event', (t, end) => {
6565
await tool.call(input)
6666

6767
const metrics = agent.metrics.getOrCreateMetric(
68-
`Supportability/Nodejs/ML/Langchain/${pkgVersion}`
68+
`Supportability/Nodejs/ML/LangChain/${pkgVersion}`
6969
)
7070
assert.equal(metrics.callCount > 0, true)
7171

test/versioned/langchain/vectorstore.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ function runVectorstoreTests(config) {
6767
helper.runInTransaction(agent, async (tx) => {
6868
const result = await vs.similaritySearch(searchQuery, 1)
6969
assert.ok(result)
70-
assertSegments(tx.trace, tx.trace.root, ['Llm/vectorstore/Langchain/similaritySearch'], {
70+
assertSegments(tx.trace, tx.trace.root, ['Llm/vectorstore/LangChain/similaritySearch'], {
7171
exact: false
7272
})
7373
tx.end()
74-
assertSpanKind({ agent, segments: [{ name: 'Llm/vectorstore/Langchain/similaritySearch', kind: 'internal' }] })
74+
assertSpanKind({ agent, segments: [{ name: 'Llm/vectorstore/LangChain/similaritySearch', kind: 'internal' }] })
7575
end()
7676
})
7777
})
@@ -87,7 +87,7 @@ function runVectorstoreTests(config) {
8787
// version. Find the right one that has a call count
8888

8989
for (const metric in agent.metrics._metrics.unscoped) {
90-
if (metric.startsWith('Supportability/Nodejs/ML/Langchain')) {
90+
if (metric.startsWith('Supportability/Nodejs/ML/LangChain')) {
9191
plan.equal(agent.metrics._metrics.unscoped[metric].callCount > 0, true)
9292
}
9393
}
@@ -263,8 +263,8 @@ function runVectorstoreTests(config) {
263263
helper.runInTransaction(agent, async (tx) => {
264264
await vs.similaritySearch(searchQuery, 1)
265265

266-
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/vectorstore/Langchain/similaritySearch')
267-
assert.equal(segment, undefined, 'should not create Llm/vectorstore/Langchain/similaritySearch segment when ai_monitoring is disabled')
266+
const segment = findSegment(tx.trace, tx.trace.root, 'Llm/vectorstore/LangChain/similaritySearch')
267+
assert.equal(segment, undefined, 'should not create Llm/vectorstore/LangChain/similaritySearch segment when ai_monitoring is disabled')
268268

269269
tx.end()
270270
end()

0 commit comments

Comments
 (0)