-
Notifications
You must be signed in to change notification settings - Fork 38
feat(langchain): add ChatAnthropic support, including tool-calling, to langchain instrumentation #188
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
lmolkova
merged 25 commits into
open-telemetry:main
from
bhumikadangayach:feat/chat-anthropic-langchain-support
Jul 22, 2026
Merged
feat(langchain): add ChatAnthropic support, including tool-calling, to langchain instrumentation #188
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ffae686
feat(langchain): add ChatAnthropic support to langchain instrumentation
bhumikadangayach ef52763
changelog: add entry for ChatAnthropic langchain support
bhumikadangayach b6ef07d
fix: address Copilot review comments
bhumikadangayach d832e66
fix: rename changelog fragment to match PR number
bhumikadangayach acd78dc
fix: apply ruff formatting
bhumikadangayach 1731090
fix: apply ruff formatting to test_llm_call.py
bhumikadangayach b31a02f
test(langchain): add VCR tool-calling test for ChatAnthropic
bhumikadangayach 324cc72
fix: move tool import to top-level
bhumikadangayach b0ea4d1
fix(langchain): correct stop_reason key lookup for Anthropic finish r…
bhumikadangayach f02c380
fix(langchain): apply ruff formatting, align finish_reason assertion …
bhumikadangayach ce861db
style(langchain): remove blank line per ruff 0.14.1 formatting
bhumikadangayach 3083253
style: remove leftover blank lines from conflict resolution
bhumikadangayach d3bf7e2
docs: clarify changelog entry per rads-1996's review
bhumikadangayach 66e7bea
test(langchain): add coverage for stop_sequences fallback per review
bhumikadangayach 71dbde8
docs(langchain): add AI-generated header to tool_call cassette per AG…
bhumikadangayach 5603c51
fix(langchain): add langchain-anthropic to conformance env deps
bhumikadangayach 13b625a
fix(langchain): rebuild tool_call cassette to match real request body
bhumikadangayach 46c311a
fix(langchain): pin langchain-anthropic in oldest test requirements
bhumikadangayach 1e7c6cf
fix(langchain): add serialized.kwargs fallback for constructor-level …
bhumikadangayach 216acf7
fix(langchain): pin max_tokens for cross-version cassette compatibili…
bhumikadangayach 8ddf514
fix: remove leftover merge conflict markers in requirements.latest.txt
bhumikadangayach 1723280
fix: resolve conflict markers in requirements.latest.txt, sync boto3/…
bhumikadangayach 9845804
Merge branch 'main' into feat/chat-anthropic-langchain-support
lmolkova e364186
Apply suggestions from code review
lmolkova febe547
fix: remove trailing whitespace from test_llm_call.py
bhumikadangayach 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/188.added
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,2 @@ | ||
| Add ChatAnthropic tool-calling test coverage and fix finish_reason extraction for | ||
| Anthropic responses in LangChain instrumentation. | ||
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
46 changes: 46 additions & 0 deletions
46
...mentation-genai-langchain/tests/cassettes/test_chat_anthropic_claude_sonnet_llm_call.yaml
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,46 @@ | ||
| interactions: | ||
| - request: | ||
| body: |- | ||
| {"model": "claude-sonnet-4-5", "max_tokens": 1024, "temperature": 0.1, "system": "You are a helpful assistant!", "messages": [{"role": "user", "content": "What is the capital of France?"}]} | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| User-Agent: | ||
| - !!binary | | ||
| QW50aHJvcGljL1B5dGhvbiAxLjAuMA== | ||
| x-api-key: | ||
| - test_key | ||
| anthropic-version: | ||
| - '2023-06-01' | ||
| method: POST | ||
| uri: https://api.anthropic.com/v1/messages | ||
| response: | ||
| body: | ||
| string: |- | ||
| { | ||
| "id": "msg_01XFDUDYJgAACzvnptvVoYEL", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "model": "claude-sonnet-4-5", | ||
| "content": [ | ||
| { | ||
| "type": "text", | ||
| "text": "The capital of France is Paris." | ||
| } | ||
| ], | ||
| "stop_reason": "end_turn", | ||
| "stop_sequence": null, | ||
| "usage": { | ||
| "input_tokens": 13, | ||
| "output_tokens": 10 | ||
| } | ||
| } | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| Date: | ||
| - Thu, 04 Sep 2025 20:00:58 GMT | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
44 changes: 44 additions & 0 deletions
44
...ests/cassettes/test_chat_anthropic_claude_sonnet_stop_sequences_constructor_fallback.yaml
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,44 @@ | ||
| # TODO: this is generated by AI, re-record | ||
| interactions: | ||
| - request: | ||
| body: |- | ||
| {"max_tokens":1024,"messages":[{"role":"user","content":"Say hi"}],"model":"claude-sonnet-4-5","stop_sequences":["STOP"]} | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| x-api-key: | ||
| - test_key | ||
| anthropic-version: | ||
| - '2023-06-01' | ||
| method: POST | ||
| uri: https://api.anthropic.com/v1/messages | ||
| response: | ||
| body: | ||
| string: |- | ||
| { | ||
| "id": "msg_anthropic_constructor_stop_sequences_001", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "model": "claude-sonnet-4-5", | ||
| "content": [ | ||
| { | ||
| "type": "text", | ||
| "text": "Hi there!" | ||
| } | ||
| ], | ||
| "stop_reason": "stop_sequence", | ||
| "stop_sequence": "STOP", | ||
| "usage": { | ||
| "input_tokens": 10, | ||
| "output_tokens": 5 | ||
| } | ||
| } | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| Date: | ||
| - Thu, 04 Sep 2025 20:00:58 GMT | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
55 changes: 55 additions & 0 deletions
55
...-langchain/tests/cassettes/test_chat_anthropic_claude_sonnet_stop_sequences_fallback.yaml
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,55 @@ | ||
| # TODO: this is generated by AI, re-record | ||
| interactions: | ||
| - request: | ||
| body: |- | ||
| { | ||
| "model": "claude-sonnet-4-5", | ||
| "max_tokens": 1024, | ||
| "temperature": 0.1, | ||
| "stop_sequences": ["STOP"], | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": "Say hi" | ||
| } | ||
| ] | ||
| } | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| x-api-key: | ||
| - test_key | ||
| anthropic-version: | ||
| - '2023-06-01' | ||
| method: POST | ||
| uri: https://api.anthropic.com/v1/messages | ||
| response: | ||
| body: | ||
| string: |- | ||
| { | ||
| "id": "msg_anthropic_stop_sequences_001", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "model": "claude-sonnet-4-5", | ||
| "content": [ | ||
| { | ||
| "type": "text", | ||
| "text": "Hi there!" | ||
| } | ||
| ], | ||
| "stop_reason": "stop_sequence", | ||
| "stop_sequence": "STOP", | ||
| "usage": { | ||
| "input_tokens": 10, | ||
| "output_tokens": 5 | ||
| } | ||
| } | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| Date: | ||
| - Thu, 04 Sep 2025 20:00:58 GMT | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
48 changes: 48 additions & 0 deletions
48
...entation-genai-langchain/tests/cassettes/test_chat_anthropic_claude_sonnet_tool_call.yaml
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,48 @@ | ||
| # TODO: this is generated by AI, re-record | ||
| interactions: | ||
| - request: | ||
|
eternalcuriouslearner marked this conversation as resolved.
|
||
| body: |- | ||
| {"model":"claude-sonnet-4-5","max_tokens":1024,"messages":[{"role":"user","content":"What's the weather in Seattle?"}],"temperature":0.1,"tools":[{"name":"get_current_weather","input_schema":{"properties":{"location":{"type":"string"}},"required":["location"],"type":"object"},"description":"Get the current weather in a given location."}]} | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| x-api-key: | ||
| - test_key | ||
| anthropic-version: | ||
| - '2023-06-01' | ||
| method: POST | ||
| uri: https://api.anthropic.com/v1/messages | ||
| response: | ||
| body: | ||
| string: |- | ||
| { | ||
| "id": "msg_anthropic_tool_call_001", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "model": "claude-sonnet-4-5", | ||
| "content": [ | ||
| { | ||
| "type": "tool_use", | ||
| "id": "toolu_01", | ||
| "name": "get_current_weather", | ||
| "input": { | ||
| "location": "Seattle, WA" | ||
| } | ||
| } | ||
| ], | ||
| "stop_reason": "tool_use", | ||
| "stop_sequence": null, | ||
| "usage": { | ||
| "input_tokens": 20, | ||
| "output_tokens": 15 | ||
| } | ||
| } | ||
| headers: | ||
| Content-Type: | ||
| - application/json | ||
| Date: | ||
| - Thu, 04 Sep 2025 20:00:58 GMT | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 | ||
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.
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.