# Observability

## Purpose

Observability records what Teddy executed and how much AI usage each provider
consumed, so admins can inspect risky actions and operating cost.

## Current Scope

- Tool audit records in `wp_teddy_audit_log`
- AI usage records in `wp_teddy_ai_usage`
- Admin page: `Teddy -> Observability`
- REST endpoints:
  - `GET /teddy/v1/audit-log`
  - `GET /teddy/v1/ai-usage`

## Main Classes

- `src/Infrastructure/Logging/WpAuditLogger.php`
- `src/Infrastructure/Logging/AuditLogRepository.php`
- `src/Infrastructure/Logging/AiUsageRepository.php`
- `src/Application/UseCase/ListAuditLog.php`
- `src/Application/UseCase/ListAiUsage.php`
- `src/Admin/ObservabilityPage.php`

## Data Captured

### Tool audit

- user id
- tool name
- trace id
- validated input payload
- output payload/error
- status
- duration
- timestamps

### AI usage

- user id
- conversation id
- provider id
- trace id
- estimated input tokens
- estimated output tokens
- estimated USD cost
- timestamp

## Notes

AI usage is currently estimated from prompt/response size when provider-native
usage details are unavailable through the current adapter layer. This is enough
for v0.2 observability, but later milestones should prefer provider-reported
usage when possible.
