Documentation Index
Fetch the complete documentation index at: https://docs.mutagent.io/llms.txt
Use this file to discover all available pages before exploring further.
Python Tracing
Themutagent.tracing module provides OTel-aligned span instrumentation with no external collector required. It ships as part of mutagent-sdk.
Install
Initialize
Callinit_tracing once at application startup:
MUTAGENT_API_KEY environment variable and skip the argument:
Decorate Functions
The@trace decorator is the simplest way to add tracing. It captures the function’s input arguments, return value, duration, and any exceptions:
@trace Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
kind | SpanKind | "custom" | Span kind — see table below |
name | str | None | function name | Override the span name |
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 |
tool | "tool" | Tool invocations |
retrieval | "retrieval" | RAG retrieval |
guardrail | "guardrail" | Safety checks |
custom | "custom" | Any other use case |
Low-Level API
For fine-grained control, usestart_span and end_span directly:
Shutdown
For scripts or short-lived applications, flush remaining buffered spans before exit:The SDK registers an
atexit handler that flushes remaining spans automatically. Calling shutdown_tracing() explicitly is recommended for serverless functions or any process that exits quickly after the last traced call.init_tracing Options
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | Required | MutagenT API key (mt_ prefix) |
endpoint | str | https://api.mutagent.io | API endpoint URL |
environment | str | None | None | Environment name (e.g., production) |
batch_size | int | 10 | Spans buffered before flush |
batch_interval_ms | int | 5000 | Flush interval in milliseconds |
debug | bool | False | Log span events to stdout |
Framework Integrations
For automatic tracing without any code changes to your LLM calls, use the Python integration packages:Anthropic
wrap_anthropic(client) — zero-change tracing for ClaudeOpenAI
MutagentOpenAI — drop-in OpenAI client replacementLangChain
MutagentCallbackHandler — traces chains, tools, and retrieversLangGraph
MutagentCallbackHandler — automatic graph node tracingTypeScript Equivalent
The TypeScript tracing module (@mutagent/sdk/tracing) provides the same concepts: initTracing, shutdownTracing, @trace() decorator, and startSpan/endSpan. See the TypeScript tracing guide.