OpenTelemetry LangChain Instrumentation (Alpha)
This package provides OpenTelemetry instrumentation for LangChain LLM/chat workflows. It leverages Splunk distribution of opentelemetry-util-genai for producing telemetry in semantic convention. Core concepts, high-level usage and configuration
Status: Alpha (APIs and produced telemetry are subject to change).
Installation
Install from source:
pip install -e splunk-otel-instrumentation-langchain
This will pull in required OpenTelemetry core + opentelemetry-util-genai.
Quick Start
Manual Instrumentation (development/debugging)
from opentelemetry.instrumentation.langchain import LangChainInstrumentor
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
# manual instrumentation, easy to debug in your IDE
LangChainInstrumentor().instrument()
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.0)
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="What is the capital of France?"),
]
response = llm.invoke(messages)
print(response.content)
Zero-code instrumentation
in zero-code instrumentation mode, ensure you install opentelemetry-distribution and run you app with the OpenTelemetry LangChain Instrumentor enabled:
.. code:: bash
opentelemetry-instrument python your_langchain_app.py
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.0)
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="What is the capital of France?"),
]
response = llm.invoke(messages)
print(response.content)
Embedding Support
The instrumentation wraps embed_documents() and embed_query() methods for embedding classes (e.g., OpenAIEmbeddings, AzureOpenAIEmbeddings).
Token Counting: For token usage metrics, the instrumentation uses tiktoken to count input tokens client-side. This is necessary because:
LangChain’s embedding methods only return embedding vectors (list[list[float]])
The API’s usage response is discarded internally by LangChain
LangChain has no embedding callbacks (unlike LLM callbacks)
tiktoken is already a required dependency of langchain-openai, so no additional installation is needed when using OpenAI embeddings. If tiktoken is unavailable (e.g., for non-OpenAI providers), token metrics are gracefully omitted.
Interrupt/Resume Support
The instrumentation automatically detects LangGraph interrupt/resume patterns:
Error classification — GraphInterrupt, NodeInterrupt, and Interrupt exceptions are classified as interrupts (span status left as UNSET instead of ERROR). CancelledError and TaskCancelledError are classified as cancellations.
Conversation ID — thread_id from LangGraph checkpoint metadata is extracted and set as gen_ai.conversation.id on root workflow/agent spans.
See the examples/multi_agent_travel_planner demo for interrupt/resume in action.
Known LangGraph Compatibility Issue
langgraph==1.1.7 introduced a breaking change that silently drops non-GraphCallbackHandler callback handlers. This prevents the instrumentation from receiving any callbacks. The issue was fixed in langgraph 1.1.8. This package excludes langgraph==1.1.7 via != 1.1.7 in its dependency specifier.
Testing
Run the package tests (from repository root or this directory):
pytest -k langchain instrumentation-genai/opentelemetry-instrumentation-langchain-alpha/tests
(Recorded cassettes or proper API keys may be required for full integration tests.)
Contributing
Issues / PRs welcome in the main otel-splunk-python-contrib repository. This module is alpha: feedback on attribute coverage, performance, and LangChain surface expansion is especially helpful.
License
Apache 2.0
Metadata
Release files for splunk-otel-instrumentation-langchain 0.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| splunk_otel_instrumentation_langchain-0.1.16.tar.gz | 52.7 kB | Without provenance | Details for splunk_otel_instrumentation_langchain-0.1.16.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| splunk_otel_instrumentation_langchain-0.1.16-py3-none-any.whl | Python 3 | none | any | Details for splunk_otel_instrumentation_langchain-0.1.16-py3-none-any.whl |
Total release size: 84.1 kB
Release files / splunk_otel_instrumentation_langchain-0.1.16.tar.gz
| Download URL | splunk_otel_instrumentation_langchain-0.1.16.tar.gz |
|---|---|
| Size | 52.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cd461097489a6c99c032937264f8f7679b50a08207e251ed6a1ebd5ffbd8842
|
|
BLAKE2b-256 checksum How to use checksums |
beb6579e881f7da7359b8e06bda8e5b108b12d3ec7bc4d2ad1a5f971af8bbe93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.11.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.11.15","system":{"name":"Linux","release":"5.15.0-1084-aws"}} HTTPX2/2.9.1
|
Release files / splunk_otel_instrumentation_langchain-0.1.16-py3-none-any.whl
| Download URL | splunk_otel_instrumentation_langchain-0.1.16-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc322b89e258b50ae8ba41907e0e2665227deee007385df4f217f2bcfe068cd3
|
|
BLAKE2b-256 checksum How to use checksums |
2dea457aef5f6bf48436d12fcc3e4238818d04599a7cadfe4484d90e8f9ecb9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"trixie","libc":{"lib":"glibc","version":"2.41"},"name":"Debian GNU/Linux","version":"13"},"implementation":{"name":"CPython","version":"3.11.15"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.5.6 7 Apr 2026","python":"3.11.15","system":{"name":"Linux","release":"5.15.0-1084-aws"}} HTTPX2/2.9.1
|
Security for splunk-otel-instrumentation-langchain 0.1.16
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.