-
Notifications
You must be signed in to change notification settings - Fork 0
feat(observability): add production telemetry #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,293
−101
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,4 +55,5 @@ ENV/ | |
|
|
||
| .cache | ||
| /screenshots | ||
| /logs | ||
| /src/generated | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # Observability | ||
|
|
||
| Life@USTC exposes production-safe structured logs and bounded Prometheus-style | ||
| runtime metrics. Logs and metrics must not include bearer tokens, cookies, OAuth | ||
| codes, request bodies, raw query strings, upload object keys, signed URLs, or | ||
| high-cardinality resource IDs. | ||
|
|
||
| ## Log Storage | ||
|
|
||
| Structured app logs are always emitted to the app process stdout/stderr. When | ||
| `APP_LOG_DIR` is configured, server-side logs are also appended as JSON Lines to | ||
| `APP_LOG_DIR/app-YYYY-MM-DD.log`. | ||
|
|
||
| Docker Compose sets `APP_LOG_DIR=/var/log/life-ustc` and mounts | ||
| `APP_LOG_HOST_DIR` there: | ||
|
|
||
| - production default: `./logs/app` | ||
| - Docker dev default: `./logs/app-dev` | ||
|
|
||
| Create the host directory before starting Compose and make it writable by the | ||
| container user. If Docker auto-creates the bind mount as root and the app cannot | ||
| write to it, stdout/stderr logging still works and the app emits one | ||
| `app.log_file_write_failed` message. | ||
|
|
||
| Caddy access logs remain separate from the app log file. | ||
|
|
||
| ## Request Tracing | ||
|
|
||
| - Caddy access logs remain the edge source of truth for every HTTP request. | ||
| - Next.js REST routes propagate `x-request-id` and `x-request-start-ms`. | ||
| - REST route logs use normalized route templates such as `/api/todos/:id`. | ||
| - MCP transport logs include JSON-RPC method summaries, tool names, argument | ||
| keys, status, duration, and registered tool count. | ||
|
|
||
| ## Metrics | ||
|
|
||
| Runtime metrics are exposed as Prometheus text at `/api/metrics`. The endpoint | ||
| is readable from localhost or with `METRICS_BEARER_TOKEN`. | ||
|
|
||
| REST: | ||
|
|
||
| - `life_ustc_api_requests_started_total{method,route}` | ||
| - `life_ustc_api_requests_total{auth_mode,method,route,status}` | ||
| - `life_ustc_api_request_duration_ms_count{method,route}` | ||
| - `life_ustc_api_request_duration_ms_sum{method,route}` | ||
| - `life_ustc_api_errors_total{method,route,status}` | ||
|
|
||
| MCP: | ||
|
|
||
| - `life_ustc_mcp_http_requests_total{method,phase,status}` | ||
| - `life_ustc_mcp_http_request_duration_ms_count{method,phase}` | ||
| - `life_ustc_mcp_http_request_duration_ms_sum{method,phase}` | ||
| - `life_ustc_mcp_jsonrpc_requests_total{rpc_method}` | ||
| - `life_ustc_mcp_tool_calls_total{tool}` | ||
| - `life_ustc_mcp_tool_call_results_total{status,tool}` | ||
| - `life_ustc_mcp_tool_call_duration_ms_count{tool}` | ||
| - `life_ustc_mcp_tool_call_duration_ms_sum{tool}` | ||
|
|
||
| OAuth, audit, and storage: | ||
|
|
||
| - `life_ustc_oauth_token_requests_total{grant_type,has_resource,status}` | ||
| - `life_ustc_oauth_token_request_duration_ms_count{grant_type,has_resource}` | ||
| - `life_ustc_oauth_token_request_duration_ms_sum{grant_type,has_resource}` | ||
| - `life_ustc_audit_writes_total{action,status}` | ||
| - `life_ustc_audit_write_duration_ms_count{action}` | ||
| - `life_ustc_audit_write_duration_ms_sum{action}` | ||
| - `life_ustc_storage_operations_total{operation,status}` | ||
| - `life_ustc_storage_operation_duration_ms_count{operation}` | ||
| - `life_ustc_storage_operation_duration_ms_sum{operation}` | ||
|
|
||
| ## Readiness | ||
|
|
||
| `/api/readiness` returns internal dependency status for DB reachability, storage | ||
| configuration, and process uptime. It is readable from localhost, with | ||
| `READINESS_BEARER_TOKEN`, or with `METRICS_BEARER_TOKEN`. | ||
|
|
||
| Use readiness for operator diagnostics. Keep Docker health checks shallow so a | ||
| transient dependency issue does not restart an otherwise healthy process. | ||
|
|
||
| ## Alerts | ||
|
|
||
| Recommended critical alerts: | ||
|
|
||
| - Public blackbox probe failure for `https://life-ustc.tiankaima.dev`. | ||
| - App container unhealthy or restarting. | ||
| - Sustained REST 5xx rate from `life_ustc_api_errors_total`. | ||
| - Caddy upstream `502` or `504` spike. | ||
| - Database readiness failure. | ||
| - Disk usage above 85%. | ||
|
|
||
| Recommended warning alerts: | ||
|
|
||
| - REST or MCP latency regression from duration sum/count metrics. | ||
| - OAuth token failure spike. | ||
| - MCP auth rejection spike. | ||
| - Storage operation error spike. | ||
| - Audit write error spike. | ||
| - Memory pressure or sustained swap growth. | ||
|
|
||
| ## Dashboards | ||
|
|
||
| At minimum, Grafana should show: | ||
|
|
||
| - REST request rate, status class, top routes, and average latency. | ||
| - MCP HTTP phases, JSON-RPC methods, tool calls, tool failures, and latency. | ||
| - OAuth token requests by grant type/status. | ||
| - Audit write success/error counts. | ||
| - Storage operation success/error counts and latency. | ||
| - Host CPU, memory, swap, disk, and container restart state. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.