git:20261114.b353ad0 to git:20261114.1296d8c

99 added, 56 removed. Audit A to A.

What this update changes in the checks

No check changed: every fixed check gives the same answer before and after this update.

A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.

---
name: monitoring-game-ops
description: >-
- Use when implementing game monitoring, structured logging, player telemetry, alerting rules, or performance budgets. Triggers: monitoring, logging, telemetry, alerts, observability, metrics.
+ Structured logs, server health signals and alert rules for a live
+ multiplayer game server: tick time against the tick budget, room and
+ WebSocket connection counts, disconnects, errors per game mode and message
+ type, failed jobs and currency flow. Use when a game server needs logging, a
+ health dashboard or alerts, when players report lag or drops and you need to
+ see why, or when a release needs post-deploy checks; the code targets Bun
+ and Elysia.
---
- # Monitoring & Game Ops
+ # Monitoring Game Ops
- ## Purpose
+ A game server needs two outputs. Log lines answer "what happened to this
+ player in this room". Metrics answer "is the server healthy right now".
+ Player behaviour (DAU, session length, D1/D7/D30 retention, funnels) is
+ analytics, not ops: use `gameplay-analytics` for it.
- Structured logging, player telemetry, alerting, and performance budgets for game servers.
+ ## Files
- ## When to Use
+ - `boilerplate/logger.ts`: copy when the server needs structured logs. It has
+ `GameLogger` (JSON lines, child loggers that carry `playerId`, `sessionId`,
+ `roomId`), the `requestLogger` Elysia plugin, and `createSessionLogger` for
+ WebSocket connections.
+ - `templates/alert-config.ts`: copy when you define metrics and alerts. It
+ names the game signals, the `AlertRule` shape, and three rule builders
+ (tick overrun, capacity, baseline). None of them has a default threshold.
+ - `references/sources.md`: read when you need the source behind a rule here.
- Trigger: monitoring, logging, telemetry, alerting, performance, metrics, observability, error tracking, player analytics, server health, uptime
+ ## Logging
- ## Prerequisites
+ - One JSON object per line, written to stdout/stderr. Fields: `level`,
+ `message`, `timestamp`, `context` (`service`, `component`, `playerId`,
+ `sessionId`, `roomId`, `requestId`), `data`, `error`.
+ - Per-request values (request id, start time) come from `.derive()`, never
+ from `store`. Elysia's `store` is one global object for the whole app, so
+ concurrent requests overwrite each other's values. `derive` runs once per
+ request, and its values are not shared with other requests.
+ - Register `requestLogger` before the routes it should log. Elysia hooks
+ apply only to routes registered after them.
+ - A request with no matching route, or a body that does not parse, fails
+ before `derive` runs. Those lines carry no `requestId`. The plugin logs
+ them, and validation failures, as `warn` `request_rejected`, so the error
+ rate counts server faults only.
+ - A validation failure logs the target (`body`, `query`...), the property
+ path and the schema rule it broke, never the rejected value. Elysia's
+ `error.message` and its summary both include the input, and a login body
+ holds a password.
+ - Create one session logger per WebSocket connection and pass it to the room.
+ Every line from that player's messages then carries the player, session and
+ room.
+ - Do not log per entity per tick. Line volume multiplies by the tick rate and
+ the room count. Count per-tick work in metrics; log state changes (player
+ joined, match ended, tick overrun).
- - `game-backend-architecture` — what we're monitoring
- - `redis-game-patterns` — metrics storage
+ ## Health signals
- ## Core Principles
+ `templates/alert-config.ts` defines these names. Record durations as
+ histograms, never as averages: a mean hides the slow tail, and the tail is
+ what players feel as lag.
- 1. **Structured logging** — JSON logs with consistent fields; never unstructured console.log in production
- 2. **Player telemetry** — track actions, session length, retention, spending — anonymized
- 3. **Alert on anomalies** — sudden drops in DAU, spike in errors, economy inflation
- 4. **Performance budgets** — server tick must complete in < 16ms (60fps); API responses < 200ms p95
- 5. **Dashboard first** — if you can't see it, you can't fix it
+ | Signal | Instrument | Where the threshold comes from |
+ |--------|-----------|--------------------------------|
+ | `game.tick.duration` (p99) | histogram, seconds | Tick budget: `1 / tickRate` times a headroom fraction. Tick rate from `game-backend-architecture`. |
+ | `game.tick.overruns` | counter | Ticks that took longer than the interval. A sustained count means rooms fall behind. |
+ | `game.rooms.active`, `game.ws.connections` | up-down counter | A load test of one server (see below). |
+ | `game.ws.closes` by `code` | counter | Baseline per close code. |
+ | `game.messages.errors` by `mode`, `messageType` | counter | Baseline rate. |
+ | `game.matchmaking.wait` (p95) | histogram, seconds | Baseline per mode. The queue design is in `matchmaking-system`. |
+ | `game.jobs.failed` by `queue` | counter | Baseline. Count failed and stalled jobs from the queue events in `bullmq-game-queues`. |
+ | `game.currency.minted`, `game.currency.spent` | counter | The sink and faucet targets in `game-economy-design`. |
- ## Key Metrics
+ - Error rate per room: put `roomId` in the log context and query the logs.
+ Do not make `roomId`, `playerId` or `sessionId` a metric label: each value
+ becomes its own time series.
+ - WebSocket close code 1006 means the connection closed abnormally, without
+ a Close frame; Bun's `close` handler reports 1006 when the client process
+ dies. 1000 is a normal close; 1001 is a page navigating away or a server
+ going down. Alert on a rise in 1006, not on total closes.
- | Category | Metric | Target | Alert Threshold |
- |----------|--------|--------|----------------|
- | Server | Tick time (p95) | < 16ms | > 50ms |
- | Server | API response (p95) | < 200ms | > 500ms |
- | Server | WebSocket connections | N/A | > 80% capacity |
- | Server | Error rate | < 0.1% | > 1% |
- | Player | DAU | Trending up | -20% day-over-day |
- | Player | Session length (median) | 10-30 min | < 5 min |
- | Player | Day 1 retention | > 40% | < 25% |
- | Player | Day 7 retention | > 15% | < 8% |
- | Economy | Currency in circulation | Stable | +50% week-over-week |
- | Economy | Revenue per DAU | Stable | -30% week-over-week |
+ ## Setting thresholds
- ## Log Schema
+ 1. Tick: compute the interval from the tick rate. Profile a full room and
+ pick the headroom fraction from that profile. A tick that uses the whole
+ interval falls behind under the first spike, so the alert must fire below
+ the interval. `tickOverrunRule` takes both values.
+ 2. Capacity: load-test one server with bots until tick p99 crosses the
+ budget. That room and connection count is the measured limit.
+ `capacityRule` fires at a fraction of it that you choose.
+ 3. Everything else: measure a baseline over normal play, including a peak
+ hour and a quiet hour, then set a factor with `baselineRule`. Tighten or
+ loosen it after the first false alert.
+ 4. Route: page only for a problem players feel now that a person can act on.
+ Everything else is a ticket. Every rule has a `runbook` line saying what
+ the responder does first.
- ```typescript
- interface GameLogEntry {
- timestamp: string; // ISO 8601
- level: 'debug' | 'info' | 'warn' | 'error';
- service: string; // 'game-server' | 'api' | 'worker'
- event: string; // 'player.login' | 'combat.resolved' | 'purchase.completed'
- playerId?: string;
- sessionId?: string;
- data: Record<string, unknown>;
- duration?: number; // ms, for timed operations
- error?: {
- message: string;
- stack?: string;
- code?: string;
- };
- }
- ```
+ ## Pitfalls
- ## Cross-References
+ - Request id or start time in `store`: wrong ids and durations under load.
+ - Average tick time: looks fine while a few rooms stutter. Use p99
+ and the overrun counter.
+ - 404s and bad payloads logged as errors: the error rate rises with every
+ scanner bot. Keep them at `warn`.
+ - Alerts on DAU or retention from the ops stack: those move by day, not by
+ minute. They belong in `gameplay-analytics`.
+ - Thresholds copied from another game: tick rate, room size and message rate
+ differ. Measure your own.
- - `game-backend-architecture` — server topology to monitor
- - `redis-game-patterns` — real-time metrics storage
- - `bullmq-game-queues` — queue health monitoring
- - `stripe-game-payments` — revenue tracking
- - `ci-cd-game` — post-deployment monitoring
+ ## Post-deploy check
- ## Sources
+ - [ ] Tick p99 and overruns per mode match the previous release at the first
+ peak after deploy.
+ - [ ] 1006 closes did not rise.
+ - [ ] No new `messageType` appears in `game.messages.errors`.
+ - [ ] No rise in failed or stalled jobs.
+ - [ ] Currency minted against spent stays inside the `game-economy-design`
+ targets.
- - "Game Server Monitoring at Scale" — GDC 2020
- - "Player Telemetry Best Practices" — GDC 2019
- - OpenTelemetry documentation
+ `ci-cd-game` runs the deploy; this list is what to look at afterwards.