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

# Events & Observability

> JavaScript API reference for Events & Observability.

## EventEmitter

A typed event emitter. Handlers may be sync or async; async rejections and
thrown errors are caught and logged rather than propagated. Parameterize with
an event-to-args map for type-safe EventEmitter.on/EventEmitter.emit.

### Constructor

```typescript theme={null}
new EventEmitter()
```

### closeEmitter

```typescript theme={null}
closeEmitter(): Promise<void>
```

Close the emitter: drop all handlers and stop emitting. Waits up to 2 seconds
for in-flight async handlers to settle before returning.

### emit

```typescript theme={null}
emit(event: string, ...args: any[]): void
```

<ParamField path="event" type="string" required />

### listenerCount

```typescript theme={null}
listenerCount(event: string): number
```

<ParamField path="event" type="string" required />

<ResponseField name="returns" type="number" />

### off

```typescript theme={null}
off(event: string, handler: EventHandler): void
```

<ParamField path="event" type="string" required />

<ParamField path="handler" type="EventHandler" required />

### on

```typescript theme={null}
on(event: string, handler: EventHandler): EventHandler
```

<ParamField path="event" type="string" required />

<ParamField path="handler" type="EventHandler" required />

<ResponseField name="returns" type="EventHandler" />

### once

```typescript theme={null}
once(event: string, handler: EventHandler): EventHandler
```

<ParamField path="event" type="string" required />

<ParamField path="handler" type="EventHandler" required />

<ResponseField name="returns" type="EventHandler" />

### removeAllListeners

```typescript theme={null}
removeAllListeners(event?: string): void
```

<ParamField path="event" type="string" />

***

## MetricsOptions

Configure metrics export. See MetricsOptionsInit.

### Constructor

```typescript theme={null}
new MetricsOptions(init: MetricsOptionsInit)
```

<ParamField path="enabled" type="boolean">
  Whether metrics collection is enabled. Defaults to `true`.
</ParamField>

<ParamField path="exportUrl" type="string | null">
  OTLP endpoint to export metrics to. Defaults to `null` (no external export).
</ParamField>

<ParamField path="exportHeaders" type="Record<string, string> | null">
  Headers sent with metric exports (e.g. auth). Defaults to `null`.
</ParamField>

***

## TracesOptions

Configure distributed tracing export. See TracesOptionsInit.

### Constructor

```typescript theme={null}
new TracesOptions(init: TracesOptionsInit)
```

<ParamField path="enabled" type="boolean">
  Whether tracing is enabled. Defaults to `true`.
</ParamField>

<ParamField path="exportUrl" type="string | null">
  OTLP endpoint to export traces to. Defaults to `null` (no external export).
</ParamField>

<ParamField path="exportHeaders" type="Record<string, string> | null">
  Headers sent with trace exports (e.g. auth). Defaults to `null`.
</ParamField>

***

## LoggingOptions

Configure log export. See LoggingOptionsInit.

### Constructor

```typescript theme={null}
new LoggingOptions(init: LoggingOptionsInit)
```

<ParamField path="enabled" type="boolean">
  Whether log export is enabled. Defaults to `false`.
</ParamField>

<ParamField path="level" type="string | string[]">
  Minimum log level(s) to export (e.g. `'INFO'`). Defaults to `'INFO'`.
</ParamField>

<ParamField path="exportUrl" type="string | null">
  Endpoint to export logs to. Defaults to `null` (no external export).
</ParamField>

<ParamField path="exportHeaders" type="Record<string, string> | null">
  Headers sent with log exports (e.g. auth). Defaults to `null`.
</ParamField>

***

## ObservabilityOptions

Group tracing, metrics, and logging settings into one object. See ObservabilityOptionsInit.

### Constructor

```typescript theme={null}
new ObservabilityOptions(init: ObservabilityOptionsInit)
```

<ParamField path="traces" type="TracesOptions | null">
  Tracing settings. See TracesOptions. Defaults to `null`.
</ParamField>

<ParamField path="metrics" type="MetricsOptions | null">
  Metrics settings. See MetricsOptions. Defaults to `null`.
</ParamField>

<ParamField path="logs" type="LoggingOptions | null">
  Logging settings. See LoggingOptions. Defaults to `null`.
</ParamField>

***

## setupLogging

```typescript theme={null}
function setupLogging(level: string | number = 'INFO'): Logger
```

Configure and return the shared `zrt.agents` Logger.

<ParamField path="level" type="string | number">
  Minimum level to emit. Default: `'INFO'`.
</ParamField>

<ResponseField name="returns" type="Logger" />
