`LangchainIntegration` breaks if only `langchain-core` is installed
Closed this issue · 4 comments
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.35.1, 2.37.0
Steps to Reproduce
#4678 has introduced changes that made langchain package required to be installed in order to use LangchainIntegration whereas previously only the langchain-core was required. The integration, however, uses langchain package only to wrap the AgentExecutor methods, which is anyway optional.
- create a project with
langchain-coreandsentry-sdkpackages - run
sentry_sdk.integrations.langchain - See
DidNotEnable("langchain not installed")exception
Or just run this command
uv run --with "sentry-sdk" --with "langchain-core" python -c "import sentry_sdk.integrations.langchain"Expected Result
When langchain package is not installed it just skips wrapping AgentExecutor methods in setup_once if langchain package is not present
Actual Result
Traceback (most recent call last):
File "/Users/user/.cache/uv/archive-v0/LbXO3QDNdb9rlVPdSE8LR/lib/python3.12/site-packages/sentry_sdk/integrations/langchain.py", line 32, in <module>
from langchain.agents import AgentExecutor
ModuleNotFoundError: No module named 'langchain'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/user/.cache/uv/archive-v0/LbXO3QDNdb9rlVPdSE8LR/lib/python3.12/site-packages/sentry_sdk/integrations/langchain.py", line 44, in <module>
raise DidNotEnable("langchain not installed")
sentry_sdk.integrations.DidNotEnable: langchain not installed
Hey @mshavliuk thanks for writing in!
There should definitely not be an error when langchain is not installed like you showed above. We will fix this.
@mshavliuk we have a fix: #4783
this will be released soon.
@mshavliuk the fix has been released in version 2.37.1: https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md