View module source on GitHub

SpanConfig

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

@dataclass
class SpanConfig()

Span config.

This class represents a span config.

SpanConfigDict

class SpanConfigDict(TypedDict)

Span config dict.

This class represents a span config dictionary.

get_span_config_dict

def get_span_config_dict(
        config: Union[SpanConfig, SpanConfigDict]) -> dict[str, Any]

Convert a span config to a span config dict else return the config.

Arguments:

NameDescription
configThe config to convert.

Returns:

dict[str, Any]: The span config dict.

Span

class Span(EventEmittingBaseContainer)

Span.

This class represents a span.

__init__

def __init__(config: Union[SpanConfig, SpanConfigDict], writer: LogWriter)

Initialize a span.

Arguments:

NameDescription
configThe config to initialize the span with.
writerThe writer to use.

span

def span(config: Union[SpanConfig, SpanConfigDict])

Add a span to this span.

Arguments:

NameDescription
configThe config to add the span to.

input

def input(input: str)

Set the input for this span.

Arguments:

NameDescription
inputThe input to set for this span.

input_

@staticmethod
def input_(writer: LogWriter, span_id: str, input: str)

Set the input for this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to set the input for.
inputThe input to set for this span.

add_error

def add_error(config: ErrorConfig) -> Error

Add an error to this span.

Arguments:

NameDescription
configThe config to add the error to.

Returns:

NameDescription
[Error](/sdk/python/references/models/prompt)The error that was added.

error_

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

Add an error to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the error to.
configThe config to add the error to.

Returns:

NameDescription
[Error](/sdk/python/references/models/prompt)The error that was added.

span_

@staticmethod
def span_(writer: LogWriter, span_id: str, config: Union[SpanConfig,
                                                         SpanConfigDict])

Add a span to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the span to.
configThe config to add the span to.

Returns:

NameDescription
[Span](/sdk/python/references/logger/components/span)The span that was added.

generation

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

Add a generation to this span.

Arguments:

NameDescription
configThe config to add the generation to.

Returns:

NameDescription
[Generation](/sdk/python/references/logger/components/generation)The generation that was added.

tool_call

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

Add a tool call to this span.

Arguments:

NameDescription
configThe config to add the tool call to.

Returns:

NameDescription
[ToolCall](/sdk/python/references/models/prompt)The tool call that was added.

tool_call_

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

Add a tool call to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the tool call to.
configThe config to add the tool call to.

Returns:

NameDescription
[ToolCall](/sdk/python/references/models/prompt)The tool call that was added.

generation_

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

Add a generation to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the generation to.
configThe config to add the generation to.

Returns:

NameDescription
[Generation](/sdk/python/references/logger/components/generation)The generation that was added.

add_attachment

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

Add an attachment to this span.

Arguments:

NameDescription
attachmentThe attachment to add.

add_attachment_

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

Static method to add an attachment to a span.

Arguments:

NameDescription
writerThe LogWriter instance to use.
span_idThe ID of the span to add the attachment to.
attachmentThe attachment to add.

retrieval

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

Add a retrieval to this span.

Arguments:

NameDescription
configThe config to add the retrieval to.

Returns:

NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)The retrieval that was added.

retrieval_

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

Add a retrieval to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the retrieval to.
configThe config to add the retrieval to.

Returns:

NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)The retrieval that was added.

end_

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

End this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to end.
dataThe data to add to the span.

add_tag_

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

Add a tag to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the tag to.
keyThe key of the tag.
valueThe value of the tag.

event_

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

Add an event to this span.

Arguments:

NameDescription
writerThe writer to use.
span_idThe id of the span to add the event to.
idThe id of the event.
nameThe name of the event.
tagsThe tags of the event.
metadataThe metadata of the event.