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

> Metrics & spans — generated from python/alibi_sdk source.

Structured spans + metrics for the Alibi SDK (record latency, restore, pool wait).

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

## `MetricSample`

**Attributes**

| Name | Type |
| - | - |
| `name` | `str` |
| `value` | `float` |
| `unit` | `str` |
| `labels` | `dict[str, str]` |

## `MetricsRegistry`

In-process metrics sink (exportable; no external deps required).

#### `__init__`

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

**Returns**

`None`

#### `observe`

```python theme={null}
def observe(name: str, value: float, unit: str = 'ms', labels: Optional[dict[str, str]] = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `name` | `str` |
| `value` | `float` |
| `unit` | `str` |
| `labels` | `Optional[dict[str, str]]` |

**Returns**

`None`

#### `incr`

```python theme={null}
def incr(name: str, amount: float = 1.0) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `name` | `str` |
| `amount` | `float` |

**Returns**

`None`

#### `snapshot`

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

**Returns**

`dict[str, Any]`

#### `reset`

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

**Returns**

`None`

## `metrics`

Module-level export.

## `AlibiSpan`

**Attributes**

| Name | Type |
| - | - |
| `name` | `str` |
| `attributes` | `dict[str, Any]` |
| `start_ns` | `int` |
| `end_ns` | `int` |
| `status` | `str` |
| `error` | `Optional[str]` |

#### `duration_ms`

```python theme={null}
def duration_ms() -> float
```

**Returns**

`float`

#### `to_dict`

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

**Returns**

`dict[str, Any]`

### `span`

```python theme={null}
def span(name: str, attributes: Optional[dict[str, Any]] = None, metric: Optional[str] = None) -> Iterator[AlibiSpan]
```

Emit a structured span; optionally record duration as a metric.

**Parameters**

| Name | Type |
| - | - |
| `name` | `str` |
| `attributes` | `Optional[dict[str, Any]]` |
| `metric` | `Optional[str]` |

**Returns**

`Iterator[AlibiSpan]`

### `record_pool_wait`

```python theme={null}
def record_pool_wait(ms: float, sandbox_id: Optional[str] = None) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `ms` | `float` |
| `sandbox_id` | `Optional[str]` |

**Returns**

`None`

### `record_restore`

```python theme={null}
def record_restore(ms: float, plugin: str) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `ms` | `float` |
| `plugin` | `str` |

**Returns**

`None`

### `record_record_latency`

```python theme={null}
def record_record_latency(ms: float, path: str) -> None
```

**Parameters**

| Name | Type |
| - | - |
| `ms` | `float` |
| `path` | `str` |

**Returns**

`None`


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