The AgentBasis SDK provides powerful primitives for manually tracking your application logic and associating data with specific users.Documentation Index
Fetch the complete documentation index at: https://docs.agentbasis.co/llms.txt
Use this file to discover all available pages before exploring further.
Manual Tracing
Use the@trace decorator to automatically track any function execution as a span. This captures arguments, return values, and execution time.
Async Functions
The@trace decorator works with both sync and async functions:
User & Session Context
Context allows you to associate traces with specific users or sessions, enabling you to debug issues per-user or view session-based analytics.Global Context
Set context globally, which applies to all subsequent operations until changed:Reading Context
You can read the current context values:Scoped Context (Context Manager)
For multi-threaded or async applications, use thecontext manager to scope data to a specific block:
Scoped Context (Decorator)
Use@with_context to set context for an entire function:
Flush & Shutdown
Flushing Data
The SDK batches and sends data asynchronously. If you need to ensure all data is sent at a specific point, useflush():
flush():
- Before a critical operation
- At specific checkpoints in your application
- In serverless functions before the function terminates
Shutdown
The SDK automatically shuts down and flushes on normal Python exit. If you need to manually shut down:shutdown() is idempotent - calling it multiple times is safe.How It Works
- OpenTelemetry: We use OTel under the hood for maximum compatibility with observability tools.
- Spans: Every action (function call, LLM request) is recorded as a Span with timing, inputs, and outputs.
- Transport: Data is batched and sent asynchronously, ensuring minimal impact on your application’s latency.
- Context Propagation: User, session, and metadata are automatically attached to all spans.

