Signature
Overview
span() creates a manual span within an active trace. Use it to trace custom operations — database queries, API calls, business logic — that aren’t automatically captured by SDK instrumentation.
Must be called inside an @observe-decorated function or a trace() context manager. If no active trace exists, span() yields a no-op dummy span that does nothing.
Parameters
string
required
Name of the span. Use descriptive names like
"vector-search" or "database.query.customers".SpanType
default:"SpanType.CHAIN"
Type of operation. Choose the most specific type:
dict
default:"{}"
Input data to record with the span.
dict
default:"{}"
Additional metadata to attach to the span.
Yields
ASpan object. You can write to s.metadata inside the block to attach data discovered during execution.
Behavior
- On normal exit: span is marked
SUCCESS - On exception: span is marked
ERRORwith the exception message, then the exception re-raises - After the block: span is queued for sending
Examples
Basic custom span
Tool span
Database query
Combining with LLM calls
See Also
- @observe — Create a trace context
- trace() — Context manager trace creation
- Manual Tracing — Full guide

