|
| 1 | +# Audit Log |
| 2 | + |
| 3 | +The audit log records every state change: who made it, when, what route was affected, and the before/after status. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## What gets recorded |
| 8 | + |
| 9 | +An entry is written whenever: |
| 10 | + |
| 11 | +- A route's status changes (maintenance on/off, enable, disable, env-gate) |
| 12 | +- A global maintenance window is activated or deactivated |
| 13 | +- A rate limit policy is created, updated, or deleted |
| 14 | +- A feature flag is created, updated, or deleted |
| 15 | +- A segment is created, updated, or deleted |
| 16 | + |
| 17 | +Each entry captures: |
| 18 | + |
| 19 | +| Field | Description | |
| 20 | +|---|---| |
| 21 | +| `path` | The route key, e.g. `GET:/payments` | |
| 22 | +| `action` | What happened, e.g. `maintenance_on`, `enable`, `disable` | |
| 23 | +| `actor` | Who made the change (`"system"` for decorator-driven changes, or a username from the CLI or dashboard) | |
| 24 | +| `platform` | Where the change came from (`"cli"`, `"dashboard"`, `"api"`, or `""`) | |
| 25 | +| `old_status` | Route status before the change | |
| 26 | +| `new_status` | Route status after the change | |
| 27 | +| `reason` | The reason string, if one was provided | |
| 28 | +| `timestamp` | UTC timestamp of the change | |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Viewing the audit log |
| 33 | + |
| 34 | +### Dashboard |
| 35 | + |
| 36 | +Open the admin dashboard and click the **Audit** tab. Filter by route path and scroll through the history. Each row shows the actor, platform, action, and timestamp. |
| 37 | + |
| 38 | +### CLI |
| 39 | + |
| 40 | +```bash |
| 41 | +# Last 20 entries across all routes |
| 42 | +waygate audit |
| 43 | + |
| 44 | +# Filter to a specific route |
| 45 | +waygate audit GET:/payments |
| 46 | + |
| 47 | +# Increase the limit |
| 48 | +waygate audit --limit 100 |
| 49 | +``` |
| 50 | + |
| 51 | +### Engine API |
| 52 | + |
| 53 | +```python |
| 54 | +# All entries (last 100 by default) |
| 55 | +entries = await engine.get_audit_log() |
| 56 | + |
| 57 | +# Filter to a specific route |
| 58 | +entries = await engine.get_audit_log(path="GET:/payments") |
| 59 | + |
| 60 | +# Increase the limit |
| 61 | +entries = await engine.get_audit_log(limit=500) |
| 62 | + |
| 63 | +for entry in entries: |
| 64 | + print(entry.timestamp, entry.actor, entry.action, entry.path) |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Reading an entry |
| 70 | + |
| 71 | +```python |
| 72 | +from waygate.core.models import AuditEntry |
| 73 | + |
| 74 | +entries = await engine.get_audit_log(path="GET:/payments") |
| 75 | +entry: AuditEntry = entries[0] |
| 76 | + |
| 77 | +print(entry.path) # "GET:/payments" |
| 78 | +print(entry.action) # "maintenance_on" |
| 79 | +print(entry.actor) # "admin" |
| 80 | +print(entry.platform) # "dashboard" |
| 81 | +print(entry.old_status) # "active" |
| 82 | +print(entry.new_status) # "maintenance" |
| 83 | +print(entry.reason) # "Database migration" |
| 84 | +print(entry.timestamp) # datetime(2025, 6, 1, 3, 0, tzinfo=UTC) |
| 85 | +``` |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Suppressing audit entries |
| 90 | + |
| 91 | +Pass `audit=False` to suppress entries for programmatic changes at startup, such as seeding flags or registering routes: |
| 92 | + |
| 93 | +```python |
| 94 | +@asynccontextmanager |
| 95 | +async def lifespan(_): |
| 96 | + await engine.save_flag(FeatureFlag(key="new-checkout", ...), audit=False) |
| 97 | + await engine.save_segment(Segment(key="beta-users", ...), audit=False) |
| 98 | + yield |
| 99 | +``` |
| 100 | + |
| 101 | +Changes made through the dashboard, CLI, or REST API always create audit entries. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## Storage |
| 106 | + |
| 107 | +Audit entries are stored in the active backend alongside route state. |
| 108 | + |
| 109 | +| Backend | Audit storage | Notes | |
| 110 | +|---|---|---| |
| 111 | +| `MemoryBackend` | In-process list | Lost on restart | |
| 112 | +| `FileBackend` | Appended to the state file | Survives restarts | |
| 113 | +| `RedisBackend` | Redis list | Shared across all workers | |
| 114 | + |
| 115 | +For long-term retention, export entries periodically to your own datastore. |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## Next step |
| 120 | + |
| 121 | +[**Tutorial: Admin Dashboard**](admin-dashboard.md) |
0 commit comments