Skip to content

Commit 24a1bec

Browse files
docs: add Phase 5 Logging & Monitoring to MIGRATIONS.md
1 parent 24a8574 commit 24a1bec

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

MIGRATIONS.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,72 @@ Breaking changes and upgrade notes for downstream projects.
44

55
---
66

7+
## Logging & Monitoring (2026-03-26)
8+
9+
Structured logging, audit trail, Sentry error capture, and enriched health check.
10+
11+
### New module
12+
13+
`modules/audit/` — auto-discovered, no manual registration needed.
14+
15+
### New dependencies
16+
17+
- `@sentry/node` — error tracking (no-op when unconfigured)
18+
19+
### Configuration
20+
21+
Add to your env-specific config or override via `DEVKIT_NODE_*` env vars:
22+
23+
```js
24+
// Audit log (modules/audit/config/audit.development.config.js)
25+
audit: {
26+
enabled: true, // set false to disable audit logging
27+
ttlDays: 90, // auto-purge after N days (MongoDB TTL index)
28+
}
29+
30+
// Sentry (config/defaults/development.config.js)
31+
sentry: {
32+
dsn: '', // Sentry DSN — empty = disabled
33+
environment: 'development',
34+
enabled: false,
35+
}
36+
37+
// Logging (config/defaults/development.config.js)
38+
log: {
39+
json: false, // true = structured JSON output (recommended for prod)
40+
level: 'info', // Winston log level
41+
}
42+
```
43+
44+
All features are no-op when not configured — safe to deploy without Sentry or audit.
45+
46+
### What's included
47+
48+
| Feature | File | Notes |
49+
|---------|------|-------|
50+
| Winston JSON logging | `lib/services/logger.js` | Structured JSON when `log.json: true`, configurable level |
51+
| X-Request-ID | `lib/middlewares/requestId.js` | UUID per request, `req.id` + response header |
52+
| Sentry SDK | `lib/services/sentry.js` | Error capture, no-op when DSN empty |
53+
| AuditLog model | `audit.model.mongoose.js` | TTL index, auto-purge via `audit.ttlDays` |
54+
| Audit middleware | `audit.middleware.js` | Auto-captures POST/PUT/DELETE mutations (same pattern as analytics) |
55+
| Audit API | `GET /api/audit` | Admin-only, paginated, filterable by action/userId/orgId |
56+
| Audit policy | `audit.policy.js` | CASL: admin read-only |
57+
| Health endpoint | `GET /api/health` | Public: `{ status }`, Admin (JWT): `{ status, db, uptime, version, memory }` |
58+
59+
### New MongoDB collection
60+
61+
| Collection | Model | Purpose | TTL |
62+
|------------|-------|---------|-----|
63+
| `auditlogs` | `AuditLog` | Action audit trail (who did what when) | Configurable via `audit.ttlDays` |
64+
65+
### Action for downstream
66+
67+
1. Run `/update-stack` to pull the new modules
68+
2. Set env vars if needed: `DEVKIT_NODE_sentry__dsn`, `DEVKIT_NODE_audit__ttlDays`
69+
3. No DB migration needed — collection and TTL index auto-created on first write
70+
71+
---
72+
773
## PostHog Analytics (2026-03-26)
874

975
Server-side analytics, user/org identification, API auto-capture, and feature flags via PostHog.

0 commit comments

Comments
 (0)