TraciumClient
The main client class for interacting with the Tracium API.
Rule of thumb
Prefer tracium.trace() for most apps. It initializes the SDK and enables auto-instrumentation in one call. Use tracium.init() only when you need advanced configuration, then call client.trace().
tracium.init()
Initialize the Tracium SDK with your configuration.
import tracium
client = tracium.init( api_key=None, # Or use TRACIUM_API_KEY base_url=None, # Custom API endpoint config=None, # TraciumClientConfig for advanced settings default_agent_name="app", # Default agent name for auto-traces default_model_id=None, # Default model ID default_version=None, # Your application version (not SDK version) default_tags=None, # Default tags for all traces default_metadata=None, # Default metadata auto_instrument_langchain=True, auto_instrument_langgraph=True, auto_instrument_llm_clients=True, capture_media=False, # Capture audio/image outputs (base64))tracium.trace()
One-line setup with automatic tracing enabled. This is the recommended approach for most use cases.
import tracium
# Initialize and enable auto-instrumentation in one callclient = tracium.trace( api_key=None, # ... same kwargs as init())import tracium
# Example: opt-in to capturing audio/image mediaclient = tracium.trace(capture_media=True)TraciumClient Methods
agent_trace()
Create a trace context manager for an agent workflow.
client.agent_trace( agent_name, # Required: Name of your agent model_id=None, # Model being used metadata=None, # Custom metadata tags=None, # Tags for filtering trace_id=None, # Custom trace ID workspace_id=None, # Workspace identifier version=None, # Application version lazy_start=False, # Defer trace creation until first span) -> AgentTraceManager
# Usagewith client.agent_trace(agent_name="my-agent") as trace: # Create spans within this trace passtrace()
Enable automatic tracing for all supported libraries.
client.trace() -> TraciumClient
# Usageclient = tracium.init(api_key="...")client.trace() # Enable auto-instrumentationget_queue_stats()
Get statistics about the background sender queue.
client.get_queue_stats() -> dict
# Returns:{ "queue_size": int, # Current events in queue "max_queue_size": int, # Maximum capacity "capacity_percent": float, # Queue fullness percentage "is_healthy": bool, # Queue health status "total_enqueued": int, # Total events added "total_sent": int, # Successfully sent "total_failed": int, # Failed to send "total_dropped": int, # Dropped due to full queue "success_rate": float, # Percentage sent successfully "drop_rate": float, # Percentage dropped "blocking_enabled": bool, # If blocking mode is on}flush()
Wait for all pending async requests to be sent.
client.flush( timeout=None # Max wait time (default: 5.0)) -> None
# Call before application exitclient.flush()close()
Close the client and shutdown background sender.
client.close() -> None
# Or use as context managerwith tracium.TraciumClient(api_key="...") as client: # Use client pass # Automatically closedAgentTraceHandle
The handle returned by agent_trace() context manager.
Properties
trace.id -> str # Trace IDtrace.agent_name -> str # Agent nametrace.tags -> list[str] # Current tagstrace.summary -> dict # Trace summarytrace.start_payload -> dictMethods
# Create a span within this tracetrace.span( span_type, name=None, input=None, metadata=None, tags=None, parent_span_id=None, span_id=None, model_id=None, # ... additional options) -> AgentSpanContext
# Record a complete span in one calltrace.record_span( span_type, name=None, input=None, output=None, status=None, error=None, latency_ms=None, # ... additional options) -> dict
# Set trace summarytrace.set_summary(summary) -> None
# Add tagstrace.add_tags(tags) -> None
# Mark trace as failedtrace.mark_failed(error, metadata=None) -> None
# Finish trace manually (usually automatic)trace.finish( summary=None, metadata=None, tags=None,) -> dict
# Mark as failed and finishtrace.fail(error, metadata=None) -> dictAgentSpanHandle
The handle returned by trace.span() context manager.
Properties
span.id -> str # Span IDspan.trace_id -> str # Parent trace IDspan.parent_span_id -> str | Nonespan.payload -> dict # Last recorded payloadMethods
# Record input dataspan.record_input(input_data) -> None
# Record output dataspan.record_output(output_data) -> None
# Set token usagespan.set_token_usage( input_tokens=None, output_tokens=None, cached_input_tokens=None,) -> None
# Add tagsspan.add_tags(tags) -> None
# Set statusspan.set_status(status) -> None
# Mark as failedspan.mark_failed(error, metadata=None) -> NoneModule-Level Functions
import tracium
# Get the globally initialized clientclient = tracium.get_client()
# Get queue statistics from global clientstats = tracium.get_queue_stats()
# Start a trace using global defaultswith tracium.start_trace( agent_name="my-agent", model_id=None, version=None, metadata=None, tags=None, trace_id=None,): pass
# Get current active trace (if any)trace = tracium.current_trace()
# Create span within current tracewith tracium.span( span_type="tool", name=None, # ... span options): pass