How saran1to5ai/openllmetry works
Purpose and entry points
OpenLLMetry is a Python monorepo of OpenTelemetry extensions for LLM applications: provider, framework, vector-database, and MCP instrumentation plus the Traceloop SDK. Primary consumer entry point is Traceloop.init() from packages/traceloop-sdk/traceloop/sdk/__init__.py; individual instrumentations expose provider-specific OpenTelemetry instrumentors through their package __init__.py files, e.g. packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/__init__.py.
SDK orchestration
The SDK configures tracing, metrics, logging, SDK-managed instrumentations, and context behavior around an application.
• Initialization and public API: packages/traceloop-sdk/traceloop/sdk/__init__.py
• Instrumentation selection/activation: packages/traceloop-sdk/traceloop/sdk/instruments.py
• OpenTelemetry tracing setup and manual spans: packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py, packages/traceloop-sdk/traceloop/sdk/tracing/manual.py
• Metrics setup: packages/traceloop-sdk/traceloop/sdk/metrics/metrics.py
Control flow is application → SDK initialization → OpenTelemetry providers/processors/exporters plus enabled instrumentations → configured observability destination.
Provider instrumentation layer
Provider packages wrap SDK calls, translate request/response and token/model metadata into OpenTelemetry spans/events/metrics, and support synchronous, asynchronous, and often streaming calls. OpenAI is a representative complex implementation:
• Registration and version-specific patching: packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/__init__.py, packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/__init__.py
• Shared chat/completion/embedding wrappers: packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py, packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py
• Responses, assistants, and realtime boundaries: packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/v1/responses_wrappers.py
Parallel packages cover Anthropic, Bedrock, Cohere, Gemini, Groq, Mistral, Ollama, Replicate, SageMaker, Together, Vertex AI, Watsonx, Writer, and others.
Framework, agent, and protocol instrumentation
Framework packages capture higher-level execution topology—chains, agents, tools, retrieval, handoffs, and workflows—rather than only underlying model calls.
• LangChain callbacks, patching, LangGraph support: packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py, packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/patch.py
• LlamaIndex dispatcher and specialized instrumentors: packages/opentelemetry-instrumentation-llamaindex/opentelemetry/instrumentation/llamaindex/dispatcher_wrapper.py, packages/opentelemetry-instrumentation-llamaindex/opentelemetry/instrumentation/llamaindex/base_agent_instrumentor.py
• OpenAI Agents hooks/realtime wrappers: packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
• MCP/FastMCP instrumentation: packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py
Retrieval and vector-store boundary
Vector DB packages wrap client operations to emit retrieval/indexing spans while preserving the application’s native client behavior. Implementations are adapter-specific rather than centralized:
• Chroma: packages/opentelemetry-instrumentation-chromadb/opentelemetry/instrumentation/chromadb/wrapper.py
• Qdrant: packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/wrapper.py
• Pinecone query handling: packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/query_handlers.py
• Weaviate: packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate/wrapper.py
Semantic, product, and remote-service APIs
A semantic-conventions package supplies shared AI telemetry semantics: packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/__init__.py. The SDK additionally has HTTP-backed product features:
• Prompt registry client/models: packages/traceloop-sdk/traceloop/sdk/prompts/client.py
• Dataset CRUD and attachments: packages/traceloop-sdk/traceloop/sdk/datasets/datasets.py, packages/traceloop-sdk/traceloop/sdk/datasets/attachment.py
• Experiments/evaluators and streamed evaluation: packages/traceloop-sdk/traceloop/sdk/experiment/experiment.py, packages/traceloop-sdk/traceloop/sdk/evaluator/stream_client.py
• Guardrails and failure policy: packages/traceloop-sdk/traceloop/sdk/guardrail/guardrail.py, packages/traceloop-sdk/traceloop/sdk/guardrail/on_failure.py
Runtime and delivery
Runtime code is Python, packaged independently with pyproject.toml/Poetry metadata per package. The repository is coordinated as an Nx workspace (nx.json, package.json), with CI and release workflows at .github/workflows/ci.yml and .github/workflows/release.yml. External integrations include OpenTelemetry-compatible exporters/collectors and observability backends, LLM providers, agent frameworks, and vector databases; the repository itself is a library collection, not a deployed web service.
Main entry points: instruments.py Instrumentation activation · __init__.py Traceloop.init() · chat_wrappers.py OpenAI call wrappers · callback_handler.py Framework and agent adapters
Components 19
Traceloop SDK
Application-facing orchestration and product APIs.
- Traceloop.init() · Configures application observability.
packages/traceloop-sdk/traceloop/sdk/__init__.py - Instrumentation activation
packages/traceloop-sdk/traceloop/sdk/instruments.py - Tracing and manual spans
packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py - Metrics setup
packages/traceloop-sdk/traceloop/sdk/metrics/metrics.py - Prompts, datasets, experiments · HTTP-backed registry, dataset, evaluation, and guardrail features.
packages/traceloop-sdk/traceloop/sdk/prompts/client.py - OpenTelemetry pipeline
Instrumentation packages
OpenTelemetry adapters for model, framework, protocol, and retrieval calls.
- AI semantic conventions
packages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/__init__.py - OpenAI instrumentor · Registers version-specific OpenAI patching.
packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/__init__.py - OpenAI call wrappers · Captures sync, async, streaming, and specialized OpenAI calls.
packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py - Other LLM providers · Adapters for Anthropic, Bedrock, Gemini, and other providers.
- Framework and agent adapters · Captures chains, agents, tools, retrieval, handoffs, and workflows.
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py - MCP and FastMCP adapter
packages/opentelemetry-instrumentation-mcp/opentelemetry/instrumentation/mcp/instrumentation.py - Vector-store adapters · Wraps native vector client operations without changing behavior.
packages/opentelemetry-instrumentation-chromadb/opentelemetry/instrumentation/chromadb/wrapper.py
External runtimes
Services and libraries observed by this repository.
- Instrumented application
- LLM provider services
- Agent and framework runtimes
- Vector databases
- Traceloop product service
- OTel collector or backend
Connections 22
- Instrumented application → Traceloop.init(): initializes
- Traceloop.init() → Instrumentation activation: selects
- Traceloop.init() → Tracing and manual spans: configures
- Traceloop.init() → Metrics setup: configures
- Traceloop.init() → Prompts, datasets, experiments: exposes
- Instrumentation activation → OpenAI instrumentor: enables
- Instrumentation activation → Other LLM providers: enables
- Instrumentation activation → Framework and agent adapters: enables
- Instrumentation activation → MCP and FastMCP adapter: enables
- Instrumentation activation → Vector-store adapters: enables
- OpenAI instrumentor → OpenAI call wrappers: patches with
- OpenAI call wrappers → LLM provider services: wraps calls to
- Other LLM providers → LLM provider services: wraps calls to
- Framework and agent adapters → Agent and framework runtimes: observes
- MCP and FastMCP adapter → Agent and framework runtimes: observes
- Vector-store adapters → Vector databases: wraps operations to
- AI semantic conventions → OpenAI call wrappers: defines attributes for
- AI semantic conventions → Framework and agent adapters: defines attributes for
- Tracing and manual spans → OpenTelemetry pipeline: creates telemetry through
- Metrics setup → OpenTelemetry pipeline: emits through
- OpenTelemetry pipeline → OTel collector or backend: exports to
- Prompts, datasets, experiments → Traceloop product service: uses HTTP API