-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Instrument langgraph createReactAgent #18403
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
Open
nicohrubec
wants to merge
37
commits into
develop
Choose a base branch
from
nh/langgraph-no-invoke-agent
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
cee1039
Add failing test
nicohrubec 877b10e
Try to instrument createReactAgent (doesn't work yet)
nicohrubec da96451
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec 335ee5a
Use two modules
nicohrubec 40cde73
clean comment
nicohrubec 819cf39
Split patch for main and prebuilt langgraph modules
nicohrubec 435ee61
revert stuff
nicohrubec 0246624
now we get some spans for cjs
nicohrubec e9862c0
try to fix esm with explicit file wrap
nicohrubec d503485
Fix formatting
nicohrubec 481fc12
try catch
nicohrubec 5ec4427
Revert "try catch"
nicohrubec 25a7524
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec cade4aa
bump iitm
nicohrubec c529f1b
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec 5ac942f
resolve iitm
nicohrubec 703c29a
remove file
nicohrubec 7e81978
try as separate module
nicohrubec 8df7871
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec f21ecda
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec e22b707
fix(tracing): get llm request model in createReactAgent
isaacs ffe34fb
fix(tracing): patch @langchain/langgraph/prebuilt in ESM mode
isaacs b3ad20a
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec 180e987
iitm 2.0.0
nicohrubec 7cf8796
revert yarn.lock
nicohrubec 957b6ed
revert yarn.lock
nicohrubec 8231651
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec 4fa35c7
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec df9c9d2
chore: update @opentelemetry dependencies
isaacs 021b2be
Merge remote-tracking branch 'origin/develop' into nh/langgraph-no-in…
isaacs 8b05eaa
fix opentelemetry instrumentation in node unit test
isaacs 121bd49
fix lint
isaacs bf435e6
fix: load langgraph/prebuilt ESM file properly
isaacs 7be8df2
fix flaky langgraph test, exclude Express spans
isaacs b086742
Merge branch 'develop' into nh/langgraph-no-invoke-agent
nicohrubec 0920edf
constants
nicohrubec 11a976f
fix file formatting
nicohrubec 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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
dev-packages/node-integration-tests/suites/tracing/langgraph/agent-scenario.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,70 @@ | ||
| import { ChatAnthropic } from '@langchain/anthropic'; | ||
| import { HumanMessage, SystemMessage } from '@langchain/core/messages'; | ||
| import { createReactAgent } from '@langchain/langgraph/prebuilt'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import express from 'express'; | ||
|
|
||
| function startMockAnthropicServer() { | ||
| const app = express(); | ||
| app.use(express.json()); | ||
|
|
||
| app.post('/v1/messages', (req, res) => { | ||
| const model = req.body.model; | ||
|
|
||
| // Simulate basic response | ||
| res.json({ | ||
| id: 'msg_react_agent_123', | ||
| type: 'message', | ||
| role: 'assistant', | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: 'Mock response from Anthropic!', | ||
| }, | ||
| ], | ||
| model: model, | ||
| stop_reason: 'end_turn', | ||
| stop_sequence: null, | ||
| usage: { | ||
| input_tokens: 10, | ||
| output_tokens: 15, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| return new Promise(resolve => { | ||
| const server = app.listen(0, () => { | ||
| resolve(server); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function run() { | ||
| const server = await startMockAnthropicServer(); | ||
| const baseUrl = `http://localhost:${server.address().port}`; | ||
|
|
||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| // Create mocked LLM instance | ||
| const llm = new ChatAnthropic({ | ||
| model: 'claude-3-5-sonnet-20241022', | ||
| apiKey: 'mock-api-key', | ||
| clientOptions: { | ||
| baseURL: baseUrl, | ||
| }, | ||
| }); | ||
|
|
||
| // Create a simple react agent with no tools | ||
| const agent = createReactAgent({ llm, tools: [] }); | ||
|
|
||
| // Test: basic invocation | ||
| await agent.invoke({ | ||
| messages: [new SystemMessage('You are a helpful assistant.'), new HumanMessage('What is the weather today?')], | ||
| }); | ||
| }); | ||
|
|
||
| await Sentry.flush(2000); | ||
|
|
||
| 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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mechanism type doesn't align with span origin
Low Severity
In the new
instrumentCreateReactAgentfunction, themechanism.typeis set to'auto.ai.langgraph.error', which doesn't align with theSEMANTIC_ATTRIBUTE_SENTRY_ORIGINvalue of'auto.ai.langgraph'. Other AI integrations (Anthropic uses'auto.ai.anthropic', Google GenAI uses'auto.ai.google_genai') set the mechanismtypeto match the origin exactly. The.errorsuffix deviates from that convention. This also applies to the pre-existing instances at lines 77 and 177, but since this is new code, it's a good opportunity to align with the convention.Triggered by project rule: PR Review Guidelines for Cursor Bot