trace.Span
An operation whose lifetime the code that starts it owns, instead of one function call's: for work that begins in one call and ends in another, such as a stream that is pulled step by step, or an agent run spanning many model turns. It is a span like a traced function call's, nested under the span active where it starts (or `parent`).
Signature
class trace.SpanAn operation whose lifetime the code that starts it owns, instead of one
function call's: for work that begins in one call and ends in another, such
as a stream that is pulled step by step, or an agent run spanning many
model turns. It is a span like a traced function call's, nested under the
span active where it starts (or parent).
Start it with trace.start_span, run each piece of its work inside it with
run, and end it once with finish, fail, fail_with_context or
close. Inputs are captured at creation. The first ending wins; close
makes no claim about the outcome.
Source:<builtin>/trace/trace.bamlbytes 6092–7615
Fields
_handle
$rust_typeInstance methods
(internal) Make this operation the active span for the rest of the
calling frame, which run scopes to its body.
close
(self) -> null throws neverEnd without asserting success, failure, or cancellation.
fail
<E>(self, error: E) -> null throws neverRecord an error value and end the operation. Does not throw that value.
fail_with_context
<E>(self, error: E, context: baml.errors.Context) -> null throws neverRecord an error with its existing baml.errors.Context and end the operation.
finish
<T>(self, value: T) -> null throws neverRecord a successful output and end the operation.
is_closed
(self) -> bool throws neverExecute with this operation as the parent, using its context without completing it.