Python Integrations
MutagenT provides first-class Python support for tracing AI applications. The Python ecosystem consists of a core tracing SDK and framework-specific adapters that automatically instrument your LLM calls.Architecture
Requirements
- Python >= 3.10
- A MutagenT API key (get one here)
Package Status
| Package | Version | Status | Description |
|---|---|---|---|
mutagent-tracing | 0.1.0 | Alpha (source only) | Core SDK — spans, context propagation, batch transport |
mutagent-openai | 0.1.0 | Alpha (source only) | Automatic tracing for the OpenAI Python SDK |
mutagent-langchain | 0.1.0 | Alpha (source only) | Callback handler for LangChain |
mutagent-langgraph | 0.1.0 | Alpha (source only) | Graph tracer for LangGraph workflows |
Quick Setup
Install the core SDK
Environment Variables
You can configure tracing via environment variables instead of passing arguments directly:| Variable | Description | Default |
|---|---|---|
MUTAGENT_API_KEY | Your MutagenT API key | Required |
MUTAGENT_API_URL | MutagenT API endpoint | https://api.mutagent.io |
Configuration Options
Theinit_tracing function accepts the following parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | Required | MutagenT API key |
endpoint | str | https://api.mutagent.io | API endpoint URL |
environment | str | None | None | Environment name (e.g., production, staging) |
batch_size | int | 10 | Number of spans to buffer before flushing |
flush_interval_ms | int | 5000 | Flush interval in milliseconds |
debug | bool | False | Enable debug logging |
source | str | "sdk" | Source identifier for traces (internal use) |
Core SDK: Manual Spans
Themutagent-tracing package also exposes a low-level API for creating custom spans when you need fine-grained control:
Available Span Kinds
| Kind | Value | Use Case |
|---|---|---|
LLM_CHAT | llm.chat | Chat completions |
LLM_COMPLETION | llm.completion | Text completions |
LLM_EMBEDDING | llm.embedding | Embedding generation |
CHAIN | chain | Sequential pipelines |
AGENT | agent | Agent execution |
GRAPH | graph | Graph workflows |
NODE | node | Graph nodes |
EDGE | edge | Graph edges |
WORKFLOW | workflow | Multi-step workflows |
MIDDLEWARE | middleware | Middleware layers |
TOOL | tool | Tool invocations |
RETRIEVAL | retrieval | RAG retrieval |
RERANK | rerank | Reranking operations |
GUARDRAIL | guardrail | Safety checks |
CUSTOM | custom | Custom operations |
Shutdown
Always callshutdown_tracing() before your application exits to flush remaining spans:
The SDK registers an
atexit handler that flushes remaining spans automatically. Calling shutdown_tracing() explicitly is recommended for long-running applications or serverless functions.Framework Guides
OpenAI
Automatic tracing for the OpenAI Python SDK
LangChain
Callback handler for LangChain chains and agents
LangGraph
Graph tracer for LangGraph workflows
TypeScript Equivalents
If you are using TypeScript/Node.js, see the TypeScript integration guides for the equivalent packages:| Python Package | TypeScript Equivalent |
|---|---|
mutagent-tracing | @mutagent/sdk |
mutagent-openai | @mutagent/openai |
mutagent-langchain | @mutagent/langchain |
mutagent-langgraph | @mutagent/langgraph |