View module source on GitHub

TraceConfig

@deprecated(
    "This class will be removed in a future version. Use {} which is TypedDict."
)

@dataclass
class TraceConfig()

Trace config.

This class represents a trace config.

TraceConfigDict

class TraceConfigDict(TypedDict)

Trace config dict.

This class represents a trace config dictionary.

get_trace_config_dict

def get_trace_config_dict(
        config: Union[TraceConfig, TraceConfigDict]) -> TraceConfigDict

Convert a TraceConfig object to a TraceConfigDict.

Arguments:

NameDescription
configEither a TraceConfig object or a TraceConfigDict dictionary.

Returns:

A TraceConfigDict dictionary representation of the config.

Trace

class Trace(EventEmittingBaseContainer)

A class representing a trace in the logging system.

A trace is a high-level container for tracking a complete operation or workflow.

__init__

def __init__(config: Union[TraceConfig, TraceConfigDict], writer: LogWriter)

Initialize a new Trace instance.

Arguments:

NameDescription
configConfiguration for the trace, either as a TraceConfig object or a TraceConfigDict.
writerThe LogWriter instance to use for writing log entries.

set_input

def set_input(input: str)

Set the input for this trace.

Arguments:

NameDescription
inputThe input string to set.

set_input_

@staticmethod
def set_input_(writer: LogWriter, trace_id: str, input: str)

Static method to set the input for a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to update.
inputThe input string to set.

set_output

def set_output(output: str)

Set the output for this trace.

Arguments:

NameDescription
outputThe output string to set.

set_output_

@staticmethod
def set_output_(writer: LogWriter, trace_id: str, output: str)

Static method to set the output for a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to update.
outputThe output string to set.

generation

def generation(
        config: Union[GenerationConfig, GenerationConfigDict]) -> Generation

Add a generation to this trace.

Arguments:

NameDescription
configConfiguration for the generation.

Returns:

A new Generation instance.

tool_call

def tool_call(config: Union[ToolCallConfig, ToolCallConfigDict]) -> ToolCall

Add a tool call to this trace.

Arguments:

NameDescription
configConfiguration for the tool call.

Returns:

A new ToolCall instance.

tool_call_

@staticmethod
def tool_call_(writer: LogWriter, trace_id: str,
               config: Union[ToolCallConfig, ToolCallConfigDict]) -> ToolCall

Static method to add a tool call to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the tool call to.
configConfiguration for the tool call.

Returns:

A new ToolCall instance.

generation_

@staticmethod
def generation_(
        writer: LogWriter, trace_id: str,
        config: Union[GenerationConfig, GenerationConfigDict]) -> Generation

Static method to add a generation to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the generation to.
configConfiguration for the generation.

Returns:

A new Generation instance.

add_error

def add_error(config: ErrorConfig) -> Error

Add an error to this trace.

Arguments:

NameDescription
configConfiguration for the error.

Returns:

A new Error instance.

error_

@staticmethod
def error_(writer: LogWriter, trace_id: str, config: ErrorConfig) -> Error

Static method to add an error to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the error to.
configConfiguration for the error.

Returns:

A new Error instance.

retrieval

def retrieval(config: Union[RetrievalConfig, RetrievalConfigDict])

Add a retrieval to this trace.

Arguments:

NameDescription
configConfiguration for the retrieval.

Returns:

A new Retrieval instance.

retrieval_

@staticmethod
def retrieval_(writer: LogWriter, trace_id: str,
               config: Union[RetrievalConfig, RetrievalConfigDict])

Static method to add a retrieval to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the retrieval to.
configConfiguration for the retrieval.

Returns:

A new Retrieval instance.

span

def span(config: Union["SpanConfig", "SpanConfigDict"]) -> "Span"

Add a span to this trace.

Arguments:

NameDescription
configConfiguration for the span.

Returns:

A new Span instance.

span_

@staticmethod
def span_(writer: LogWriter, trace_id: str,
          config: Union["SpanConfig", "SpanConfigDict"]) -> "Span"

Static method to add a span to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the span to.
configConfiguration for the span.

Returns:

A new Span instance.

feedback

def feedback(feedback: Union[Feedback, FeedbackDict])

Add feedback to this trace.

Arguments:

NameDescription
feedbackThe feedback to add.

feedback_

@staticmethod
def feedback_(writer: LogWriter, trace_id: str, feedback: Union[Feedback,
                                                                FeedbackDict])

Static method to add feedback to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the feedback to.
feedbackThe feedback to add.

add_tag_

@staticmethod
def add_tag_(writer: LogWriter, id: str, key: str, value: str)

Static method to add a tag to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to add the tag to.
keyThe tag key.
valueThe tag value.

add_attachment

def add_attachment(attachment: Union[FileAttachment, FileDataAttachment,
                                     UrlAttachment])

Add an attachment to this trace.

Arguments:

NameDescription
attachmentThe attachment to add.

add_attachment_

@staticmethod
def add_attachment_(writer: LogWriter, trace_id: str,
                    attachment: Union[FileAttachment, FileDataAttachment,
                                      UrlAttachment])

Static method to add an attachment to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the attachment to.
attachmentThe attachment to add.

end_

@staticmethod
def end_(writer: LogWriter,
         trace_id: str,
         data: Optional[Dict[str, str]] = None)

Static method to end a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to end.
dataAdditional data to include in the end event.

Returns:

The result of the end operation.

event_

@staticmethod
def event_(writer: LogWriter,
           trace_id: str,
           id: str,
           event: str,
           tags: Optional[Dict[str, str]] = None,
           metadata: Optional[Dict[str, Any]] = None)

Static method to add a custom event to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
trace_idThe ID of the trace to add the event to.
idThe ID of the event.
eventThe name of the event.
tagsOptional tags to associate with the event.
metadataOptional metadata to include with the event.

Returns:

The result of the event operation.

data

def data() -> Dict[str, Any]

Get the data representation of this trace.

Returns:

A dictionary containing the trace data.