OpenTelemetry Official Langchain instrumentation
Project description
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)
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.
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splunk_otel_instrumentation_langchain-0.1.9.tar.gz.
File metadata
- Download URL: splunk_otel_instrumentation_langchain-0.1.9.tar.gz
- Upload date:
- Size: 45.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5d4a9dc9bde8f9a0227fd46ea21f933f90a519a3d057542dbdce4aeec90102b
|
|
| MD5 |
eef33b5a59e0a137f702d2d8f02442c6
|
|
| BLAKE2b-256 |
5a2cbad649fcafc8eadf009a2cb10f796bbd580c0cac34c787606e935f2faa21
|
File details
Details for the file splunk_otel_instrumentation_langchain-0.1.9-py3-none-any.whl.
File metadata
- Download URL: splunk_otel_instrumentation_langchain-0.1.9-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2482b65132330f4a6ded1adf25779ab836442cd68b8ae571723e7d6d865f705
|
|
| MD5 |
1d0781b3a9222a55487dc595c3baaafc
|
|
| BLAKE2b-256 |
573a3547b8b750b9535c1b9a4e91576f24b1f4540d72b7fb1b80a52665ab7ca8
|