> ## Documentation Index
> Fetch the complete documentation index at: https://www.getmaxim.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Logger

> Logger utilities for logging and instrumentation utilities for tracking ai model interactions.

[View module source on GitHub](https://github.com/maximhq/maxim-py/blob/main/maxim/logger/logger.py)

Configuration class for [Maxim](/sdk/python/references/maxim) [Logger](/sdk/python/references/logger/logger).

This class holds the configuration settings for the [Logger](/sdk/python/references/logger/logger), including
the logger ID, auto-flush setting, and flush interval.

**Attributes**:

| Name             | Type   | Description                                                                                        |
| ---------------- | ------ | -------------------------------------------------------------------------------------------------- |
| `id`             | *str*  | The unique identifier for the logger.                                                              |
| `auto_flush`     | *bool* | Whether to automatically flush logs. Defaults to True.                                             |
| `flush_interval` | *int*  | The interval (in seconds) at which to flush logs when auto\_flush is True. Defaults to 10 seconds. |

## [LoggerConfig](/sdk/python/references/logger/logger)

```python theme={null}
@deprecated(
    "This class will be removed in a future version. Use LoggerConfigDict instead."
)
class LoggerConfig()
```

Configuration class for [Maxim](/sdk/python/references/maxim) [Logger](/sdk/python/references/logger/logger).

This class holds the configuration settings for the [Logger](/sdk/python/references/logger/logger), including
the logger ID, auto-flush setting, and flush interval.

**Attributes**:

| Name             | Type   | Description                                                                |
| ---------------- | ------ | -------------------------------------------------------------------------- |
| `id`             | *str*  | The unique identifier for the logger.                                      |
| `auto_flush`     | *bool* | Whether to automatically flush logs.                                       |
| `flush_interval` | *int*  | The interval (in seconds) at which to flush logs when auto\_flush is True. |

## [Logger](/sdk/python/references/logger/logger)

```python theme={null}
class Logger()
```

A class representing a logger for the [Maxim](/sdk/python/references/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](/sdk/python/references/logger/writer) to handle the
actual logging operations.

**Attributes**:

| Name               | Type                                                | Description                                                                                        |
| ------------------ | --------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `_id`              | *str*                                               | The unique identifier for this logger instance.                                                    |
| `raise_exceptions` | *bool*                                              | Whether to raise exceptions during logging operations.                                             |
| `is_debug`         | *bool*                                              | Whether debug logging is enabled.                                                                  |
| `writer`           | *[LogWriter](/sdk/python/references/logger/writer)* | The [LogWriter](/sdk/python/references/logger/writer) instance used for actual logging operations. |

#### \_\_init\_\_

```python theme={null}
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**:

| Name               | Type                                                   | Description                                         |
| ------------------ | ------------------------------------------------------ | --------------------------------------------------- |
| `config`           | *[LoggerConfig](/sdk/python/references/logger/logger)* | The configuration for the logger.                   |
| `api_key`          | *str*                                                  | The API key for the logger.                         |
| `base_url`         | *str*                                                  | The base URL for the logger.                        |
| `is_debug`         | *bool, optional*                                       | Whether to enable debug logging. Defaults to False. |
| `raise_exceptions` | *bool, optional*                                       | Whether to raise exceptions. Defaults to False.     |

#### session

```python theme={null}
def session(config: Union[SessionConfig, SessionConfigDict]) -> Session
```

Creates a new session with the given configuration.

**Arguments**:

| Name     | Type                                                                | Description                            |
| -------- | ------------------------------------------------------------------- | -------------------------------------- |
| `config` | *[SessionConfig](/sdk/python/references/logger/components/session)* | The configuration for the new session. |

**Returns**:

| Name                                                          | Description                |
| ------------------------------------------------------------- | -------------------------- |
| `[Session](/sdk/python/references/logger/components/session)` | The newly created session. |

#### trace

```python theme={null}
def trace(config: Union[TraceConfig, TraceConfigDict]) -> Trace
```

Creates a new trace with the given configuration.

**Arguments**:

| Name     | Type                                                            | Description                          |
| -------- | --------------------------------------------------------------- | ------------------------------------ |
| `config` | *[TraceConfig](/sdk/python/references/logger/components/trace)* | The configuration for the new trace. |

**Returns**:

| Name                                                      | Description              |
| --------------------------------------------------------- | ------------------------ |
| `[Trace](/sdk/python/references/logger/components/trace)` | The newly created trace. |

#### session\_add\_tag

```python theme={null}
def session_add_tag(session_id: str, key: str, value: str)
```

Adds a tag to the session.

**Arguments**:

| Name         | Type  | Description            |
| ------------ | ----- | ---------------------- |
| `session_id` | *str* | The ID of the session. |
| `key`        | *str* | The key of the tag.    |
| `value`      | *str* | The value of the tag.  |

#### session\_end

```python theme={null}
def session_end(session_id: str)
```

Ends the session.

**Arguments**:

| Name         | Type  | Description            |
| ------------ | ----- | ---------------------- |
| `session_id` | *str* | The ID of the session. |

#### session\_event

```python theme={null}
def session_event(session_id: str, event_id: str, event: str, data: Any)
```

Adds an event to the session.

**Arguments**:

| Name         | Type  | Description                         |
| ------------ | ----- | ----------------------------------- |
| `session_id` | *str* | The ID of the session.              |
| `event_id`   | *str* | The ID of the event.                |
| `event`      | *str* | The name of the event.              |
| `data`       | *Any* | The data associated with the event. |

#### session\_feedback

```python theme={null}
@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**:

| Name         | Type                                                            | Description            |
| ------------ | --------------------------------------------------------------- | ---------------------- |
| `session_id` | *str*                                                           | The ID of the session. |
| `feedback`   | *[Feedback](/sdk/python/references/logger/components/feedback)* | The feedback to add.   |

#### session\_add\_attachment

```python theme={null}
def session_add_attachment(session_id: str,
                           attachment: Union[FileAttachment,
                                             FileDataAttachment,
                                             UrlAttachment])
```

Adds an attachment to the session.

#### session\_add\_feedback

```python theme={null}
def session_add_feedback(session_id: str, feedback: FeedbackDict)
```

Adds a feedback to the session.

#### session\_trace

```python theme={null}
@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**:

| Name         | Type                                                            | Description                      |
| ------------ | --------------------------------------------------------------- | -------------------------------- |
| `session_id` | *str*                                                           | The ID of the session.           |
| `config`     | *[TraceConfig](/sdk/python/references/logger/components/trace)* | The configuration for the trace. |

**Returns**:

| Name                                                      | Description              |
| --------------------------------------------------------- | ------------------------ |
| `[Trace](/sdk/python/references/logger/components/trace)` | The newly created trace. |

#### session\_add\_trace

```python theme={null}
def session_add_trace(session_id: str,
                      config: Union[TraceConfig, TraceConfigDict]) -> Trace
```

Adds a trace to the session.

**Arguments**:

| Name         | Type                                                            | Description                      |
| ------------ | --------------------------------------------------------------- | -------------------------------- |
| `session_id` | *str*                                                           | The ID of the session.           |
| `config`     | *[TraceConfig](/sdk/python/references/logger/components/trace)* | The configuration for the trace. |

**Returns**:

| Name                                                      | Description              |
| --------------------------------------------------------- | ------------------------ |
| `[Trace](/sdk/python/references/logger/components/trace)` | The newly created trace. |

#### trace\_generation

```python theme={null}
@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**:

| Name       | Type               | Description                           |
| ---------- | ------------------ | ------------------------------------- |
| `trace_id` | *str*              | The ID of the trace.                  |
| `config`   | *GenerationConfig* | The configuration for the generation. |

**Returns**:

| Name                                                                | Description                   |
| ------------------------------------------------------------------- | ----------------------------- |
| `[Generation](/sdk/python/references/logger/components/generation)` | The newly created generation. |

#### trace\_add\_generation

```python theme={null}
def trace_add_generation(
        trace_id: str, config: Union[GenerationConfig,
                                     GenerationConfigDict]) -> Generation
```

Adds a generation to the trace.

**Arguments**:

| Name       | Type               | Description                           |
| ---------- | ------------------ | ------------------------------------- |
| `trace_id` | *str*              | The ID of the trace.                  |
| `config`   | *GenerationConfig* | The configuration for the generation. |

**Returns**:

| Name                                                                | Description                   |
| ------------------------------------------------------------------- | ----------------------------- |
| `[Generation](/sdk/python/references/logger/components/generation)` | The newly created generation. |

#### trace\_retrieval

```python theme={null}
@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**:

| Name       | Type                                                                    | Description                          |
| ---------- | ----------------------------------------------------------------------- | ------------------------------------ |
| `trace_id` | *str*                                                                   | The ID of the trace.                 |
| `config`   | *[RetrievalConfig](/sdk/python/references/logger/components/retrieval)* | The configuration for the retrieval. |

**Returns**:

| Name                                                              | Description                  |
| ----------------------------------------------------------------- | ---------------------------- |
| `[Retrieval](/sdk/python/references/logger/components/retrieval)` | The newly created retrieval. |

#### trace\_add\_retrieval

```python theme={null}
def trace_add_retrieval(
        trace_id: str, config: Union[RetrievalConfig,
                                     RetrievalConfigDict]) -> Retrieval
```

Adds a retrieval to the trace.

**Arguments**:

| Name       | Type                                                                    | Description                          |
| ---------- | ----------------------------------------------------------------------- | ------------------------------------ |
| `trace_id` | *str*                                                                   | The ID of the trace.                 |
| `config`   | *[RetrievalConfig](/sdk/python/references/logger/components/retrieval)* | The configuration for the retrieval. |

**Returns**:

| Name                                                              | Description                  |
| ----------------------------------------------------------------- | ---------------------------- |
| `[Retrieval](/sdk/python/references/logger/components/retrieval)` | The newly created retrieval. |

#### trace\_span

```python theme={null}
@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**:

| Name       | Type                                                          | Description                     |
| ---------- | ------------------------------------------------------------- | ------------------------------- |
| `trace_id` | *str*                                                         | The ID of the trace.            |
| `config`   | *[SpanConfig](/sdk/python/references/logger/components/span)* | The configuration for the span. |

**Returns**:

| Name                                                    | Description             |
| ------------------------------------------------------- | ----------------------- |
| `[Span](/sdk/python/references/logger/components/span)` | The newly created span. |

#### trace\_add\_span

```python theme={null}
def trace_add_span(trace_id: str, config: Union[SpanConfig,
                                                SpanConfigDict]) -> Span
```

Adds a span to the trace.

**Arguments**:

| Name       | Type                                                          | Description                     |
| ---------- | ------------------------------------------------------------- | ------------------------------- |
| `trace_id` | *str*                                                         | The ID of the trace.            |
| `config`   | *[SpanConfig](/sdk/python/references/logger/components/span)* | The configuration for the span. |

**Returns**:

| Name                                                    | Description             |
| ------------------------------------------------------- | ----------------------- |
| `[Span](/sdk/python/references/logger/components/span)` | The newly created span. |

#### trace\_add\_error

```python theme={null}
def trace_add_error(trace_id: str, config: ErrorConfig) -> Error
```

Adds an error to the trace.

#### trace\_add\_tag

```python theme={null}
def trace_add_tag(trace_id: str, key: str, value: str)
```

Adds a tag to the trace.

**Arguments**:

| Name       | Type  | Description           |
| ---------- | ----- | --------------------- |
| `trace_id` | *str* | The ID of the trace.  |
| `key`      | *str* | The key of the tag.   |
| `value`    | *str* | The value of the tag. |

#### trace\_add\_tool\_call

```python theme={null}
def trace_add_tool_call(
        trace_id: str, config: Union[ToolCallConfig,
                                     ToolCallConfigDict]) -> ToolCall
```

Adds a tool call to the trace.

**Arguments**:

| Name       | Type                                                                   | Description                          |
| ---------- | ---------------------------------------------------------------------- | ------------------------------------ |
| `trace_id` | *str*                                                                  | The ID of the trace.                 |
| `config`   | *[ToolCallConfig](/sdk/python/references/logger/components/tool_call)* | The configuration for the tool call. |

**Returns**:

| Name                                               | Description                  |
| -------------------------------------------------- | ---------------------------- |
| `[ToolCall](/sdk/python/references/models/prompt)` | The newly created tool call. |

#### trace\_event

```python theme={null}
@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**:

| Name       | Type                         | Description                         |
| ---------- | ---------------------------- | ----------------------------------- |
| `trace_id` | *str*                        | The ID of the trace.                |
| `event_id` | *str*                        | The ID of the event.                |
| `event`    | *str*                        | The name of the event.              |
| `tags`     | *Optional\[Dict\[str, str]]* | The tags associated with the event. |

#### trace\_add\_event

```python theme={null}
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

```python theme={null}
def trace_set_input(trace_id: str, input: str)
```

Sets the input for the trace.

**Arguments**:

| Name       | Type  | Description              |
| ---------- | ----- | ------------------------ |
| `trace_id` | *str* | The ID of the trace.     |
| `input`    | *str* | The input for the trace. |

#### trace\_set\_output

```python theme={null}
def trace_set_output(trace_id: str, output: str)
```

Sets the output for the trace.

**Arguments**:

| Name       | Type  | Description               |
| ---------- | ----- | ------------------------- |
| `trace_id` | *str* | The ID of the trace.      |
| `output`   | *str* | The output for the trace. |

#### trace\_feedback

```python theme={null}
@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**:

| Name       | Type                                                            | Description          |
| ---------- | --------------------------------------------------------------- | -------------------- |
| `trace_id` | *str*                                                           | The ID of the trace. |
| `feedback` | *[Feedback](/sdk/python/references/logger/components/feedback)* | The feedback to add. |

#### trace\_add\_feedback

```python theme={null}
def trace_add_feedback(trace_id: str, feedback: FeedbackDict)
```

Adds a feedback to the trace.

#### trace\_add\_metadata

```python theme={null}
def trace_add_metadata(trace_id: str, metadata: Dict[str, Any])
```

Adds metadata to the trace.

**Arguments**:

| Name       | Type              | Description          |
| ---------- | ----------------- | -------------------- |
| `trace_id` | *str*             | The ID of the trace. |
| `metadata` | *Dict\[str, Any]* | The metadata to add. |

#### trace\_add\_attachment

```python theme={null}
def trace_add_attachment(trace_id: str,
                         attachment: Union[FileAttachment, FileDataAttachment,
                                           UrlAttachment])
```

Adds an attachment to the trace.

#### trace\_end

```python theme={null}
def trace_end(trace_id: str)
```

Ends the trace.

**Arguments**:

| Name       | Type  | Description          |
| ---------- | ----- | -------------------- |
| `trace_id` | *str* | The ID of the trace. |

#### generation\_set\_model

```python theme={null}
def generation_set_model(generation_id: str, model: str)
```

Sets the model for the generation.

**Arguments**:

| Name            | Type  | Description                   |
| --------------- | ----- | ----------------------------- |
| `generation_id` | *str* | The ID of the generation.     |
| `model`         | *str* | The model for the generation. |

#### generation\_set\_provider

```python theme={null}
def generation_set_provider(generation_id: str, provider: str)
```

Sets the provider for the generation.

#### generation\_add\_message

```python theme={null}
def generation_add_message(generation_id: str,
                           message: GenerationRequestMessage)
```

Adds a message to the generation.

**Arguments**:

| Name            | Type  | Description                     |
| --------------- | ----- | ------------------------------- |
| `generation_id` | *str* | The ID of the generation.       |
| `message`       | *Any* | The OpenAI chat message to add. |

#### generation\_set\_model\_parameters

```python theme={null}
def generation_set_model_parameters(generation_id: str,
                                    model_parameters: Dict[str, Any])
```

Sets the model parameters for the generation.

**Arguments**:

| Name               | Type   | Description                              |
| ------------------ | ------ | ---------------------------------------- |
| `generation_id`    | *str*  | The ID of the generation.                |
| `model_parameters` | *dict* | The model parameters for the generation. |

#### generation\_result

```python theme={null}
def generation_result(generation_id: str, result: Any)
```

Sets the result for the generation.

**Arguments**:

| Name            | Type  | Description                    |
| --------------- | ----- | ------------------------------ |
| `generation_id` | *str* | The ID of the generation.      |
| `result`        | *Any* | The result for the generation. |

#### generation\_add\_attachment

```python theme={null}
def generation_add_attachment(generation_id: str,
                              attachment: Union[FileAttachment,
                                                FileDataAttachment,
                                                UrlAttachment])
```

Adds an attachment to the generation.

#### generation\_end

```python theme={null}
def generation_end(generation_id: str)
```

Ends the generation.

**Arguments**:

| Name            | Type  | Description               |
| --------------- | ----- | ------------------------- |
| `generation_id` | *str* | The ID of the generation. |

#### generation\_error

```python theme={null}
def generation_error(generation_id: str, error: GenerationError)
```

Sets the error for the generation.

**Arguments**:

| Name            | Type                                                                | Description                   |
| --------------- | ------------------------------------------------------------------- | ----------------------------- |
| `generation_id` | *str*                                                               | The ID of the generation.     |
| `error`         | *[GenerationError](/sdk/python/references/logger/components/types)* | The error for the generation. |

#### span\_generation

```python theme={null}
@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**:

| Name      | Type               | Description                           |
| --------- | ------------------ | ------------------------------------- |
| `span_id` | *str*              | The ID of the span.                   |
| `config`  | *GenerationConfig* | The configuration for the generation. |

**Returns**:

| Name                                                                | Description                   |
| ------------------------------------------------------------------- | ----------------------------- |
| `[Generation](/sdk/python/references/logger/components/generation)` | The newly created generation. |

#### span\_add\_generation

```python theme={null}
def span_add_generation(
        span_id: str, config: Union[GenerationConfig,
                                    GenerationConfigDict]) -> Generation
```

Adds a generation to the span.

**Arguments**:

| Name      | Type               | Description                           |
| --------- | ------------------ | ------------------------------------- |
| `span_id` | *str*              | The ID of the span.                   |
| `config`  | *GenerationConfig* | The configuration for the generation. |

**Returns**:

| Name                                                                | Description                   |
| ------------------------------------------------------------------- | ----------------------------- |
| `[Generation](/sdk/python/references/logger/components/generation)` | The newly created generation. |

#### span\_add\_error

```python theme={null}
def span_add_error(span_id: str, config: ErrorConfig) -> Error
```

Adds an error to the span.

#### span\_retrieval

```python theme={null}
@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**:

| Name      | Type                                                                    | Description                          |
| --------- | ----------------------------------------------------------------------- | ------------------------------------ |
| `span_id` | *str*                                                                   | The ID of the span.                  |
| `config`  | *[RetrievalConfig](/sdk/python/references/logger/components/retrieval)* | The configuration for the retrieval. |

**Returns**:

| Name                                                              | Description                  |
| ----------------------------------------------------------------- | ---------------------------- |
| `[Retrieval](/sdk/python/references/logger/components/retrieval)` | The newly created retrieval. |

#### span\_add\_retrieval

```python theme={null}
def span_add_retrieval(
        span_id: str, config: Union[RetrievalConfig,
                                    RetrievalConfigDict]) -> Retrieval
```

Adds a retrieval to the span.

**Arguments**:

| Name      | Type                                                                    | Description                          |
| --------- | ----------------------------------------------------------------------- | ------------------------------------ |
| `span_id` | *str*                                                                   | The ID of the span.                  |
| `config`  | *[RetrievalConfig](/sdk/python/references/logger/components/retrieval)* | The configuration for the retrieval. |

**Returns**:

| Name                                                              | Description                  |
| ----------------------------------------------------------------- | ---------------------------- |
| `[Retrieval](/sdk/python/references/logger/components/retrieval)` | The newly created retrieval. |

#### span\_add\_tool\_call

```python theme={null}
def span_add_tool_call(
        span_id: str, config: Union[ToolCallConfig,
                                    ToolCallConfigDict]) -> ToolCall
```

Adds a tool call to the span.

**Arguments**:

| Name      | Type                                                                   | Description                          |
| --------- | ---------------------------------------------------------------------- | ------------------------------------ |
| `span_id` | *str*                                                                  | The ID of the span.                  |
| `config`  | *[ToolCallConfig](/sdk/python/references/logger/components/tool_call)* | The configuration for the tool call. |

**Returns**:

| Name                                               | Description                  |
| -------------------------------------------------- | ---------------------------- |
| `[ToolCall](/sdk/python/references/models/prompt)` | The newly created tool call. |

#### span\_end

```python theme={null}
def span_end(span_id: str)
```

Ends the span.

**Arguments**:

| Name      | Type  | Description         |
| --------- | ----- | ------------------- |
| `span_id` | *str* | The ID of the span. |

#### span\_add\_tag

```python theme={null}
def span_add_tag(span_id: str, key: str, value: str)
```

Adds a tag to the span.

**Arguments**:

| Name      | Type  | Description           |
| --------- | ----- | --------------------- |
| `span_id` | *str* | The ID of the span.   |
| `key`     | *str* | The key of the tag.   |
| `value`   | *str* | The value of the tag. |

#### span\_event

```python theme={null}
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**:

| Name       | Type                         | Description                         |
| ---------- | ---------------------------- | ----------------------------------- |
| `span_id`  | *str*                        | The ID of the span.                 |
| `event_id` | *str*                        | The ID of the event.                |
| `name`     | *str*                        | The name of the event.              |
| `tags`     | *Optional\[Dict\[str, str]]* | The tags associated with the event. |

#### span\_add\_metadata

```python theme={null}
def span_add_metadata(span_id: str, metadata: Dict[str, Any])
```

Adds metadata to the span.

**Arguments**:

| Name       | Type              | Description          |
| ---------- | ----------------- | -------------------- |
| `span_id`  | *str*             | The ID of the span.  |
| `metadata` | *Dict\[str, Any]* | The metadata to add. |

#### span\_add\_attachment

```python theme={null}
def span_add_attachment(span_id: str,
                        attachment: Union[FileAttachment, FileDataAttachment,
                                          UrlAttachment])
```

Adds an attachment to the span.

#### span\_span

```python theme={null}
@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**:

| Name      | Type                                                          | Description                         |
| --------- | ------------------------------------------------------------- | ----------------------------------- |
| `span_id` | *str*                                                         | The ID of the span.                 |
| `config`  | *[SpanConfig](/sdk/python/references/logger/components/span)* | The configuration for the sub-span. |

**Returns**:

| Name                                                    | Description                 |
| ------------------------------------------------------- | --------------------------- |
| `[Span](/sdk/python/references/logger/components/span)` | The newly created sub-span. |

#### span\_add\_sub\_span

```python theme={null}
def span_add_sub_span(span_id: str, config: Union[SpanConfig,
                                                  SpanConfigDict]) -> Span
```

Adds a sub-span to the span.

**Arguments**:

| Name      | Type                                                          | Description                         |
| --------- | ------------------------------------------------------------- | ----------------------------------- |
| `span_id` | *str*                                                         | The ID of the span.                 |
| `config`  | *[SpanConfig](/sdk/python/references/logger/components/span)* | The configuration for the sub-span. |

**Returns**:

| Name                                                    | Description                 |
| ------------------------------------------------------- | --------------------------- |
| `[Span](/sdk/python/references/logger/components/span)` | The newly created sub-span. |

#### retrieval\_end

```python theme={null}
def retrieval_end(retrieval_id: str)
```

Ends the retrieval.

**Arguments**:

| Name           | Type  | Description              |
| -------------- | ----- | ------------------------ |
| `retrieval_id` | *str* | The ID of the retrieval. |

#### retrieval\_input

```python theme={null}
def retrieval_input(retrieval_id: str, query: Any)
```

Sets the input for the retrieval.

**Arguments**:

| Name           | Type  | Description                  |
| -------------- | ----- | ---------------------------- |
| `retrieval_id` | *str* | The ID of the retrieval.     |
| `query`        | *Any* | The input for the retrieval. |

#### retrieval\_output

```python theme={null}
def retrieval_output(retrieval_id: str, docs: Any)
```

Sets the output for the retrieval.

**Arguments**:

| Name           | Type  | Description                   |
| -------------- | ----- | ----------------------------- |
| `retrieval_id` | *str* | The ID of the retrieval.      |
| `docs`         | *Any* | The output for the retrieval. |

#### retrieval\_add\_tag

```python theme={null}
def retrieval_add_tag(retrieval_id: str, key: str, value: str)
```

Adds a tag to the retrieval.

**Arguments**:

| Name           | Type  | Description              |
| -------------- | ----- | ------------------------ |
| `retrieval_id` | *str* | The ID of the retrieval. |
| `key`          | *str* | The key of the tag.      |
| `value`        | *str* | The value of the tag.    |

#### retrieval\_add\_attachment

```python theme={null}
def retrieval_add_attachment(retrieval_id: str,
                             attachment: Union[FileAttachment,
                                               FileDataAttachment,
                                               UrlAttachment])
```

Adds an attachment to the retrieval.

#### tool\_call\_update

```python theme={null}
def tool_call_update(tool_call_id: str, data: Dict[str, Any])
```

Updates the tool call.

**Arguments**:

| Name           | Type              | Description                            |
| -------------- | ----------------- | -------------------------------------- |
| `tool_call_id` | *str*             | The ID of the tool call.               |
| `data`         | *Dict\[str, Any]* | The data to update the tool call with. |

#### tool\_call\_result

```python theme={null}
def tool_call_result(tool_call_id: str, result: Any)
```

Sets the result for the tool call.

**Arguments**:

| Name           | Type  | Description                   |
| -------------- | ----- | ----------------------------- |
| `tool_call_id` | *str* | The ID of the tool call.      |
| `result`       | *Any* | The result for the tool call. |

#### tool\_call\_error

```python theme={null}
def tool_call_error(tool_call_id: str, error: Union[ToolCallError,
                                                    ToolCallErrorDict])
```

Sets the error for the tool call.

**Arguments**:

| Name           | Type                                                                  | Description                  |
| -------------- | --------------------------------------------------------------------- | ---------------------------- |
| `tool_call_id` | *str*                                                                 | The ID of the tool call.     |
| `error`        | *[ToolCallError](/sdk/python/references/logger/components/tool_call)* | The error for the tool call. |

#### tool\_call\_add\_metadata

```python theme={null}
def tool_call_add_metadata(tool_call_id: str, metadata: Dict[str, Any])
```

Adds metadata to the tool call.

**Arguments**:

| Name           | Type              | Description              |
| -------------- | ----------------- | ------------------------ |
| `tool_call_id` | *str*             | The ID of the tool call. |
| `metadata`     | *Dict\[str, Any]* | The metadata to add.     |

#### id

```python theme={null}
@property
def id()
```

Returns the ID of the logger.

#### flush

```python theme={null}
def flush()
```

Flushes the writer.

#### cleanup

```python theme={null}
def cleanup(is_sync=False)
```

Cleans up the writer.
