> ## 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.

# components.Trace

> Trace functionality for Components integration.

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

## [TraceConfig](/sdk/python/references/logger/components/trace)

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

@dataclass
class TraceConfig()
```

[Trace](/sdk/python/references/logger/components/trace) config.

This class represents a trace config.

## [TraceConfigDict](/sdk/python/references/logger/components/trace)

```python theme={null}
class TraceConfigDict(TypedDict)
```

[Trace](/sdk/python/references/logger/components/trace) config dict.

This class represents a trace config dictionary.

#### get\_trace\_config\_dict

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

Convert a [TraceConfig](/sdk/python/references/logger/components/trace) object to a [TraceConfigDict](/sdk/python/references/logger/components/trace).

**Arguments**:

| Name     | Description                                                                                                                                                      |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `config` | Either a [TraceConfig](/sdk/python/references/logger/components/trace) object or a [TraceConfigDict](/sdk/python/references/logger/components/trace) dictionary. |

**Returns**:

A [TraceConfigDict](/sdk/python/references/logger/components/trace) dictionary representation of the config.

## [Trace](/sdk/python/references/logger/components/trace)

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

```python theme={null}
def __init__(config: Union[TraceConfig, TraceConfigDict], writer: LogWriter)
```

Initialize a new [Trace](/sdk/python/references/logger/components/trace) instance.

**Arguments**:

| Name     | Description                                                                                                                                                                           |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `config` | Configuration for the trace, either as a [TraceConfig](/sdk/python/references/logger/components/trace) object or a [TraceConfigDict](/sdk/python/references/logger/components/trace). |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use for writing log entries.                                                                                        |

#### set\_input

```python theme={null}
def set_input(input: str)
```

Set the input for this trace.

**Arguments**:

| Name    | Description              |
| ------- | ------------------------ |
| `input` | The input string to set. |

#### set\_input\_

```python theme={null}
@staticmethod
def set_input_(writer: LogWriter, trace_id: str, input: str)
```

Static method to set the input for a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to update.                                         |
| `input`    | The input string to set.                                               |

#### set\_output

```python theme={null}
def set_output(output: str)
```

Set the output for this trace.

**Arguments**:

| Name     | Description               |
| -------- | ------------------------- |
| `output` | The output string to set. |

#### set\_output\_

```python theme={null}
@staticmethod
def set_output_(writer: LogWriter, trace_id: str, output: str)
```

Static method to set the output for a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to update.                                         |
| `output`   | The output string to set.                                              |

#### generation

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

Add a generation to this trace.

**Arguments**:

| Name     | Description                       |
| -------- | --------------------------------- |
| `config` | Configuration for the generation. |

**Returns**:

A new [Generation](/sdk/python/references/logger/components/generation) instance.

#### tool\_call

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

Add a tool call to this trace.

**Arguments**:

| Name     | Description                      |
| -------- | -------------------------------- |
| `config` | Configuration for the tool call. |

**Returns**:

A new [ToolCall](/sdk/python/references/models/prompt) instance.

#### tool\_call\_

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

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the tool call to.                           |
| `config`   | Configuration for the tool call.                                       |

**Returns**:

A new [ToolCall](/sdk/python/references/models/prompt) instance.

#### generation\_

```python theme={null}
@staticmethod
def generation_(
        writer: LogWriter, trace_id: str,
        config: Union[GenerationConfig, GenerationConfigDict]) -> Generation
```

Static method to add a generation to a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the generation to.                          |
| `config`   | Configuration for the generation.                                      |

**Returns**:

A new [Generation](/sdk/python/references/logger/components/generation) instance.

#### add\_error

```python theme={null}
def add_error(config: ErrorConfig) -> Error
```

Add an error to this trace.

**Arguments**:

| Name     | Description                  |
| -------- | ---------------------------- |
| `config` | Configuration for the error. |

**Returns**:

A new [Error](/sdk/python/references/models/prompt) instance.

#### error\_

```python theme={null}
@staticmethod
def error_(writer: LogWriter, trace_id: str, config: ErrorConfig) -> Error
```

Static method to add an error to a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the error to.                               |
| `config`   | Configuration for the error.                                           |

**Returns**:

A new [Error](/sdk/python/references/models/prompt) instance.

#### retrieval

```python theme={null}
def retrieval(config: Union[RetrievalConfig, RetrievalConfigDict])
```

Add a retrieval to this trace.

**Arguments**:

| Name     | Description                      |
| -------- | -------------------------------- |
| `config` | Configuration for the retrieval. |

**Returns**:

A new [Retrieval](/sdk/python/references/logger/components/retrieval) instance.

#### retrieval\_

```python theme={null}
@staticmethod
def retrieval_(writer: LogWriter, trace_id: str,
               config: Union[RetrievalConfig, RetrievalConfigDict])
```

Static method to add a retrieval to a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the retrieval to.                           |
| `config`   | Configuration for the retrieval.                                       |

**Returns**:

A new [Retrieval](/sdk/python/references/logger/components/retrieval) instance.

#### span

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

Add a span to this trace.

**Arguments**:

| Name     | Description                 |
| -------- | --------------------------- |
| `config` | Configuration for the span. |

**Returns**:

A new [Span](/sdk/python/references/logger/components/span) instance.

#### span\_

```python theme={null}
@staticmethod
def span_(writer: LogWriter, trace_id: str,
          config: Union["SpanConfig", "SpanConfigDict"]) -> "Span"
```

Static method to add a span to a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the span to.                                |
| `config`   | Configuration for the span.                                            |

**Returns**:

A new [Span](/sdk/python/references/logger/components/span) instance.

#### feedback

```python theme={null}
def feedback(feedback: Union[Feedback, FeedbackDict])
```

Add feedback to this trace.

**Arguments**:

| Name       | Description          |
| ---------- | -------------------- |
| `feedback` | The feedback to add. |

#### feedback\_

```python theme={null}
@staticmethod
def feedback_(writer: LogWriter, trace_id: str, feedback: Union[Feedback,
                                                                FeedbackDict])
```

Static method to add feedback to a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the feedback to.                            |
| `feedback` | The feedback to add.                                                   |

#### add\_tag\_

```python theme={null}
@staticmethod
def add_tag_(writer: LogWriter, id: str, key: str, value: str)
```

Static method to add a tag to a trace.

**Arguments**:

| Name     | Description                                                            |
| -------- | ---------------------------------------------------------------------- |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`     | The ID of the trace to add the tag to.                                 |
| `key`    | The tag key.                                                           |
| `value`  | The tag value.                                                         |

#### add\_attachment

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

Add an attachment to this trace.

**Arguments**:

| Name         | Description            |
| ------------ | ---------------------- |
| `attachment` | The attachment to add. |

#### add\_attachment\_

```python theme={null}
@staticmethod
def add_attachment_(writer: LogWriter, trace_id: str,
                    attachment: Union[FileAttachment, FileDataAttachment,
                                      UrlAttachment])
```

Static method to add an attachment to a trace.

**Arguments**:

| Name         | Description                                                            |
| ------------ | ---------------------------------------------------------------------- |
| `writer`     | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id`   | The ID of the trace to add the attachment to.                          |
| `attachment` | The attachment to add.                                                 |

#### end\_

```python theme={null}
@staticmethod
def end_(writer: LogWriter,
         trace_id: str,
         data: Optional[Dict[str, str]] = None)
```

Static method to end a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to end.                                            |
| `data`     | Additional data to include in the end event.                           |

**Returns**:

The result of the end operation.

#### event\_

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

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `trace_id` | The ID of the trace to add the event to.                               |
| `id`       | The ID of the event.                                                   |
| `event`    | The name of the event.                                                 |
| `tags`     | Optional tags to associate with the event.                             |
| `metadata` | Optional metadata to include with the event.                           |

**Returns**:

The result of the event operation.

#### data

```python theme={null}
def data() -> Dict[str, Any]
```

Get the data representation of this trace.

**Returns**:

A dictionary containing the trace data.
