Creating and managing spans manually for fine-grained control
observe
patternLaminar.start_as_current_span
method is a recommended way to create spans manually in Python.
It creates a new span and sets it as the current span using a context manager. Context manager properly starts and ends the span.name
(str
): name of the spaninput
(Any
): input to the span. It will be serialized to JSON and recorded as span inputspan_type
(Literal['DEFAULT'] | Literal['LLM']
): type of the span. If not specified, it will be 'DEFAULT'
span_type="LLM"
and properly set the span attributes related to LLM calls.
messages
format to get see LLM calls-specific rendering in the UI.Laminar.startSpan
to create a span manually.
It doesn’t set the span as the current span.
You need to manually set the span as the current span using Laminar.withSpan
context manager.
You also need to manually end the span using span.end()
method.Laminar.withSpan
to set the manually created span as the current span.