Skip to main content

Span

The Span class represents a granular operation within a trace, such as an LLM call, tool execution, embedding generation, or retrieval operation. Spans can be nested to represent sub-operations. Create a Span via trace.log_span() or span.log_span() for nested spans.

Properties

Status Values

Span status (SpanStatus) must be one of: "success", "failure", "aborted", "cancelled", "unknown".

Methods

update

Updates span fields in place. Takes a dict with the fields to update. Only the keys "name", "status", "tags", "attributes", "run_evaluation", and "content" are applied; all other keys are silently ignored. Returns self for method chaining.

Parameters

updates
dict
required
Dictionary of fields to update.
Returns: Span (self, for chaining).

log_span

Creates a child Span nested under this span and adds it to the monitor buffer. The child span’s parent_reference_id is automatically set to this span’s reference_id. This is a synchronous method.

Parameters

name
str
required
Display name for the child span.
status
str
default:"unknown"
Span status (SpanStatus). One of: "success", "failure", "aborted", "cancelled", "unknown".
reference_id
str | None
Client-side unique identifier. If omitted, a UUID is auto-generated.
prompt_id
str | None
Prompt identifier to associate with this span.
deployment_id
str | None
Deployment identifier to associate with this span.
run_evaluation
bool | None
Whether to run evaluation on this span.
tags
list[str] | None
Optional list of string tags.
attributes
dict[str, Any] | None
Optional key-value metadata. Values are wrapped in LogAttributesValue automatically.
content
LogSpanContent | None
Span content payload (LogSpanContent). Falls back to the monitor’s default_content if not provided.
Returns: A new child Span instance.

end

Marks the span as complete and ready for flushing. Automatically ends all child spans whose parent_reference_id matches this span. Idempotent: subsequent calls return the reference ID without side effects.
Returns: str | None — the span’s reference_id.

Span Content Types

Content is wrapped using LogSpanContent with one of the following 8 types:

LogSpanModelContent

Standard LLM inference calls.

LogSpanModelStreamContent

Streaming LLM inference calls.

LogSpanEmbeddingsContent

Embedding generation calls.

LogSpanFunctionContent

Custom application logic and function calls.

LogSpanToolContent

Tool/API invocations.

LogSpanGuardrailContent

Safety and compliance checks.

LogSpanRetrievalContent

RAG and vector database queries.

LogSpanOtherContent

Catch-all for any other operation type.

Example: Nested Spans