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

> Span functionality for Components integration.

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

## [SpanConfig](/sdk/python/references/logger/components/span)

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

@dataclass
class SpanConfig()
```

[Span](/sdk/python/references/logger/components/span) config.

This class represents a span config.

## [SpanConfigDict](/sdk/python/references/logger/components/span)

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

[Span](/sdk/python/references/logger/components/span) config dict.

This class represents a span config dictionary.

#### get\_span\_config\_dict

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

| Name     | Description            |
| -------- | ---------------------- |
| `config` | The config to convert. |

**Returns**:

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

## [Span](/sdk/python/references/logger/components/span)

```python theme={null}
class Span(EventEmittingBaseContainer)
```

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

This class represents a span.

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

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

Initialize a span.

**Arguments**:

| Name     | Description                             |
| -------- | --------------------------------------- |
| `config` | The config to initialize the span with. |
| `writer` | The writer to use.                      |

#### span

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

Add a span to this span.

**Arguments**:

| Name     | Description                    |
| -------- | ------------------------------ |
| `config` | The config to add the span to. |

#### input

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

Set the input for this span.

**Arguments**:

| Name    | Description                     |
| ------- | ------------------------------- |
| `input` | The input to set for this span. |

#### input\_

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

Set the input for this span.

**Arguments**:

| Name      | Description                              |
| --------- | ---------------------------------------- |
| `writer`  | The writer to use.                       |
| `span_id` | The id of the span to set the input for. |
| `input`   | The input to set for this span.          |

#### add\_error

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

Add an error to this span.

**Arguments**:

| Name     | Description                     |
| -------- | ------------------------------- |
| `config` | The config to add the error to. |

**Returns**:

| Name                                            | Description               |
| ----------------------------------------------- | ------------------------- |
| `[Error](/sdk/python/references/models/prompt)` | The error that was added. |

#### error\_

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

Add an error to this span.

**Arguments**:

| Name      | Description                             |
| --------- | --------------------------------------- |
| `writer`  | The writer to use.                      |
| `span_id` | The id of the span to add the error to. |
| `config`  | The config to add the error to.         |

**Returns**:

| Name                                            | Description               |
| ----------------------------------------------- | ------------------------- |
| `[Error](/sdk/python/references/models/prompt)` | The error that was added. |

#### span\_

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

Add a span to this span.

**Arguments**:

| Name      | Description                            |
| --------- | -------------------------------------- |
| `writer`  | The writer to use.                     |
| `span_id` | The id of the span to add the span to. |
| `config`  | The config to add the span to.         |

**Returns**:

| Name                                                    | Description              |
| ------------------------------------------------------- | ------------------------ |
| `[Span](/sdk/python/references/logger/components/span)` | The span that was added. |

#### generation

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

Add a generation to this span.

**Arguments**:

| Name     | Description                          |
| -------- | ------------------------------------ |
| `config` | The config to add the generation to. |

**Returns**:

| Name                                                                | Description                    |
| ------------------------------------------------------------------- | ------------------------------ |
| `[Generation](/sdk/python/references/logger/components/generation)` | The generation that was added. |

#### tool\_call

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

Add a tool call to this span.

**Arguments**:

| Name     | Description                         |
| -------- | ----------------------------------- |
| `config` | The config to add the tool call to. |

**Returns**:

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

#### tool\_call\_

```python theme={null}
@staticmethod
def tool_call_(writer: LogWriter, span_id: str,
               config: Union[ToolCallConfig, ToolCallConfigDict]) -> ToolCall
```

Add a tool call to this span.

**Arguments**:

| Name      | Description                                 |
| --------- | ------------------------------------------- |
| `writer`  | The writer to use.                          |
| `span_id` | The id of the span to add the tool call to. |
| `config`  | The config to add the tool call to.         |

**Returns**:

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

#### generation\_

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

Add a generation to this span.

**Arguments**:

| Name      | Description                                  |
| --------- | -------------------------------------------- |
| `writer`  | The writer to use.                           |
| `span_id` | The id of the span to add the generation to. |
| `config`  | The config to add the generation to.         |

**Returns**:

| Name                                                                | Description                    |
| ------------------------------------------------------------------- | ------------------------------ |
| `[Generation](/sdk/python/references/logger/components/generation)` | The generation that was added. |

#### add\_attachment

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

Add an attachment to this span.

**Arguments**:

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

#### add\_attachment\_

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

Static method to add an attachment to a span.

**Arguments**:

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

#### retrieval

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

Add a retrieval to this span.

**Arguments**:

| Name     | Description                         |
| -------- | ----------------------------------- |
| `config` | The config to add the retrieval to. |

**Returns**:

| Name                                                              | Description                   |
| ----------------------------------------------------------------- | ----------------------------- |
| `[Retrieval](/sdk/python/references/logger/components/retrieval)` | The retrieval that was added. |

#### retrieval\_

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

Add a retrieval to this span.

**Arguments**:

| Name      | Description                                 |
| --------- | ------------------------------------------- |
| `writer`  | The writer to use.                          |
| `span_id` | The id of the span to add the retrieval to. |
| `config`  | The config to add the retrieval to.         |

**Returns**:

| Name                                                              | Description                   |
| ----------------------------------------------------------------- | ----------------------------- |
| `[Retrieval](/sdk/python/references/logger/components/retrieval)` | The retrieval that was added. |

#### end\_

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

End this span.

**Arguments**:

| Name      | Description                  |
| --------- | ---------------------------- |
| `writer`  | The writer to use.           |
| `span_id` | The id of the span to end.   |
| `data`    | The data to add to the span. |

#### add\_tag\_

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

Add a tag to this span.

**Arguments**:

| Name      | Description                           |
| --------- | ------------------------------------- |
| `writer`  | The writer to use.                    |
| `span_id` | The id of the span to add the tag to. |
| `key`     | The key of the tag.                   |
| `value`   | The value of the tag.                 |

#### event\_

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

| Name       | Description                             |
| ---------- | --------------------------------------- |
| `writer`   | The writer to use.                      |
| `span_id`  | The id of the span to add the event to. |
| `id`       | The id of the event.                    |
| `name`     | The name of the event.                  |
| `tags`     | The tags of the event.                  |
| `metadata` | The metadata of the event.              |
