> ## 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-node/observability

> Metrics & spans — generated from packages/sdk-node/src/observability.ts.

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

*Source:* [`packages/sdk-node/src/observability.ts`](https://github.com/valid22/alibi-ai/blob/main/packages/sdk-node/src/observability.ts)

## `MetricSample`

| Property | Type |
| - | - |
| `name` | `string` |
| `value` | `number` |
| `unit` | `string` |
| `labels` | `Record<string, string>` |

## `MetricsRegistry`

### `samples`

```ts theme={null}
samples: MetricSample[]
```

### `counters`

```ts theme={null}
counters: Record<string, number>
```

### `observe`

```ts theme={null}
observe(
    name: string,
    value: number,
    opts?: { unit?: string; labels?: Record<string, string> },
  ): void
```

**Parameters**

| Name | Type |
| - | - |
| `name` | `string` |
| `value` | `number` |
| `opts` | `\{ unit?: string; labels?: Record<string, string> \}` |

### `incr`

```ts theme={null}
incr(name: string, amount = 1): void
```

**Parameters**

| Name | Type |
| - | - |
| `name` | `string` |
| `amount = 1` | `—` |

### `snapshot`

```ts theme={null}
snapshot(): {
    samples: MetricSample[];
    counters: Record<string, number>;
  }
```

### `reset`

```ts theme={null}
reset(): void
```

## `AlibiSpan`

| Property | Type |
| - | - |
| `name` | `string` |
| `attributes` | `Record<string, unknown>` |
| `startNs` | `number` |
| `endNs` | `number` |
| `status` | `string` |
| `error?` | `string` |
| `durationMs` | `number` |

## `withSpan`

```ts theme={null}
export async function withSpan<T>(
  name: string,
  opts: {
    attributes?: Record<string, unknown>;
    metric?: string;
  },
  fn: (span: AlibiSpan) => Promise<T> | T,
): Promise<T>
```

**Parameters**

| Name | Type |
| - | - |
| `name` | `string` |
| `opts` | `\{ attributes?: Record<string, unknown>; metric?: string; \}` |
| `fn` | `(span: AlibiSpan) => Promise<T> \| T,` |

## `recordPoolWait`

```ts theme={null}
export function recordPoolWait(
  ms: number,
  opts?: { sandboxId?: string },
): void
```

**Parameters**

| Name | Type |
| - | - |
| `ms` | `number` |
| `opts` | `\{ sandboxId?: string \}` |

## `recordRestore`

```ts theme={null}
export function recordRestore(ms: number, opts: { plugin: string }): void
```

**Parameters**

| Name | Type |
| - | - |
| `ms` | `number` |
| `opts` | `\{ plugin: string \}` |

## `recordRecordLatency`

```ts theme={null}
export function recordRecordLatency(
  ms: number,
  opts: { path: string },
): void
```

**Parameters**

| Name | Type |
| - | - |
| `ms` | `number` |
| `opts` | `\{ path: string \}` |


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