with and async with. Function decorators support synchronous and asynchronous functions; span without an active trace simply executes the original function. start_trace raises if no global client is available. For capture, use with client.capture_traces(...) as capture.
On this page
SpanContext, TraceCapture, TraceContext, get_current_session_id, get_current_trace, get_current_user_id, get_span_stack, reset_current_session_id, reset_current_user_id, session, set_current_session_id, set_current_user_id, set_session, set_user, span, start_trace, trace, user.Example
SpanContext
Constructor
Fields and properties
Methods
set_input
set_input
Sets the recorded input. Trace and LLM inputs use the messages schema; other span kinds may use domain values.
set_output
set_output
Sets the recorded output. Trace and LLM outputs use the messages schema; other span kinds may use domain values.
set_token_usage
set_token_usage
Records supplied token counts and additional numeric usage. This setter does not measure token use itself.
set_model
set_model
Records the model identifier for this span.
set_model_parameters
set_model_parameters
Records the supplied model invocation parameters.
set_cost
set_cost
Records supplied total cost and any additional named cost components. It does not look up provider prices.
set_completion_start_time
set_completion_start_time
Records the time completion output began, such as the first streamed token.
set_error
set_error
Records an error message and sets the span status to ERROR.
set_metadata
set_metadata
Merges metadata into the current record; existing keys with the same name are replaced.
TraceCapture
Constructor
Fields and properties
TraceContext
Constructor
Fields and properties
Methods
span
span
set_output
set_output
Sets the recorded output. Trace and LLM outputs use the messages schema; other span kinds may use domain values.
set_input
set_input
Sets the recorded input. Trace and LLM inputs use the messages schema; other span kinds may use domain values.
set_metadata
set_metadata
Merges metadata into the current record; existing keys with the same name are replaced.
set_status
set_status
Sets the trace status using a supported TraceStatus value.
add_span_data
add_span_data
get_current_session_id
None.
Source declaration
get_current_trace
get_current_user_id
None.
Source declaration
get_span_stack
reset_current_session_id
reset_current_user_id
session
set_current_session_id
set_current_user_id
set_session
set_user
span
SpanContext.
Source declaration
start_trace
TraceContext context manager.
Source declaration
trace
TraceContext.
Source declaration
user
Signatures and fields are generated from the SDK source. See the import index for available entry points.

