🐛 Bug Report: opentelemetry-instrument silently skips langchain, llamaindex, writer and watsonx (wrong instruments extra)
Which component is this bug for?
LangChain, LlamaIndex, Writer and watsonx instrumentations
📜 Description
opentelemetry-instrument decides whether to load an instrumentor from the instruments extra in the package metadata (get_dist_dependency_conflicts), not from instrumentation_dependencies(). In four packages that extra names a different package than the one the code actually instruments, so zero-code setup skips the instrumentor without any error.
| Package | instruments extra (pyproject.toml) |
What the code instruments |
|---|---|---|
| langchain | langchain (pyproject.toml:24) |
langchain-core > 0.1.0 (__init__.py:37) |
| llamaindex | llama-index (pyproject.toml:25) |
llama-index-core works (__init__.py:45) |
| writer | writer (pyproject.toml:23) |
writer-sdk (__init__.py:40) |
| watsonx | ibm-watson-machine-learning (pyproject.toml:22) |
same, but that package is replaced by ibm-watsonx-ai |
Related problems in the same packages:
- writer:
_instruments = ("writer-sdk >= 2.2.1, < 3",). writer-sdk 3.x is out, soinstrument()does nothing on it, through the SDK too. - watsonx: only targets the old
ibm-watson-machine-learning, so it does nothing for users ofibm-watsonx-ai, through the SDK too. - llamaindex:
custom_llm_instrumentor.py:34importsllama_index.llmsat module top, so the package fails to import when nollama-index-llms-*integration is installed.Traceloop.init()hides this in a try/except.
👟 Reproduction steps
- In a clean venv:
pip install opentelemetry-distro opentelemetry-instrumentation-langchain langchain-core langchain-openai(do not installlangchain) - Run a simple prompt | ChatOpenAI chain under
opentelemetry-instrument --traces_exporter console python app.py
👍 Expected behavior
LangChain spans (RunnableSequence.workflow, ChatOpenAI.chat, ...) are emitted, as they are when calling LangchainInstrumentor().instrument() directly.
👎 Actual Behavior with Screenshots
No LangChain spans. After pip install langchain they appear. The same happens for llamaindex with only llama-index-core, and for writer with writer-sdk.
🤖 Python Version
3.12
📃 Provide any additional context for the Bug.
Langgraph-only setups usually have langchain-core but not langchain, so this affects many zero-code users. Suggested fix: make each instruments extra match the real dependency (and instrumentation_dependencies()), lift the writer < 3 cap after checking 3.x, add ibm-watsonx-ai support, and make the llamaindex llama_index.llms import lazy.
I'd like to work on this issue.
I traced the issue to the instruments optional dependencies in the four instrumentation packages not matching the actual packages supported by their instrumentors.
I'd like to submit a focused PR correcting the metadata and adding regression coverage for zero-code instrumentation discovery, particularly for LangChain and LlamaIndex.
I'll keep the unrelated compatibility issues separate. Please let me know if this scope matches what the maintainers would expect.
Hi, I'd like to take the writer piece of this: lifting the < 3 cap on writer-sdk (and widening the test dependency so CI covers 3.x), with a regression test.
I reproduced it on Windows with Python 3.11.9 and writer-sdk 3.0.0: WriterInstrumentor logs that the installed version falls outside >= 2.2.1, < 3, so nothing is instrumented and the existing writer tests fail with IndexError.
I'm leaving the instruments extras to @ima-d-ice and not touching langchain, llamaindex or watsonx. I'll disclose AI assistance in the PR. Could a maintainer confirm this scope?
$ pip show writer-sdk | findstr Version
Version: 3.0.0
$ python -m pytest tests -x -q
F
FAILED tests/test_chat.py::test_writer_chat_legacy - IndexError: tuple index out of range
E IndexError: tuple index out of range
tests\test_chat.py:41: IndexError (writer_span = spans[0], no spans were recorded)
ERROR opentelemetry.instrumentation.instrumentor:instrumentor.py:107
WriterInstrumentor only instruments "writer-sdk >= 2.2.1, < 3", but currently
installed version ("writer-sdk 3.0.0") falls outside of that range, so nothing
can be instrumented.
1 failed, 1 warning in 2.60s