API Reference
Complete reference for all observability APIs in the Basalt Python SDK.Core Decorators and Context Managers
start_observe
Creates a root span to start a new trace. Every trace must have exactly one root span. As Decorator:
Identity Structure:
observe
Creates a child span within an existing trace. Requires a parent span fromstart_observe. If no parent span exists, silently creates a no-op span (no errors, just no telemetry).
As Decorator:
ObserveKind Values:
async_start_observe / async_observe
Explicit async variants ofstart_observe and observe. Also works with auto-detection using @start_observe and @observe on async functions.
Signatures: Same as sync versions
Examples:
Span Handle Methods
When using context managers, you get a span handle with these methods:Data Methods
set_input(data)
Set the input data for the span.set_output(data)
Set the output data for the span.set_attribute(key, value)
Set a single attribute on the span.set_metadata(metadata)
Set multiple attributes at once.Identity Methods
set_identity(identity)
Set user and organization identity.set_user(user_id, name=None)
Set user identity only.set_organization(org_id, name=None)
Set organization identity only.Status and Error Methods
set_status(status, message=None)
Set the span status."ok", "error", "unset"
Example:
record_exception(exception)
Record an exception with full traceback.Event Methods
add_event(name, attributes=None)
Add a timestamped event to the span.Evaluator Methods
add_evaluator(slug, metadata=None)
Add a single evaluator to this span only (non-propagating).add_evaluators(*slugs)
Add multiple evaluators at once (non-propagating).set_evaluator_config(config)
Set evaluation configuration (e.g., sample rate).set_evaluator_metadata(metadata)
Set metadata for evaluators to use.LLM-Specific Methods
For spans withkind=ObserveKind.GENERATION:
set_model(model)
Set the LLM model name.set_prompt(prompt)
Set the prompt text.set_completion(completion)
Set the LLM completion/response text.set_tokens(input=None, output=None, total=None)
Set token counts.Static Methods on observe Class
For use within decorator-traced functions (when you don’t have span handle access):observe.metadata(metadata)
Set metadata on the current active span.observe.update_metadata(metadata)
Update existing metadata on the current active span.observe.set_input(data)
Set input on the current active span.observe.set_output(data)
Set output on the current active span.observe.set_identity(identity)
Set identity on the current active span.observe.evaluate(slug)
Add evaluator to the current active span.Evaluator Decorators and Context Managers
@evaluator
Attach evaluators in propagating mode (affects all child spans).
Example:
with_evaluators
Context manager for propagating evaluators.attach_evaluator
Context manager for attaching a single propagating evaluator.Global Configuration
configure_trace_defaults
Set global defaults for all traces.
Example:
current_trace_defaults
Get current global trace defaults.experiment, metadata, and evaluators keys.
Example:
Trace Context Helpers
set_trace_user
Set user identity in current context (propagates to all spans).set_trace_organization
Set organization identity in current context (propagates to all spans).Data Classes
EvaluationConfig
Configuration for evaluator sampling and behavior.TraceExperiment
Experiment information for A/B testing.Auto-Instrumentation
Basalt Initialization
Enable auto-instrumentation when initializing Basalt.TelemetryConfig
Advanced telemetry configuration.Context Keys (Advanced)
For advanced use cases, these context keys are available:See Also
- Core Concepts - Understanding traces, spans, and context propagation
- Patterns Guide - Decorators vs context managers
- Workflows - Complete end-to-end examples
- Evaluators Guide - Quality evaluation
- Auto-Instrumentation - Supported providers