OpenTelemetry MCP Instrumentation (OpenLLMetry)
The `opentelemetry-instrumentation-mcp` package provides automatic OpenTelemetry instrumentation for a wide array of Large Language Models (LLMs), vector databases, and other AI frameworks. As part of the Traceloop `openllmetry` project, it acts as a meta-package, consolidating over 30 individual instrumentations for popular libraries like OpenAI, LangChain, Anthropic, and Pinecone into a single installation. It is currently at version 0.58.0 and follows a rapid release cadence with frequent updates.
Warnings
- breaking Frequent updates to OpenTelemetry GenAI Semantic Conventions may lead to changes in span and attribute names. This is common in a rapidly evolving ecosystem.
- gotcha This package (`opentelemetry-instrumentation-mcp`) is a meta-package, meaning installing it brings in a large number of individual `opentelemetry-instrumentation-*` packages. This can lead to a large dependency tree and potential version conflicts with other libraries in your project.
- breaking Instrumentation for Pinecone switched from the deprecated `pinecone-client` to the `pinecone` package.
Install
-
pip install opentelemetry-instrumentation-mcp openllmetry-sdk -
pip install openai
Imports
- init
from openllmetry.sdk import init
Quickstart
import os
from openllmetry.sdk import init
from openai import OpenAI
# Initialize OpenLLMetry to enable instrumentation
init()
# Ensure OPENAI_API_KEY is set in your environment
openai_api_key = os.environ.get('OPENAI_API_KEY', '')
if not openai_api_key:
print("Warning: OPENAI_API_KEY not set. Skipping OpenAI call.")
else:
print("OpenAI API Key found. Making a sample call...")
client = OpenAI(api_key=openai_api_key)
try:
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "What is OpenTelemetry?"}
]
)
print(f"OpenAI response: {completion.choices[0].message.content[:50]}...")
print("Traces for this call should be visible in your configured OpenTelemetry collector.")
except Exception as e:
print(f"Error during OpenAI call: {e}")