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

# Exporters

> Stream audit events to your observability stack

plyra-guard emits an audit event for every decision — allowed and blocked.
Events go to one or more exporters.

<div style={{margin: '32px 0', borderRadius: '8px', overflow: 'hidden', border: '1px solid #1e2a38'}}>
  <img src="https://mintcdn.com/plyra/Lg9SA-tSj-CaqUyK/images/guard-exporters.svg?fit=max&auto=format&n=Lg9SA-tSj-CaqUyK&q=85&s=8ccdeab902daa640146057f0bdb8c43d" alt="Plyra Guard Exporters" style={{width:'100%', background:'#0d1117'}} width="720" height="260" data-path="images/guard-exporters.svg" />
</div>

plyra-guard emits an audit event for every decision — allowed and blocked.
Events go to one or more exporters.

<Note>
  `StdoutExporter` is always enabled by default. It writes JSON lines to
  stdout on every action. In production, disable it to avoid log noise by
  setting `observability.exporters: []` in your YAML config.
</Note>

## StdoutExporter (default)

Writes audit entries as JSON lines to stdout. Enabled by default when
`"stdout"` is in the `observability.exporters` list.

```python theme={null}
from plyra_guard import StdoutExporter

exporter = StdoutExporter(pretty=True)  # pretty-prints JSON
guard.add_exporter(exporter)
```

To disable in your config:

```yaml theme={null}
observability:
  exporters: []
```

### Constructor

| Parameter | Type             | Default      | Description              |
| --------- | ---------------- | ------------ | ------------------------ |
| `stream`  | `object \| None` | `sys.stdout` | Output stream            |
| `pretty`  | `bool`           | `False`      | Pretty-print JSON output |

## OTelExporter

Exports audit entries as OpenTelemetry spans.

```bash theme={null}
pip install "plyra-guard[otel]"
```

```python theme={null}
from plyra_guard.observability.exporters import OTelExporter

guard.add_exporter(OTelExporter(service_name="my-agent"))
```

### Constructor

| Parameter      | Type  | Default         | Description                 |
| -------------- | ----- | --------------- | --------------------------- |
| `service_name` | `str` | `"plyra_guard"` | OTel service name for spans |

## DatadogExporter

Exports audit entries as Datadog spans via `ddtrace`.

```bash theme={null}
pip install "plyra-guard[datadog]"
```

```python theme={null}
from plyra_guard.observability.exporters import DatadogExporter

guard.add_exporter(DatadogExporter(service_name="my-agent"))
```

### Constructor

| Parameter      | Type  | Default         | Description                    |
| -------------- | ----- | --------------- | ------------------------------ |
| `service_name` | `str` | `"plyra_guard"` | Datadog service name for spans |

## WebhookExporter

POSTs audit entries as JSON to an arbitrary URL. Useful for Slack, PagerDuty,
or custom dashboards.

```python theme={null}
from plyra_guard.observability.exporters import WebhookExporter

guard.add_exporter(WebhookExporter(
    url="https://hooks.slack.com/services/...",
    headers={"Authorization": "Bearer token"},
    timeout=10,
))
```

### Constructor

| Parameter | Type                     | Default | Description                |
| --------- | ------------------------ | ------- | -------------------------- |
| `url`     | `str`                    | —       | Webhook URL to POST to     |
| `headers` | `dict[str, str] \| None` | `None`  | Extra HTTP headers         |
| `timeout` | `int`                    | `10`    | Request timeout in seconds |

## Combining exporters

```python theme={null}
from plyra_guard.observability.exporters import (
    OTelExporter,
    DatadogExporter,
    WebhookExporter,
)

guard.add_exporter(OTelExporter())
guard.add_exporter(DatadogExporter())
guard.add_exporter(WebhookExporter(url="https://..."))
```

## Snapshot database

All decisions are written to `~/.plyra/snapshots.db` (SQLite).
Change the path via environment variable:

```bash theme={null}
export PLYRA_SNAPSHOT_PATH=/your/path/snapshots.db
```

Or in your YAML config:

```yaml theme={null}
rollback:
  snapshot_dir: /your/path/
```
