Skip to main content

Trace

The Trace class represents a high-level operation in your AI application, such as a user request or workflow execution. Traces group related spans together and are buffered in the Monitor until flushed. Create a Trace via monitor.log_trace().

Properties

Status Values

Trace status (TraceStatus) must be one of: "success", "failure", "aborted", "cancelled", "pending", "unknown".

Methods

update

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

Parameters

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

log_span

Creates a child Span under this trace and adds it to the monitor buffer. This is a synchronous method.

Parameters

name
str
required
Display name for the 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 Span instance.

end

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

Example