API Reference
Complete API documentation for TraceCraft.
Modules
Core →
Core models, runtime, and configuration
Decorators →
Instrumentation decorators and context managers
Exporters →
Export traces to different backends
Processors →
Data processing and transformation
Adapters →
Framework integration adapters
Configuration →
Configuration classes and options
Quick Reference
Core Classes
from tracecraft import (
TraceCraftRuntime,
TraceCraftConfig,
AgentRun,
Step,
StepType,
)
# Create runtime
runtime = TraceCraftRuntime(config=TraceCraftConfig())
# Create run
with runtime.run("my_run"):
# Your code here
passDecorators
from tracecraft import (
trace_agent,
trace_tool,
trace_llm,
trace_retrieval,
step,
)
@trace_agent(name="agent")
async def agent(input: str) -> str:
pass
@trace_tool(name="tool")
def tool(input: str) -> str:
pass
@trace_llm(name="llm", model="gpt-4", provider="openai")
async def llm(prompt: str) -> str:
pass
@trace_retrieval(name="retrieval")
async def retrieval(query: str) -> list[str]:
passExporters
from tracecraft.exporters import (
ConsoleExporter,
JSONLExporter,
OTLPExporter,
MLflowExporter,
HTMLExporter,
)
# Use with init
tracecraft.init(
exporters=[
ConsoleExporter(),
JSONLExporter(filepath="traces.jsonl"),
OTLPExporter(endpoint="http://localhost:4317"),
]
)Processors
from tracecraft.processors.redaction import RedactionProcessor, RedactionMode
from tracecraft.processors.sampling import SamplingProcessor
from tracecraft.processors.enrichment import EnrichmentProcessor
# PII redaction
redaction = RedactionProcessor(mode=RedactionMode.MASK)
# Sampling
sampling = SamplingProcessor(rate=0.1)
# Enrichment
enrichment = EnrichmentProcessor(
static_attributes={"version": "1.0.0"}
)Adapters
# LangChain
from tracecraft.adapters.langchain import TraceCraftCallbackHandler
handler = TraceCraftCallbackHandler()
# LlamaIndex
from tracecraft.adapters.llamaindex import TraceCraftSpanHandler
handler = TraceCraftSpanHandler()
# PydanticAI
from tracecraft.adapters.pydantic_ai import TraceCraftSpanProcessor
processor = TraceCraftSpanProcessor()
# Claude SDK
from tracecraft.adapters.claude_sdk import ClaudeTraceCraftr
tracer = ClaudeTraceCraftr(runtime=runtime)Auto-Generated Documentation
The following pages contain auto-generated API documentation from source code docstrings:
- Core - Core functionality
- Decorators - Instrumentation decorators
- Exporters - Export backends
- Processors - Data processors
- Adapters - Framework adapters
- Configuration - Configuration classes
Type Hints
TraceCraft is fully typed. Import types for static analysis:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from tracecraft.core.runtime import TALRuntime
from tracecraft.core.models import AgentRun, Step
from tracecraft.core.config import TraceCraftConfigNext Steps
Explore specific API modules: