- php-error bridge: accept paperclip_project_id / paperclipProjectId in CrmPhpPayload and promote into event context alongside project_slug/gitea_repo - recent-errors: extract paperclip_project_id from context_json and emit as top-level field so error loop can route issues to the correct project board column without falling back to PAPERCLIP_ERROR_LOOP_PROJECT_ID_BY_SLUG - Add tests for include/omit behaviour (mirrors gitea_repo coverage) - Update ERROR_MONITORING_PUBLIC_API.md to document both optional fields No DB migration required: field is stored in existing context_json column. Co-Authored-By: Paperclip <[email protected]>
7.7 KiB
Public error-monitoring API (hub)
CRM-shaped JSON endpoints served by the Fastify API (@errors-bitreport/api). Same paths as the CRM ErrorMonitoring module where noted.
Canonical HTTP shapes + curl cookbook: docs/HTTP_CONTRACTS.md (repo root).
Operator runbooks: docs/RUNBOOK_OPERATIONS.md, docs/RUNBOOK_INGEST_DEBUG.md.
Authentication
Read (GET …/recent-errors, GET …/stats)
- Query:
api_keymust matchERROR_RESOLVE_API_KEYorERROR_REPORTING_API_KEY, or - Query:
view_errorsmust matchDEBUG_VIEW_ERRORS_KEY. - If neither server secret is set → 503.
Mutations (POST …/resolve, bulk-resolve, purge-resolved)
- Header
X-Error-Resolve-Keyor JSON body fieldapi_keymust matchERROR_RESOLVE_API_KEYorERROR_REPORTING_API_KEYwhen that secret is set, or - Admin session: HTTP-only cookie
__Host-access(JWT) with:errors:triagefor resolve and bulk-resolveerrors:deletefor purge-resolved
- If no resolve key is configured → only session auth is accepted (token-only automation is disabled).
GET /api/error-monitoring/stats
Hub operational summary (24h ingestion, severity/state counts, per-project rollups). Also refreshes Prometheus gauges on the API process (best-effort).
Auth: Same query keys as recent-errors (api_key or view_errors).
Example
curl -sS -G "${ER_API_BASE}/api/error-monitoring/stats" --data-urlencode "api_key=${ERROR_RESOLVE_API_KEY}"
GET /api/error-monitoring/recent-errors
Alias: GET /v1/paperclip/recent-errors
| Query | Description |
|---|---|
limit |
Max rows (default large cap; invalid → 400) |
offset |
Pagination offset (default 0) |
status |
Comma-separated: open, investigating, resolved, ignored (default open,investigating) |
severity |
critical | high | medium | low | info |
project_slug |
Project slug (lowercase) |
q |
Search incident title, occurrence message, or fingerprint (LIKE) |
order |
occurred_at_desc (default) or occurred_at_asc (tie-break: occurrence id) |
Response: { "success": true, "message": "ok", "data": [ … ] }
Each row includes CRM-compatible fields. For non-resolved incidents, status is always "open" (including investigating) so Paperclip error_loop continues to treat rows as open.
occurred_at: ISO-8601 timestamp of the latest occurrence returned for that incident (same row as unique_id). Used by ops scripts to verify “no new events in the last N hours” after a deploy (see repo runbook docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md §6).
stack_trace: Non-empty for every row: missing client stacks are synthesized on ingest; legacy DB rows with null/blank stack_trace get the same synthesis when serializing this endpoint (BIT-1008).
gitea_repo (optional): Gitea Owner/Repo path (e.g. BitReport.pt/WDMI) if the reporter sent gitea_repo in the error payload. Omitted when not present.
paperclip_project_id (optional): Paperclip project UUID sent by the reporter (via paperclip_project_id or paperclipProjectId payload field). When present, the Paperclip error loop uses this UUID directly to route issues to the correct project board column instead of falling back to the PAPERCLIP_ERROR_LOOP_PROJECT_ID_BY_SLUG env map. Omitted when not present.
Example
curl -sS -G "${ER_API_BASE}/api/error-monitoring/recent-errors" \
--data-urlencode "api_key=${ERROR_RESOLVE_API_KEY}" \
--data-urlencode "status=open,investigating" \
--data-urlencode "project_slug=crm" \
--data-urlencode "limit=50"
POST /api/error-monitoring/resolve
Body (JSON):
| Field | Required | Description |
|---|---|---|
unique_id |
yes | Latest occurrence id as returned in recent-errors, or incident id |
resolution_notes |
no | Stored in state history note (default message if omitted) |
assigned_to |
no | Appended to the change note for traceability |
api_key |
no | Resolve key if not using header / session |
Responses: 200 success envelope; 400 missing id; 401 auth; 404 not found or not resolvable; 503 if read keys not applicable (mutations use resolve key / session only).
Example
curl -sS -X POST "${ER_API_BASE}/api/error-monitoring/resolve" \
-H "Content-Type: application/json" \
-H "X-Error-Resolve-Key: ${ERROR_RESOLVE_API_KEY}" \
-d '{"unique_id":"12345","resolution_notes":"verified in prod"}'
POST /api/error-monitoring/bulk-resolve
Body (JSON):
| Field | Required | Description |
|---|---|---|
unique_ids |
one of | Non-empty array of numeric string ids (max 1000); maps to incidents via occurrence or incident id |
message_pattern |
one of | String or array of strings (max 20); resolves incidents with any open occurrence whose message contains the substring (LIKE %pattern%) |
resolution_notes |
no | Default bulk message if omitted |
assigned_to |
no | Appended to note |
api_key |
no | Resolve key |
If both unique_ids and message_pattern are sent, unique_ids wins (CRM behaviour).
Example (pattern)
curl -sS -X POST "${ER_API_BASE}/api/error-monitoring/bulk-resolve" \
-H "Content-Type: application/json" \
-H "X-Error-Resolve-Key: ${ERROR_RESOLVE_API_KEY}" \
-d '{"message_pattern":"Connection refused","resolution_notes":"dependency restored"}'
POST /api/error-monitoring/resolve-by-pattern
Bulk resolve incidents matching one or more advanced filters. At least one filter is required.
Body (JSON):
| Field | Required | Description |
|---|---|---|
message_pattern |
no | String or array of strings (max 20); matches occurrence message via LIKE %pattern% |
fingerprint |
no | String or array of strings (max 50); exact match on incident fingerprint |
severity |
no | String or array: critical, high, medium, low, info |
project_slug |
no | Project slug (lowercase); exact match |
from_date |
no | ISO 8601 datetime; only incidents with last_seen_at >= from_date |
to_date |
no | ISO 8601 datetime; only incidents with last_seen_at <= to_date |
resolution_notes |
no | Stored in state history (default message if omitted) |
assigned_to |
no | Appended to change note for traceability |
api_key |
no | Resolve key if not using header / session |
Response: { "success": true, "data": { "resolved": N, "matched": M } }
Auth: Same as other mutations (X-Error-Resolve-Key / body api_key / session with errors:triage).
POST /api/error-monitoring/purge-resolved
Body (JSON):
| Field | Description |
|---|---|
dry_run |
If true, returns would_delete count only |
older_than_days |
Non-negative integer; only purge resolved incidents with last_seen_at older than this many days. If omitted, purges all resolved. |
api_key |
Optional resolve key |
Effect: DELETE from er_incidents where current_state = 'resolved' (cascades occurrences and related rows per schema). All resolved incidents are removed when dry_run is false — there is no age filter in the current handler.
Example
curl -sS -X POST "${ER_API_BASE}/api/error-monitoring/purge-resolved" \
-H "Content-Type: application/json" \
-H "X-Error-Resolve-Key: ${ERROR_RESOLVE_API_KEY}" \
-d '{"dry_run":true}'
Admin UI proxy
When the Next admin UI is deployed with ERROR_REPORTING_ADMIN_API_BASE, the same paths under /api/error-monitoring/* are reverse-proxied to Fastify (see admin-ui/app/api/error-monitoring/*/route.ts).