DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
519 stars 407 forks source link

Langchain patch assumes that you have langchain_community installed #9368

Closed MartinGotelli closed 2 months ago

MartinGotelli commented 3 months ago

Summary of problem

ddtrace is assuming that if you have langchain, you also have langchain_community

Which version of dd-trace-py are you using?

2.71 but happens also in 2.8.5

Which version of pip are you using?

24.0

Which libraries and their versions are you using?

`pip freeze` aiohttp==3.9.3 aiosignal==1.3.1 annotated-types==0.6.0 anyio==4.3.0 asgiref==3.8.0 astroid==3.1.0 attrs==23.2.0 bert-score==0.3.13 black==24.1.1 boto3==1.34.86 botocore==1.34.86 build==1.1.1 bytecode==0.15.1 CacheControl==0.14.0 cattrs==23.2.3 certifi==2024.2.2 cffi==1.16.0 charset-normalizer==3.3.2 cleo==2.1.0 click==8.1.7 contourpy==1.2.1 coverage==7.4.4 crashtest==0.4.1 cycler==0.12.1 dataclasses-json==0.6.4 ddsketch==3.0.1 ddtrace==2.7.1 Deprecated==1.2.14 dill==0.3.8 distlib==0.3.8 distro==1.9.0 Django==5.0.3 django-mock-queries==2.2.0 djangorestframework==3.15.0 dulwich==0.21.7 envier==0.5.1 fastapi==0.110.1 fastjsonschema==2.19.1 filelock==3.13.4 fonttools==4.51.0 freezegun==1.4.0 frozenlist==1.4.1 fsspec==2024.3.1 h11==0.14.0 httpcore==1.0.4 httpx==0.27.0 huggingface-hub==0.22.2 idna==3.7 importlib-metadata==6.11.0 iniconfig==2.0.0 installer==0.7.0 isort==5.13.2 jaraco.classes==3.3.1 Jinja2==3.1.4 jmespath==1.0.1 joblib==1.4.0 jsonpatch==1.33 jsonpointer==2.4 keyring==24.3.1 kiwisolver==1.4.5 langchain==0.2.0 langchain-core==0.2.1 langchain-openai==0.1.7 langchain-postgres==0.0.6 langchain-text-splitters==0.2.0 langsmith==0.1.31 MarkupSafe==2.1.5 marshmallow==3.21.1 matplotlib==3.8.4 mccabe==0.7.0 mirakuru==2.5.2 model-bakery==1.17.0 more-itertools==10.2.0 mpmath==1.3.0 msgpack==1.0.8 multidict==6.0.5 mypy-extensions==1.0.0 networkx==3.3 nltk==3.8.1 numpy==1.26.4 openai==1.30.2 opentelemetry-api==1.23.0 orjson==3.9.15 packaging==23.2 pandas==2.2.2 pathspec==0.12.1 pexpect==4.9.0 pgvector==0.2.5 pillow==10.3.0 pkginfo==1.10.0 platformdirs==4.2.0 pluggy==1.4.0 poetry==1.8.2 poetry-core==1.9.0 poetry-plugin-export==1.7.1 port-for==0.7.2 protobuf==4.25.3 psutil==5.9.8 psycopg==3.1.18 psycopg-binary==3.1.18 psycopg-pool==3.2.2 psycopg2==2.9.9 psycopg2-binary==2.9.9 ptyprocess==0.7.0 pycodestyle==2.11.1 pycparser==2.21 pydantic==2.6.4 pydantic-settings==2.2.1 pydantic_core==2.16.3 pylint==3.1.0 pylint-django==2.5.5 pylint-plugin-utils==0.8.2 pyparsing==3.1.2 pyproject_hooks==1.0.0 pytest==8.1.1 pytest-asyncio==0.23.6 pytest-django==4.8.0 pytest-env==1.1.3 pytest-mock==3.12.0 pytest-postgresql==6.0.0 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 python-json-logger==2.0.7 pytz==2024.1 PyYAML==6.0.1 rapidfuzz==3.6.2 regex==2023.12.25 requests==2.31.0 requests-toolbelt==1.0.0 rouge_score==0.1.2 s3transfer==0.10.1 safetensors==0.4.3 scikit-learn==1.4.2 scipy==1.13.0 sentence-transformers==2.7.0 shellingham==1.5.4 six==1.16.0 slack_sdk==3.27.1 sniffio==1.3.1 SQLAlchemy==2.0.28 sqlparse==0.5.0 starlette==0.37.2 sympy==1.12 tenacity==8.2.3 threadpoolctl==3.4.0 tiktoken==0.7.0 tokenizers==0.19.1 tomlkit==0.12.4 torch==2.2.2 tqdm==4.66.4 transformers==4.40.1 trove-classifiers==2024.3.3 typing-inspect==0.9.0 typing_extensions==4.10.0 tzdata==2024.1 urllib3==2.2.1 uvicorn==0.29.0 virtualenv==20.25.1 vulture==2.11 wrapt==1.16.0 xattr==1.1.0 xmltodict==0.13.0 yarl==1.9.4 zipp==3.18.1

How can we reproduce your problem?

from ddtrace import patch_all

def test_ddtrace(capfd):
    patch_all()

    _, err = capfd.readouterr()
    assert err == ""

What is the result that you get?

ModuleNotFoundError for langchain_community

What is the result that you expected?

Don't patch langchain_community

emmettbutler commented 3 months ago

Thanks for the report @MartinGotelli. We'll look into it.

cc @Yun-Kim

Yun-Kim commented 3 months ago

Hi @MartinGotelli, thanks for reaching out!

After langchain>=0.1 was released most functionality regarding third party integrations was deprecated on langchain with guidance to switch over to import and use langchain_community instead.

We can add special casing to not patch langchain_community if it doesn't exist, but just a note this will disable tracing any embeddings/vectorstore objects from LangChain. In the meantime, I would recommend installing langchain-community to be compatible with ddtrace for now.

MartinGotelli commented 3 months ago

Hey @Yun-Kim that's what we did. Don't know if you manage priority, but maybe you can lower this one. The workaround is simple enough.

Thank you both!

Edit: Forgot to mention, we are using langchain 0.2.0, and we only use langchain_postgres as third party. So no need of langchain_community