> ## Documentation Index
> Fetch the complete documentation index at: https://alibi.itsdote.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# alibi_sdk.context

> Span context — generated from python/alibi_sdk source.

Request-span context for plugin observation buffers.

*Source:* [`python/alibi_sdk/alibi_sdk/context.py`](https://github.com/valid22/alibi-ai/blob/main/python/alibi_sdk/alibi_sdk/context.py)

## `SpanContext`

**Attributes**

| Name | Type |
| - | - |
| `span_id` | `str` |
| `request_id` | `str` |
| `project_id` | `str` |
| `mode` | `AlibiMode` |
| `session_id` | `Optional[str]` |
| `run_id` | `Optional[str]` |
| `case_id` | `Optional[str]` |
| `step_order` | `Optional[int]` |
| `extras` | `dict[str, Any]` |

## `ObservationBuffer`

Per-span buffer that SQL/Redis wrappers append into.

**Attributes**

| Name | Type |
| - | - |
| `mutations` | `list[dict[str, Any]]` |
| `reads` | `list[dict[str, Any]]` |

#### `clear`

```python theme={null}
def clear() -> None
```

**Returns**

`None`

#### `add_mutation`

```python theme={null}
def add_mutation(plugin: str, op: str, target: str, before: Any = None, after: Any = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `plugin` | `str` |
| `op` | `str` |
| `target` | `str` |
| `before` | `Any` |
| `after` | `Any` |

**Returns**

`None`

#### `add_read`

```python theme={null}
def add_read(plugin: str, op: str, target: str, result: Any = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `plugin` | `str` |
| `op` | `str` |
| `target` | `str` |
| `result` | `Any` |

**Returns**

`None`

### `get_span`

```python theme={null}
def get_span() -> Optional[SpanContext]
```

**Returns**

`Optional[SpanContext]`

### `get_buffer`

```python theme={null}
def get_buffer() -> Optional[ObservationBuffer]
```

**Returns**

`Optional[ObservationBuffer]`

### `begin_span`

```python theme={null}
def begin_span(span: SpanContext) -> tuple[Any, Any]
```

Bind span + fresh buffer; returns tokens for reset.

**Parameters**

| Name | Type |
| - | - |
| `span` | `SpanContext` |

**Returns**

`tuple[Any, Any]`

### `end_span`

```python theme={null}
def end_span(tokens: tuple[Any, Any]) -> ObservationBuffer
```

**Parameters**

| Name | Type |
| - | - |
| `tokens` | `tuple[Any, Any]` |

**Returns**

`ObservationBuffer`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.