View module source on GitHub Configuration class for Maxim Logger. This class holds the configuration settings for the Logger, including the logger ID, auto-flush setting, and flush interval. Attributes:
NameTypeDescription
idstrThe unique identifier for the logger.
auto_flushboolWhether to automatically flush logs. Defaults to True.
flush_intervalintThe interval (in seconds) at which to flush logs when auto_flush is True. Defaults to 10 seconds.

LoggerConfig

@deprecated(
    "This class will be removed in a future version. Use LoggerConfigDict instead."
)
class LoggerConfig()
Configuration class for Maxim Logger. This class holds the configuration settings for the Logger, including the logger ID, auto-flush setting, and flush interval. Attributes:
NameTypeDescription
idstrThe unique identifier for the logger.
auto_flushboolWhether to automatically flush logs.
flush_intervalintThe interval (in seconds) at which to flush logs when auto_flush is True.

Logger

class Logger()
A class representing a logger for the Maxim SDK. This logger provides methods for creating sessions, traces, and various logging components such as spans, generations, retrievals, and tool calls. It uses a LogWriter to handle the actual logging operations. Attributes:
NameTypeDescription
_idstrThe unique identifier for this logger instance.
raise_exceptionsboolWhether to raise exceptions during logging operations.
is_debugboolWhether debug logging is enabled.
writerLogWriterThe LogWriter instance used for actual logging operations.

__init__

def __init__(config: LoggerConfigDict,
             api_key: str,
             base_url: str,
             is_debug=False,
             raise_exceptions=False) -> None
Initializes the logger with the given configuration. Arguments:
NameTypeDescription
configLoggerConfigThe configuration for the logger.
api_keystrThe API key for the logger.
base_urlstrThe base URL for the logger.
is_debugbool, optionalWhether to enable debug logging. Defaults to False.
raise_exceptionsbool, optionalWhether to raise exceptions. Defaults to False.

session

def session(config: Union[SessionConfig, SessionConfigDict]) -> Session
Creates a new session with the given configuration. Arguments:
NameTypeDescription
configSessionConfigThe configuration for the new session.
Returns:
NameDescription
[Session](/sdk/python/references/logger/components/session)The newly created session.

trace

def trace(config: Union[TraceConfig, TraceConfigDict]) -> Trace
Creates a new trace with the given configuration. Arguments:
NameTypeDescription
configTraceConfigThe configuration for the new trace.
Returns:
NameDescription
[Trace](/sdk/python/references/logger/components/trace)The newly created trace.

session_add_tag

def session_add_tag(session_id: str, key: str, value: str)
Adds a tag to the session. Arguments:
NameTypeDescription
session_idstrThe ID of the session.
keystrThe key of the tag.
valuestrThe value of the tag.

session_end

def session_end(session_id: str)
Ends the session. Arguments:
NameTypeDescription
session_idstrThe ID of the session.

session_event

def session_event(session_id: str, event_id: str, event: str, data: Any)
Adds an event to the session. Arguments:
NameTypeDescription
session_idstrThe ID of the session.
event_idstrThe ID of the event.
eventstrThe name of the event.
dataAnyThe data associated with the event.

session_feedback

@deprecated(
    "This method will be removed in a future version. Use session_add_feedback instead."
)
def session_feedback(session_id: str, feedback: Union[Feedback, FeedbackDict])
Adds a feedback to the session. Arguments:
NameTypeDescription
session_idstrThe ID of the session.
feedbackFeedbackThe feedback to add.

session_add_attachment

def session_add_attachment(session_id: str,
                           attachment: Union[FileAttachment,
                                             FileDataAttachment,
                                             UrlAttachment])
Adds an attachment to the session.

session_add_feedback

def session_add_feedback(session_id: str, feedback: FeedbackDict)
Adds a feedback to the session.

session_trace

@deprecated(
    "This method will be removed in a future version. Use session_add_trace instead."
)
def session_trace(session_id: str, config: TraceConfig) -> Trace
Adds a trace to the session. Arguments:
NameTypeDescription
session_idstrThe ID of the session.
configTraceConfigThe configuration for the trace.
Returns:
NameDescription
[Trace](/sdk/python/references/logger/components/trace)The newly created trace.

session_add_trace

def session_add_trace(session_id: str,
                      config: Union[TraceConfig, TraceConfigDict]) -> Trace
Adds a trace to the session. Arguments:
NameTypeDescription
session_idstrThe ID of the session.
configTraceConfigThe configuration for the trace.
Returns:
NameDescription
[Trace](/sdk/python/references/logger/components/trace)The newly created trace.

trace_generation

@deprecated(
    "This method will be removed in a future version. Use trace_add_generation instead."
)
def trace_generation(trace_id: str, config: GenerationConfig) -> Generation
Adds a generation to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configGenerationConfigThe configuration for the generation.
Returns:
NameDescription
[Generation](/sdk/python/references/logger/components/generation)The newly created generation.

trace_add_generation

def trace_add_generation(
        trace_id: str, config: Union[GenerationConfig,
                                     GenerationConfigDict]) -> Generation
Adds a generation to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configGenerationConfigThe configuration for the generation.
Returns:
NameDescription
[Generation](/sdk/python/references/logger/components/generation)The newly created generation.

trace_retrieval

@deprecated(
    "This method will be removed in a future version. Use trace_add_retrieval instead."
)
def trace_retrieval(
        trace_id: str, config: Union[RetrievalConfig,
                                     RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configRetrievalConfigThe configuration for the retrieval.
Returns:
NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)The newly created retrieval.

trace_add_retrieval

def trace_add_retrieval(
        trace_id: str, config: Union[RetrievalConfig,
                                     RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configRetrievalConfigThe configuration for the retrieval.
Returns:
NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)The newly created retrieval.

trace_span

@deprecated(
    "This method will be removed in a future version. Use trace_add_span instead."
)
def trace_span(trace_id: str, config: Union[SpanConfig,
                                            SpanConfigDict]) -> Span
Adds a span to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configSpanConfigThe configuration for the span.
Returns:
NameDescription
[Span](/sdk/python/references/logger/components/span)The newly created span.

trace_add_span

def trace_add_span(trace_id: str, config: Union[SpanConfig,
                                                SpanConfigDict]) -> Span
Adds a span to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configSpanConfigThe configuration for the span.
Returns:
NameDescription
[Span](/sdk/python/references/logger/components/span)The newly created span.

trace_add_error

def trace_add_error(trace_id: str, config: ErrorConfig) -> Error
Adds an error to the trace.

trace_add_tag

def trace_add_tag(trace_id: str, key: str, value: str)
Adds a tag to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
keystrThe key of the tag.
valuestrThe value of the tag.

trace_add_tool_call

def trace_add_tool_call(
        trace_id: str, config: Union[ToolCallConfig,
                                     ToolCallConfigDict]) -> ToolCall
Adds a tool call to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
configToolCallConfigThe configuration for the tool call.
Returns:
NameDescription
[ToolCall](/sdk/python/references/models/prompt)The newly created tool call.

trace_event

@deprecated(
    "This method will be removed in a future version. Use trace_add_event instead."
)
def trace_event(trace_id: str,
                event_id: str,
                event: str,
                tags: Optional[Dict[str, str]] = None,
                metadata: Optional[Dict[str, Any]] = None)
Adds an event to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
event_idstrThe ID of the event.
eventstrThe name of the event.
tagsOptional[Dict[str, str]]The tags associated with the event.

trace_add_event

def trace_add_event(trace_id: str,
                    event_id: str,
                    event: str,
                    tags: Optional[Dict[str, str]] = None,
                    metadata: Optional[Dict[str, Any]] = None)
Adds an event to the trace.

trace_set_input

def trace_set_input(trace_id: str, input: str)
Sets the input for the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
inputstrThe input for the trace.

trace_set_output

def trace_set_output(trace_id: str, output: str)
Sets the output for the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
outputstrThe output for the trace.

trace_feedback

@deprecated(
    "This method will be removed in a future version. Use trace_add_feedback instead."
)
def trace_feedback(trace_id: str, feedback: Feedback)
Adds a feedback to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
feedbackFeedbackThe feedback to add.

trace_add_feedback

def trace_add_feedback(trace_id: str, feedback: FeedbackDict)
Adds a feedback to the trace.

trace_add_metadata

def trace_add_metadata(trace_id: str, metadata: Dict[str, Any])
Adds metadata to the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.
metadataDict[str, Any]The metadata to add.

trace_add_attachment

def trace_add_attachment(trace_id: str,
                         attachment: Union[FileAttachment, FileDataAttachment,
                                           UrlAttachment])
Adds an attachment to the trace.

trace_end

def trace_end(trace_id: str)
Ends the trace. Arguments:
NameTypeDescription
trace_idstrThe ID of the trace.

generation_set_model

def generation_set_model(generation_id: str, model: str)
Sets the model for the generation. Arguments:
NameTypeDescription
generation_idstrThe ID of the generation.
modelstrThe model for the generation.

generation_set_provider

def generation_set_provider(generation_id: str, provider: str)
Sets the provider for the generation.

generation_add_message

def generation_add_message(generation_id: str,
                           message: GenerationRequestMessage)
Adds a message to the generation. Arguments:
NameTypeDescription
generation_idstrThe ID of the generation.
messageAnyThe OpenAI chat message to add.

generation_set_model_parameters

def generation_set_model_parameters(generation_id: str,
                                    model_parameters: Dict[str, Any])
Sets the model parameters for the generation. Arguments:
NameTypeDescription
generation_idstrThe ID of the generation.
model_parametersdictThe model parameters for the generation.

generation_result

def generation_result(generation_id: str, result: Any)
Sets the result for the generation. Arguments:
NameTypeDescription
generation_idstrThe ID of the generation.
resultAnyThe result for the generation.

generation_add_attachment

def generation_add_attachment(generation_id: str,
                              attachment: Union[FileAttachment,
                                                FileDataAttachment,
                                                UrlAttachment])
Adds an attachment to the generation.

generation_end

def generation_end(generation_id: str)
Ends the generation. Arguments:
NameTypeDescription
generation_idstrThe ID of the generation.

generation_error

def generation_error(generation_id: str, error: GenerationError)
Sets the error for the generation. Arguments:
NameTypeDescription
generation_idstrThe ID of the generation.
errorGenerationErrorThe error for the generation.

span_generation

@deprecated(
    "This method will be removed in a future version. Use span_add_generation instead."
)
def span_generation(
        span_id: str, config: Union[GenerationConfig,
                                    GenerationConfigDict]) -> Generation
Adds a generation to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configGenerationConfigThe configuration for the generation.
Returns:
NameDescription
[Generation](/sdk/python/references/logger/components/generation)The newly created generation.

span_add_generation

def span_add_generation(
        span_id: str, config: Union[GenerationConfig,
                                    GenerationConfigDict]) -> Generation
Adds a generation to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configGenerationConfigThe configuration for the generation.
Returns:
NameDescription
[Generation](/sdk/python/references/logger/components/generation)The newly created generation.

span_add_error

def span_add_error(span_id: str, config: ErrorConfig) -> Error
Adds an error to the span.

span_retrieval

@deprecated(
    "This method will be removed in a future version. Use span_add_retrieval instead."
)
def span_retrieval(
        span_id: str, config: Union[RetrievalConfig,
                                    RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configRetrievalConfigThe configuration for the retrieval.
Returns:
NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)The newly created retrieval.

span_add_retrieval

def span_add_retrieval(
        span_id: str, config: Union[RetrievalConfig,
                                    RetrievalConfigDict]) -> Retrieval
Adds a retrieval to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configRetrievalConfigThe configuration for the retrieval.
Returns:
NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)The newly created retrieval.

span_add_tool_call

def span_add_tool_call(
        span_id: str, config: Union[ToolCallConfig,
                                    ToolCallConfigDict]) -> ToolCall
Adds a tool call to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configToolCallConfigThe configuration for the tool call.
Returns:
NameDescription
[ToolCall](/sdk/python/references/models/prompt)The newly created tool call.

span_end

def span_end(span_id: str)
Ends the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.

span_add_tag

def span_add_tag(span_id: str, key: str, value: str)
Adds a tag to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
keystrThe key of the tag.
valuestrThe value of the tag.

span_event

def span_event(span_id: str,
               event_id: str,
               name: str,
               tags: Optional[Dict[str, str]] = None,
               metadata: Optional[Dict[str, Any]] = None)
Adds an event to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
event_idstrThe ID of the event.
namestrThe name of the event.
tagsOptional[Dict[str, str]]The tags associated with the event.

span_add_metadata

def span_add_metadata(span_id: str, metadata: Dict[str, Any])
Adds metadata to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
metadataDict[str, Any]The metadata to add.

span_add_attachment

def span_add_attachment(span_id: str,
                        attachment: Union[FileAttachment, FileDataAttachment,
                                          UrlAttachment])
Adds an attachment to the span.

span_span

@deprecated(
    "This method will be removed in a future version. Use span_add_sub_span instead."
)
def span_span(span_id: str, config: Union[SpanConfig, SpanConfigDict]) -> Span
Adds a span to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configSpanConfigThe configuration for the sub-span.
Returns:
NameDescription
[Span](/sdk/python/references/logger/components/span)The newly created sub-span.

span_add_sub_span

def span_add_sub_span(span_id: str, config: Union[SpanConfig,
                                                  SpanConfigDict]) -> Span
Adds a sub-span to the span. Arguments:
NameTypeDescription
span_idstrThe ID of the span.
configSpanConfigThe configuration for the sub-span.
Returns:
NameDescription
[Span](/sdk/python/references/logger/components/span)The newly created sub-span.

retrieval_end

def retrieval_end(retrieval_id: str)
Ends the retrieval. Arguments:
NameTypeDescription
retrieval_idstrThe ID of the retrieval.

retrieval_input

def retrieval_input(retrieval_id: str, query: Any)
Sets the input for the retrieval. Arguments:
NameTypeDescription
retrieval_idstrThe ID of the retrieval.
queryAnyThe input for the retrieval.

retrieval_output

def retrieval_output(retrieval_id: str, docs: Any)
Sets the output for the retrieval. Arguments:
NameTypeDescription
retrieval_idstrThe ID of the retrieval.
docsAnyThe output for the retrieval.

retrieval_add_tag

def retrieval_add_tag(retrieval_id: str, key: str, value: str)
Adds a tag to the retrieval. Arguments:
NameTypeDescription
retrieval_idstrThe ID of the retrieval.
keystrThe key of the tag.
valuestrThe value of the tag.

retrieval_add_attachment

def retrieval_add_attachment(retrieval_id: str,
                             attachment: Union[FileAttachment,
                                               FileDataAttachment,
                                               UrlAttachment])
Adds an attachment to the retrieval.

tool_call_update

def tool_call_update(tool_call_id: str, data: Dict[str, Any])
Updates the tool call. Arguments:
NameTypeDescription
tool_call_idstrThe ID of the tool call.
dataDict[str, Any]The data to update the tool call with.

tool_call_result

def tool_call_result(tool_call_id: str, result: Any)
Sets the result for the tool call. Arguments:
NameTypeDescription
tool_call_idstrThe ID of the tool call.
resultAnyThe result for the tool call.

tool_call_error

def tool_call_error(tool_call_id: str, error: Union[ToolCallError,
                                                    ToolCallErrorDict])
Sets the error for the tool call. Arguments:
NameTypeDescription
tool_call_idstrThe ID of the tool call.
errorToolCallErrorThe error for the tool call.

tool_call_add_metadata

def tool_call_add_metadata(tool_call_id: str, metadata: Dict[str, Any])
Adds metadata to the tool call. Arguments:
NameTypeDescription
tool_call_idstrThe ID of the tool call.
metadataDict[str, Any]The metadata to add.

id

@property
def id()
Returns the ID of the logger.

flush

def flush()
Flushes the writer.

cleanup

def cleanup(is_sync=False)
Cleans up the writer.