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
Name of the span. Use descriptive names like
"vector-search" or "database.query.customers".Type of operation. Choose the most specific type:
| Value | Use Case |
|---|---|
SpanType.LLM | Language model calls |
SpanType.CHAIN | Orchestration / workflow logic |
SpanType.TOOL | External tool or API calls |
SpanType.FUNCTION | Internal functions or business logic |
Input data to record with the span.
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

