Repository navigation
test(node): Cover Jev calls inside createAgent and LangGraph #25132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andreiborza
merged 11 commits into
ab/langchain-typesafe-evaluate-spans
from
ab/langchain-jev-middleware-spans
Oct 8, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
164d21d
test(node): Cover Jev model router calls inside createAgent
andreiborza 2e52451
Cover Jev calls inside a LangGraph StateGraph node
andreiborza c9671ef
Assert classifier input and output in agent tests
andreiborza 6b4df51
Move LangGraph Jev test to a v1 suite excluded from the Bun build
andreiborza 9b12d53
Exclude the LangGraph v1 suite from plain Bun runs
andreiborza 32ac119
Expect the transcript form for the router's message state
andreiborza 1388724
Use span streaming in the Jev agent tests and restore the LangGraph i…
andreiborza 8266dd8
Cover the Jev agent span with genAI recording off
andreiborza 71a4276
Remove the flush from the Jev agent scenarios
andreiborza a6b3b5d
Use a caret for the @langchain/typesafe test pins
andreiborza 1045f1d
Restart CI
andreiborza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ges/node-integration-tests/suites/tracing/langchain/v1/scenario-typesafe-model-router.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { ChatAnthropic } from '@langchain/anthropic'; | ||
| import { modelRouterMiddleware } from '@langchain/typesafe/middleware'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import express from 'express'; | ||
| import { createAgent } from 'langchain'; | ||
|
|
||
| function startMockServer() { | ||
| const app = express(); | ||
| app.use(express.json()); | ||
|
|
||
| app.post('/v1/messages', (req, res) => { | ||
| res.json({ | ||
| id: 'msg_router_test', | ||
| type: 'message', | ||
| role: 'assistant', | ||
| content: [{ type: 'text', text: 'A refund is on its way.' }], | ||
| model: req.body.model, | ||
| stop_reason: 'end_turn', | ||
| stop_sequence: null, | ||
| usage: { input_tokens: 10, output_tokens: 5 }, | ||
| }); | ||
| }); | ||
|
|
||
| app.post('/v1/systemone', (req, res) => { | ||
| res.json({ | ||
| model: 'jev-1.13', | ||
| answers: { | ||
| model_route: { type: 'choice', choice: 'fast', probabilities: { fast: 0.9, smart: 0.1 }, confidence: 0.8 }, | ||
| }, | ||
| usage: { input_tokens: 40, output_tokens: 3 }, | ||
| }); | ||
| }); | ||
|
|
||
| return new Promise(resolve => { | ||
| const server = app.listen(0, () => { | ||
| resolve(server); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function run() { | ||
| const server = await startMockServer(); | ||
| const baseUrl = `http://localhost:${server.address().port}`; | ||
|
|
||
| const model = name => new ChatAnthropic({ model: name, apiKey: 'mock-api-key', clientOptions: { baseURL: baseUrl } }); | ||
|
|
||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| const agent = createAgent({ | ||
| name: 'support_agent', | ||
| model: model('claude-3-5-sonnet-20241022'), | ||
| middleware: [ | ||
| modelRouterMiddleware({ | ||
| instructions: 'Pick the model for this request.', | ||
| choices: { | ||
| fast: { model: model('claude-3-5-haiku-20241022'), criteria: 'Simple requests' }, | ||
| smart: { model: model('claude-3-5-sonnet-20241022'), criteria: 'Complex requests' }, | ||
| }, | ||
| classifierOptions: { apiKey: 'mock-api-key', baseUrl }, | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| await agent.invoke({ messages: [{ role: 'user', content: 'Where is my refund?' }] }); | ||
| }); | ||
|
|
||
| server.close(); | ||
| } | ||
|
|
||
| run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
dev-packages/node-integration-tests/suites/tracing/langgraph/v1/instrument-with-pii.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| dataCollection: { genAI: { inputs: true, outputs: true } }, | ||
| transport: loggingTransport, | ||
| }); |
10 changes: 10 additions & 0 deletions
10
dev-packages/node-integration-tests/suites/tracing/langgraph/v1/instrument.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| dataCollection: { genAI: { inputs: false, outputs: false } }, | ||
| transport: loggingTransport, | ||
| }); |
37 changes: 37 additions & 0 deletions
37
.../node-integration-tests/suites/tracing/langgraph/v1/scenario-typesafe-classifier-node.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { Annotation, END, START, StateGraph } from '@langchain/langgraph'; | ||
| import { TypeSafeClassifier } from '@langchain/typesafe'; | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| // Answer in-process through the classifier's `fetch` option, so no mock server is needed. | ||
| async function mockTypeSafeFetch() { | ||
| return new Response( | ||
| JSON.stringify({ | ||
| model: 'jev-1.13', | ||
| answers: { urgent: { type: 'noul', noul: 0.9 } }, | ||
| usage: { input_tokens: 30, output_tokens: 2 }, | ||
| }), | ||
| { headers: { 'content-type': 'application/json' } }, | ||
| ); | ||
| } | ||
|
|
||
| async function run() { | ||
| const classifier = new TypeSafeClassifier({ | ||
| apiKey: 'mock-api-key', | ||
| fetch: mockTypeSafeFetch, | ||
| questions: { urgent: { type: 'noul', instructions: 'Is this urgent?' } }, | ||
| }); | ||
|
|
||
| const State = Annotation.Root({ ticket: Annotation(), urgent: Annotation() }); | ||
|
|
||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| const graph = new StateGraph(State) | ||
| .addNode('triage', async state => ({ urgent: (await classifier.invoke(state.ticket)).nouls.urgent.noul })) | ||
| .addEdge(START, 'triage') | ||
| .addEdge('triage', END) | ||
| .compile({ name: 'triage_graph' }); | ||
|
|
||
| await graph.invoke({ ticket: 'My payouts have been failing.' }); | ||
| }); | ||
| } | ||
|
|
||
| run(); |
88 changes: 88 additions & 0 deletions
88
dev-packages/node-integration-tests/suites/tracing/langgraph/v1/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { | ||
| GEN_AI_AGENT_NAME, | ||
| GEN_AI_INPUT_MESSAGES, | ||
| GEN_AI_OUTPUT_MESSAGES, | ||
| SENTRY_OP, | ||
| SENTRY_ORIGIN, | ||
| } from '@sentry/conventions/attributes'; | ||
| import { GEN_AI_EVALUATE } from '@sentry/conventions/op'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner'; | ||
|
|
||
| describe('LangGraph integration (v1)', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests( | ||
| __dirname, | ||
| 'scenario-typesafe-classifier-node.mjs', | ||
| 'instrument-with-pii.mjs', | ||
| (createRunner, test) => { | ||
| test('records a TypeSafeClassifier call made inside a StateGraph node', async () => { | ||
| const runner = createRunner(); | ||
| const spansPromise = runner.collectStreamedSpansUntilSegment('main'); | ||
|
|
||
| await runner.start().completed(); | ||
|
|
||
| const spans = await spansPromise; | ||
| const rootSpan = spans.find(span => span.is_segment && span.name === 'main')!; | ||
| const agentSpan = spans.find(span => span.name === 'invoke_agent triage_graph')!; | ||
| const evaluateSpan = spans.find(span => span.name === 'evaluate jev-latest')!; | ||
|
|
||
| expect(agentSpan.parent_span_id).toBe(rootSpan.span_id); | ||
| expect(evaluateSpan.parent_span_id).toBe(agentSpan.span_id); | ||
| expect(evaluateSpan.attributes[SENTRY_OP].value).toBe(GEN_AI_EVALUATE); | ||
| expect(evaluateSpan.attributes[SENTRY_ORIGIN].value).toBe('auto.ai.langchain'); | ||
| expect(evaluateSpan.attributes[GEN_AI_AGENT_NAME].value).toBe('triage_graph'); | ||
| expect(JSON.parse(evaluateSpan.attributes[GEN_AI_INPUT_MESSAGES].value)).toEqual([ | ||
| { | ||
| type: 'evaluation', | ||
| state: 'My payouts have been failing.', | ||
| questions: { urgent: { type: 'noul', instructions: 'Is this urgent?' } }, | ||
| }, | ||
| ]); | ||
| expect(JSON.parse(evaluateSpan.attributes[GEN_AI_OUTPUT_MESSAGES].value)).toEqual([ | ||
| { type: 'evaluation', answers: { urgent: { type: 'noul', noul: 0.9 } } }, | ||
| ]); | ||
| }); | ||
| }, | ||
| { | ||
| additionalDependencies: { | ||
| langchain: '^1.0.0', | ||
| '@langchain/core': '^1.0.0', | ||
| '@langchain/langgraph': '^1.0.0', | ||
| '@langchain/typesafe': '^0.0.2', | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| createEsmAndCjsTests( | ||
| __dirname, | ||
| 'scenario-typesafe-classifier-node.mjs', | ||
| 'instrument.mjs', | ||
| (createRunner, test) => { | ||
| test('omits the classifier input and output when genAI recording is off', async () => { | ||
| const runner = createRunner(); | ||
| const spansPromise = runner.collectStreamedSpansUntilSegment('main'); | ||
|
|
||
| await runner.start().completed(); | ||
|
|
||
| const spans = await spansPromise; | ||
| const evaluateSpan = spans.find(span => span.name === 'evaluate jev-latest')!; | ||
|
|
||
| expect(evaluateSpan.attributes[SENTRY_OP].value).toBe(GEN_AI_EVALUATE); | ||
| expect(evaluateSpan.attributes[GEN_AI_INPUT_MESSAGES]).toBeUndefined(); | ||
| expect(evaluateSpan.attributes[GEN_AI_OUTPUT_MESSAGES]).toBeUndefined(); | ||
| }); | ||
| }, | ||
| { | ||
| additionalDependencies: { | ||
| langchain: '^1.0.0', | ||
| '@langchain/core': '^1.0.0', | ||
| '@langchain/langgraph': '^1.0.0', | ||
| '@langchain/typesafe': '^0.0.2', | ||
| }, | ||
| }, | ||
| ); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.