Skip to content

Commit 42c64c5

Browse files
committed
Add chain test for langchain node (not working yet)
1 parent 6d7f16f commit 42c64c5

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

dev-packages/node-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@langchain/anthropic": "^0.3.10",
3333
"@langchain/core": "^0.3.28",
3434
"@langchain/langgraph": "^0.2.32",
35+
"langchain": "^0.3.8",
3536
"@nestjs/common": "^11",
3637
"@nestjs/core": "^11",
3738
"@nestjs/platform-express": "^11",

dev-packages/node-integration-tests/suites/tracing/langchain/scenario.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PromptTemplate } from "@langchain/core/prompts";
2+
import { LLMChain } from "langchain/chains";
13
import { ChatAnthropic } from '@langchain/anthropic';
24
import * as Sentry from '@sentry/node';
35
import express from 'express';
@@ -56,12 +58,18 @@ async function run() {
5658
const baseUrl = `http://localhost:${server.address().port}`;
5759

5860
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
61+
const callbackHandler = Sentry.createLangChainCallbackHandler({
62+
recordInputs: false,
63+
recordOutputs: false,
64+
});
65+
5966
// Test 1: Basic chat model invocation
6067
const model1 = new ChatAnthropic({
6168
model: 'claude-3-5-sonnet-20241022',
6269
temperature: 0.7,
6370
maxTokens: 100,
6471
apiKey: 'mock-api-key',
72+
callbacks: [callbackHandler],
6573
clientOptions: {
6674
baseURL: baseUrl,
6775
},
@@ -100,6 +108,21 @@ async function run() {
100108
} catch {
101109
// Expected error
102110
}
111+
112+
// Test 4: Chain invocation
113+
const prompt = new PromptTemplate({
114+
input_variables: ["country"],
115+
template: "What is the capital of {country}?",
116+
});
117+
const chain = new LLMChain({
118+
llm: model1,
119+
prompt: prompt,
120+
callbacks: [callbackHandler],
121+
});
122+
await chain.invoke(
123+
{'country': 'France'},
124+
{ callbacks: [callbackHandler] }
125+
);
103126
});
104127

105128
await Sentry.flush(2000);

dev-packages/node-integration-tests/suites/tracing/langchain/test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ describe('LangChain integration', () => {
6868
origin: 'auto.ai.langchain',
6969
status: 'internal_error',
7070
}),
71+
// Fourth span - chain invocation
72+
expect.objectContaining({
73+
data: expect.objectContaining({
74+
'sentry.origin': 'auto.ai.langchain',
75+
'sentry.op': 'gen_ai.invoke_agent',
76+
'langchain.chain.name': 'my_test_chain',
77+
}),
78+
}),
7179
]),
7280
};
7381

@@ -138,6 +146,14 @@ describe('LangChain integration', () => {
138146
origin: 'auto.ai.langchain',
139147
status: 'internal_error',
140148
}),
149+
// Fourth span - chain invocation
150+
expect.objectContaining({
151+
data: expect.objectContaining({
152+
'sentry.origin': 'auto.ai.langchain',
153+
'sentry.op': 'gen_ai.invoke_agent',
154+
'langchain.chain.name': 'my_test_chain',
155+
}),
156+
}),
141157
]),
142158
};
143159

yarn.lock

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4992,6 +4992,22 @@
49924992
"@langchain/langgraph-sdk" "~1.0.0"
49934993
uuid "^10.0.0"
49944994

4995+
"@langchain/openai@>=0.1.0 <0.7.0":
4996+
version "0.6.17"
4997+
resolved "https://registry.yarnpkg.com/@langchain/openai/-/openai-0.6.17.tgz#6e87064316d6834b7cfb88a2df2ea7ee2a4b0325"
4998+
integrity sha512-JVSzD+FL5v/2UQxKd+ikB1h4PQOtn0VlK8nqW2kPp0fshItCv4utrjBKXC/rubBnSXoRTyonBINe8QRZ6OojVQ==
4999+
dependencies:
5000+
js-tiktoken "^1.0.12"
5001+
openai "5.12.2"
5002+
zod "^3.25.32"
5003+
5004+
"@langchain/textsplitters@>=0.0.0 <0.2.0":
5005+
version "0.1.0"
5006+
resolved "https://registry.yarnpkg.com/@langchain/textsplitters/-/textsplitters-0.1.0.tgz#f37620992192df09ecda3dfbd545b36a6bcbae46"
5007+
integrity sha512-djI4uw9rlkAb5iMhtLED+xJebDdAG935AdP4eRTB02R7OB/act55Bj9wsskhZsvuyQRpO4O1wQOp85s6T6GWmw==
5008+
dependencies:
5009+
js-tiktoken "^1.0.12"
5010+
49955011
"@leichtgewicht/ip-codec@^2.0.1":
49965012
version "2.0.4"
49975013
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
@@ -20536,6 +20552,11 @@ jsonparse@^1.2.0, jsonparse@^1.3.1:
2053620552
resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
2053720553
integrity sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==
2053820554

20555+
jsonpointer@^5.0.1:
20556+
version "5.0.1"
20557+
resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-5.0.1.tgz#2110e0af0900fd37467b5907ecd13a7884a1b559"
20558+
integrity sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==
20559+
2053920560
jsonwebtoken@^9.0.0:
2054020561
version "9.0.2"
2054120562
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz#65ff91f4abef1784697d40952bb1998c504caaf3"
@@ -20714,6 +20735,23 @@ lambda-local@^2.2.0:
2071420735
dotenv "^16.3.1"
2071520736
winston "^3.10.0"
2071620737

20738+
langchain@^0.3.8:
20739+
version "0.3.37"
20740+
resolved "https://registry.yarnpkg.com/langchain/-/langchain-0.3.37.tgz#6931ee5af763a6df35c0ac467eab028ba0ad17de"
20741+
integrity sha512-1jPsZ6xsxkcQPUvqRjvfuOLwZLLyt49hzcOK7OYAJovIkkOxd5gzK4Yw6giPUQ8g4XHyvULNlWBz+subdkcokw==
20742+
dependencies:
20743+
"@langchain/openai" ">=0.1.0 <0.7.0"
20744+
"@langchain/textsplitters" ">=0.0.0 <0.2.0"
20745+
js-tiktoken "^1.0.12"
20746+
js-yaml "^4.1.0"
20747+
jsonpointer "^5.0.1"
20748+
langsmith "^0.3.67"
20749+
openapi-types "^12.1.3"
20750+
p-retry "4"
20751+
uuid "^10.0.0"
20752+
yaml "^2.2.1"
20753+
zod "^3.25.32"
20754+
2071720755
langsmith@^0.3.67:
2071820756
version "0.3.74"
2071920757
resolved "https://registry.npmjs.org/langsmith/-/langsmith-0.3.74.tgz#014d31a9ff7530b54f0d797502abd512ce8fb6fb"
@@ -24172,11 +24210,21 @@ open@^9.1.0:
2417224210
is-inside-container "^1.0.0"
2417324211
is-wsl "^2.2.0"
2417424212

24213+
24214+
version "5.12.2"
24215+
resolved "https://registry.yarnpkg.com/openai/-/openai-5.12.2.tgz#512ab6b80eb8414837436e208f1b951442b97761"
24216+
integrity sha512-xqzHHQch5Tws5PcKR2xsZGX9xtch+JQFz5zb14dGqlshmmDAFBFEWmeIpf7wVqWV+w7Emj7jRgkNJakyKE0tYQ==
24217+
2417524218
2417624219
version "5.18.1"
2417724220
resolved "https://registry.yarnpkg.com/openai/-/openai-5.18.1.tgz#1c4884aefcada7ec684771e03c860c381f1902c1"
2417824221
integrity sha512-iXSOfLlOL+jgnFr5CGrB2SEZw5C92o1nrFW2SasoAXj4QxGhfeJPgg8zkX+vaCfX80cT6CWjgaGnq7z9XzbyRw==
2417924222

24223+
openapi-types@^12.1.3:
24224+
version "12.1.3"
24225+
resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-12.1.3.tgz#471995eb26c4b97b7bd356aacf7b91b73e777dd3"
24226+
integrity sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==
24227+
2418024228
opener@^1.5.2:
2418124229
version "1.5.2"
2418224230
resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598"
@@ -32148,6 +32196,11 @@ yaml@^1.10.0, yaml@^1.10.2:
3214832196
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
3214932197
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==
3215032198

32199+
yaml@^2.2.1:
32200+
version "2.8.2"
32201+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.8.2.tgz#5694f25eca0ce9c3e7a9d9e00ce0ddabbd9e35c5"
32202+
integrity sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==
32203+
3215132204
yaml@^2.5.0:
3215232205
version "2.5.1"
3215332206
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.5.1.tgz#c9772aacf62cb7494a95b0c4f1fb065b563db130"

0 commit comments

Comments
 (0)