Commit Graph
38 Commits
Author SHA1 Message Date
David Santos bd6e3805ec fix(ingest): non-empty stack_trace for hub occurrences (BIT-796)
Accept stack_trace as an alias for stacktrace. When both are absent, store a
synthesized stack line derived from context so recent-errors always exposes
dedupe-friendly text. Fingerprints still ignore synthesized stacks so grouping
matches legacy omit-stack payloads.

PHP ingest client: fatal shutdown handler now sends a minimal stack line.

Paperclip-Agent: David Santos (id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-796
Paperclip-Run: 7f4a8c69-7b5b-47f2-9fc9-c99e6d57f2d2
Made-with: Cursor
2026-04-04 18:26:15 +00:00
David Santos b41f17886a chore(deploy): include Apr 2026 ingest migrations in LXC run-migrate
Add occurred_at stats and ingest key rate limit SQL to deploy/lxc/run-migrate.sh
so fresh and repeat LXC installs match docker-migrate ordering (BIT-771).

Paperclip-Agent: Tiago Neves (urlKey tiago-neves; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-771
Paperclip-Run: 9d930ca7-5aba-4b1b-906c-80677815557c
Made-with: Cursor
2026-04-04 01:03:10 +00:00
Peter Spark 0d2bd5eb95 feat: add Node.js and PHP error reporter client libraries (BIT-750)
Lightweight drop-in clients for sending errors to the ingest API:
- clients/node/errorReporter.mjs (ESM) and .cjs (CommonJS)
- clients/php/ErrorReporter.php (PHP 8+)

Both use Bearer auth against /v1/ingest/events, fire-and-forget,
zero external dependencies.

Paperclip-Agent: peter-spark
Paperclip-Issue: BIT-750
Paperclip-Run: c2c29aef-e79f-4e69-98ed-3353d04b7a6d
2026-04-04 00:18:52 +00:00
Peter Spark 3b175eec86 fix(admin-ui): proxy ingest API through Next.js rewrites (BIT-750)
The single-domain deployment (errors.bitreport.pt) routed all traffic
through the admin-ui, whose auth middleware redirected /v1/ingest/events
and /health to /login — making the ingest API unreachable from outside.

- middleware.ts: pass through /v1/* and /health without auth redirect
- next.config.ts: rewrite /v1/* and /health to ingest-api backend
  (INGEST_API_URL env, default http://127.0.0.1:3041)
- docker-compose.yml: set INGEST_API_URL=http://ingest-api:3041
- env examples: document INGEST_API_URL
- scripts/onboard-project.sh: generate project + ingest key SQL

Paperclip-Agent: peter-spark
Paperclip-Issue: BIT-750
Paperclip-Run: dc5b7949-b24d-4867-a2cd-cf4f47477ef8
2026-04-03 10:01:55 +00:00
Peter Spark c8adcac393 merge: BIT-736 operational tooling — HTTP contracts, runbooks, Prometheus docs
Paperclip-Issue: BIT-736
2026-04-02 21:41:44 +00:00
Peter Spark 8767e40bb6 docs(ops): hub parity tooling — HTTP contracts, runbooks, Prometheus
Add canonical HTTP_CONTRACTS with curl for hub + ingest endpoints, operator
runbooks for ingest debugging and five common hub flows, and Grafana/Prometheus
scraping notes. Extend ERROR_MONITORING_PUBLIC_API with stats + curl examples;
align purge and resolve-by-pattern docs with the Fastify implementation.
Add optional smoke scripts under scripts/examples/.

Paperclip-Agent: 5d084b36-f38f-42a5-a92a-520005afda4f
Paperclip-Issue: BIT-736
Paperclip-Run: ad2c5129-df54-44aa-afd4-6f9f7486c1a1
Made-with: Cursor
2026-04-02 20:36:57 +00:00
spark ae9fb2a20b Merge pull request 'feat(ingest-api): ingestion hardening — fingerprints, per-key rate limits (BIT-735)' (#2) from task/BIT-735-ingest-hardening into master
Reviewed-on: #2
2026-04-02 20:47:57 +01:00
Peter Spark f5f62571fd feat(ingest-api): ingestion hardening — fingerprints, per-key rate limits (BIT-735)
- Migration: er_ingest_keys.rate_limit_max and rate_limit_window_ms (nullable overrides).
- Fingerprint policy v2: server-side digest includes normalized stacktrace (UUID/hex/line noise).
- In-memory fixed-window limits: per API key after auth; per-IP for unauthenticated POSTs
  (INGEST_ANON_IP_*). Removed @fastify/rate-limit dependency.
- OpenAPI documents 429; runbook at docs/operations/ingest-hardening-runbook.md.

Paperclip-Agent: 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376
Paperclip-Issue: BIT-735
Paperclip-Run: 0a91be22-6f8f-4c60-b889-44b99048d3a2
Made-with: Cursor
2026-04-02 19:45:27 +00:00
Peter Spark acac2ba034 merge: BIT-734 operational observability (stats, Prometheus, SLO, Grafana)
Paperclip-Issue: BIT-734
2026-04-02 19:41:23 +00:00
Peter Spark c6e4305c79 feat(observability): stats endpoint, Prometheus metrics, SLO tracking, Grafana dashboard (BIT-734)
- GET /api/error-monitoring/stats: 24h ingestion volume, severity
  distribution, per-project metrics with resolution rates, hourly trend
- Prometheus /metrics on both api (port 3200) and ingest-api (port 3041)
  with HTTP request duration histograms, ingest SLO latency (p50/p95/p99),
  event throughput counters, domain gauges
- Grafana dashboard JSON (deploy/grafana/) with SLO panels, error volume,
  severity/state distribution, per-project charts, Node.js process metrics
- SLO runbook (docs/RUNBOOK_SLO.md): alert rules, scrape config,
  triage procedures for latency, error rate, and availability breaches

Paperclip-Agent: Peter Spark (urlKey peter-spark; id 49ce66f8-6be6-4644-afd3-eb6d8d0d4b3e)
Paperclip-Issue: BIT-734
Paperclip-Run: f45bcdc4-4757-4829-8e75-b60a8f9a7be4
2026-04-02 18:26:24 +00:00
spark a0f305300a Merge pull request 'feat(api): resolve-by-pattern endpoint, purge threshold, contract tests (BIT-732)' (#1) from task/BIT-732-mutation-api-parity into master
Reviewed-on: #1
2026-04-02 19:22:06 +01:00
Peter Spark dee670ef9f feat(api): resolve-by-pattern endpoint, purge threshold, contract tests (BIT-732)
Add POST /api/error-monitoring/resolve-by-pattern with advanced filters:
severity, project_slug, fingerprint, message_pattern, time range.

Enhance purge-resolved with optional older_than_days threshold so only
stale resolved incidents are deleted.

27 contract tests (vitest) cover all four mutation endpoints: auth gating,
validation, response shapes, and CRM-compatible behaviour.

Paperclip-Agent: peter-spark
Paperclip-Issue: BIT-732
Paperclip-Run: 749dfb41-182b-48c8-b6e7-74f14bdb9d41
2026-04-02 18:16:01 +00:00
David Santos 5c97326d11 feat(ops): tooling CLI + runbook canónico de triagem
- scripts/er-cli.sh: CLI operacional sem UI com comandos list-open,
  export, resolve, resolve-by-pattern e purge; idempotente, dry-run
  em resolve-by-pattern e purge, autenticação via ERROR_RESOLVE_API_KEY
- docs/RUNBOOK_TRIAGE.md: runbook completo de triagem, resolução, deploy
  e fecho com checklist de validação pós-deploy e tabela de escalada

Paperclip-Issue: BIT-730
Paperclip-Run: f06292f3-5ab7-4715-9b61-6dee07a47ad7
2026-04-02 18:03:23 +00:00
David Santos de68f68103 feat(admin): operational stats — hourly trends, recurrence, dashboard
Extend GET /v1/stats/trend with granularity=hour (UTC buckets) and granularity=day
response envelope. Enrich GET /v1/stats/summary per-project totals and critical
counts. Add GET /v1/stats/recurrence for top incidents by occurrence volume in
a sliding window. Add index on er_incident_occurrences(occurred_at) for range
queries. Wire admin dashboard to summary, 24h/14d trends, and recurrence table.
Document contract in docs/ADMIN_STATS_API.md.

Paperclip-Agent: Pedro Alves (urlKey pedro-alves; id d706f4e6-5d05-4cec-b6e8-f8fb1f203aae)
Paperclip-Issue: BIT-728
Paperclip-Run: 948904bb-20d7-4d29-9cd7-4c22544f7570
Made-with: Cursor
2026-04-02 11:00:51 +00:00
David Santos c4e0b03ed8 ingest-api: versioned noise rules and CRM-style fingerprint normalization
- Add NOISE_RULESET_VERSION 1.0.0 with CRM/WDMI parity (external resource,
  ResizeObserver, WDMI media prefix, stale-bundle and transient JS strings).
- Skip ingest for matched noise; never suppress when level maps to critical.
- FINGERPRINT_POLICY_VERSION 1: NFKC/whitespace-normalized first line plus
  project_slug|message|file|line basis (SHA-256) when client omits fingerprint.
- Response includes noise_filtered_count and policy version fields; OpenAPI
  documents stored vs skipped result shapes.

Paperclip-Issue: BIT-727
Paperclip-Run-Id: ae412312-f71a-4efd-93e0-ca7289c93362
Made-with: Cursor
2026-04-02 10:55:11 +00:00
David Santos 7b2be679cd feat(api): harden error-monitoring mutations (audit, rate limit, 403)
Document the public CRM-shaped API matrix, emit audit rows for resolve,
bulk-resolve, and purge (including dry run), apply a dedicated per-IP
rate limit on mutation routes, and return 403 when a valid session lacks
RBAC for the action. Add Vitest coverage for authorizeMutation.

Paperclip-Agent: Tiago Neves (urlKey tiago-neves; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-731
Paperclip-Run: 7d0edfac-5676-41fa-85c2-86d01a808894
Made-with: Cursor
2026-04-02 10:52:40 +00:00
David Santos 8b0044be82 feat(api): CRM parity mutations and recent-errors filters (BIT-726)
Add POST /api/error-monitoring/resolve, bulk-resolve, and purge-resolved with
resolve key or admin JWT (errors:triage / errors:delete). Extend GET
recent-errors with status, severity, project_slug, q, offset, and stable
ordering. Document contracts in api/docs/ERROR_MONITORING_PUBLIC_API.md;
add vitest for public auth helpers. Proxy new routes and widen admin-ui
middleware for /api/error-monitoring/*.

Paperclip-Issue: BIT-726
Paperclip-Run: 3fbf92be-736e-4b11-8e90-cf993d8cd5ca
Paperclip-Agent: Pedro Alves (id d706f4e6-5d05-4cec-b6e8-f8fb1f203aae)
Made-with: Cursor
2026-04-02 10:50:06 +00:00
David Santos e0af92eda1 fix(admin-ui): allow public recent-errors API path without login redirect
Keep /api/error-monitoring/recent-errors reachable for Paperclip error loop (including path variants) so central hub returns JSON instead of 307 /login.
2026-04-02 08:50:21 +00:00
David Santos bc8bd8707f feat(api): expose CRM-shaped GET /api/error-monitoring/recent-errors on Fastify
Register the same handler as /v1/paperclip/recent-errors so NPM and direct
API probes (e.g. :3200) match Paperclip default PAPERCLIP_ERROR_API_QUERY.
Admin UI proxy now calls the Fastify path for a single contract end-to-end.

Paperclip-Agent: David Santos (urlKey david-santos; id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-702
Paperclip-Run: 4ba525c4-3929-475c-a845-400c49eda817
Made-with: Cursor
2026-04-01 16:28:43 +00:00
David Santos 6811dba303 Expose recent-errors for Paperclip via api_key (BIT-684)
Add Fastify GET /v1/paperclip/recent-errors returning CRM-compatible JSON (data
envelope, project_slug per row, status open for open/investigating incidents).

Admin UI proxies the public path /api/error-monitoring/recent-errors to the API
base; middleware bypasses the session redirect for that path only.

Auth matches CRM env names: ERROR_RESOLVE_API_KEY or ERROR_REPORTING_API_KEY for
?api_key=, DEBUG_VIEW_ERRORS_KEY for ?view_errors=.

Paperclip-Agent: David Santos (urlKey david-santos; id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-684
Paperclip-Run: cf7cb964-6953-4476-af09-3feb5d10da17
Made-with: Cursor
2026-04-01 14:18:00 +00:00
1sonhador c899cef6e1 fix(admin-ui): SSR sees ERROR_REPORTING_ADMIN_API_BASE at runtime
Next build inlines bare process.env.* as undefined without .env at build time.
Use Reflect.get for admin API base and demo flag; add .env.production default for LXC.
2026-03-29 21:20:19 +01:00
1sonhador 0a8918ed00 chore(api): add admin stats routes source (required by index register) 2026-03-29 21:17:55 +01:00
1sonhador 988f9b8987 feat(api): register GET /v1/incidents and detail; wire stats routes
Admin UI SSR calls /v1/incidents; routes were missing (404). Add incidents list/detail with errors:read and register admin stats routes in index.
2026-03-29 21:17:48 +01:00
1sonhador a3b65b4b3f chore(admin-ui): generic login copy; trim infra hints in comments and .env.example 2026-03-29 18:35:53 +01:00
1sonhador 83308b465b fix(admin-ui): middleware login gate; add admin API systemd unit
- Middleware: require development+demo or SKIP_LOGIN for unauthenticated access.
- Document SKIP_LOGIN and stricter demo in .env.example.
- Ship bitreport-error-reporting-api.service (PORT via ExecStart env; shared env has PORT for ingest).
2026-03-29 18:32:05 +01:00
1sonhador c02c300dc3 feat(deploy): version.json generation, webhook promote, verify (BIT-468)
Align LXC deploy with BIT-465: write-version-json.sh, optional
webhook-deploy.sh, verify.sh fails when ER_VERSION_JSON_PATH is set but
missing/invalid, env.example + nginx sketch + runbook updates.
Ignore deploy/lxc/runtime/ (generated on server).
2026-03-24 18:33:37 +00:00
1sonhadorandPaperclip e17acc983c fix(admin-ui): require session for dashboard in production (BIT-403)
- Add middleware redirecting unauthenticated users to /login unless dev+demo
- Disable demo incident data when NODE_ENV=production
- Forward __Host-access cookie on SSR fetches to admin API
- Document NPM /admin/ proxy to Fastify api (§14.2.2)

Co-Authored-By: Paperclip <[email protected]>
2026-03-23 23:00:20 +00:00
1sonhadorandPaperclip e3a7efc1a3 docs(NPM): domain without :3040 needs no path rewrite; forward + headers
Co-Authored-By: Paperclip <[email protected]>
2026-03-23 21:26:10 +00:00
1sonhadorandPaperclip 4a32bb3b0c fix(admin-ui): force-dynamic routes so DEMO/API env is not CDN-cached stale
Co-Authored-By: Paperclip <[email protected]>
2026-03-23 21:13:46 +00:00
1sonhadorandPaperclip b95aee6f85 deploy(lxc): systemd After=mariadb (not postgresql); note Gitea clone on CT
Co-Authored-By: Paperclip <[email protected]>
2026-03-23 21:10:52 +00:00
1sonhadorandPaperclip ff11f79acb docs(compose): admin-ui port 3040 verify + troubleshooting when host not redeployed
Co-Authored-By: Paperclip <[email protected]>
2026-03-23 20:56:50 +00:00
1sonhadorandPaperclip 563f644861 compose: add admin-ui service on port 3040 (Next standalone)
Expose Velzon admin dashboard in docker-compose with ERROR_REPORTING_UI_DEMO=1
by default until admin API serves /v1/incidents. Document env vars in .env.example.

Co-Authored-By: Paperclip <[email protected]>
2026-03-23 19:50:30 +00:00
1sonhadorandPaperclip a9d85a2fec fix: use regular unique index for MariaDB 10.6 compat (BIT-277)
MariaDB 10.6 does not support functional indexes. Replace the
LOWER(email) functional index with a plain unique index on email;
case-insensitive uniqueness is enforced at the application layer.

Paperclip-Agent: DevOps Engineer (urlKey devops-engineer; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-277
Paperclip-Run: 7cc9257b-0d1a-475b-9133-8d0aa78d0f08

Co-Authored-By: Paperclip <[email protected]>
2026-03-23 16:26:19 +00:00
1sonhadorandPaperclip 09eef93b34 docs(deployment): add public NPM/DNS/Cloudflare runbook for LXC (BIT-277)
Document Nginx Proxy Manager (CT 102), DNS for errors.bitreport.pt and
ingest.errors.bitreport.pt, Cloudflare 525 troubleshooting, and external
verification curls alongside existing verify.sh checks.

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 23:33:56 +00:00
1sonhadorandPaperclip 4604606033 feat(errors): migrate error-reporting stack from PostgreSQL to MariaDB (BIT-255)
Replace Postgres with MariaDB 11 in docker-compose; convert all
database/error_reporting and db/migrations SQL to InnoDB-friendly syntax
(DATETIME(6), AUTO_INCREMENT, ON DUPLICATE KEY). Run admin portal DDL in the
same migrate one-shot as error_reporting.

Switch ingest-api, collector-worker, and api from pg to mysql2 (pools,
parameterized queries, transactions). Align ingest writes with
er_incident_occurrences and include project_id on idempotency inserts.

Add scripts/run-mysql-migrations.sh for host-side applies; update LXC
run-migrate/verify, deployment docs, and .env.example (mysql://, ER_MYSQL_*).

Verified: npm run build + npm test in ingest-api and collector-worker;
npm run build in api. Full docker compose not run here (no local daemon).

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 19:29:11 +00:00
1sonhadorandPaperclip b0b733d5e1 feat(BIT-247): consolidate error reporting repo from OTT
Merge ingest-api, collector-worker, admin-ui, database/error_reporting, deploy/lxc,
docker-compose, and deployment docs into the dedicated repository. Paths updated
for repo root (ER_REPO_ROOT, systemd WorkingDirectory). Root README documents layout.

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 18:20:27 +00:00
1sonhadorandPaperclip eeb5039a3c feat(BIT-183): admin auth, RBAC, audit logging, rate limiting
Implements BIT-154.7 — Auth administrativa, RBAC e quotas:

- api/src/types/auth.ts: 3 roles (superadmin/admin/viewer), 18 permissions,
  ROLE_PERMISSIONS map as single source of truth
- api/src/plugins/auth.ts: JWT via HTTP-only __Host- cookies (15min access /
  7d refresh), token rotation, timing-safe login
- api/src/plugins/rbac.ts: requirePermission() + requireRole() Fastify
  decorators for route-level enforcement
- api/src/plugins/audit.ts: auditLog() helper + Fastify plugin; writes to
  audit_logs table; failure never aborts main operation
- api/src/plugins/rate-limit.ts: per-route limits (login: 10/5min IP,
  ingest: 1000/min token, global: 500/min) + payload size enforcement
- api/src/routes/admin/auth.ts: POST login, POST refresh, POST logout,
  GET /me — with audit events on all operations
- db/migrations/001–004: admin_users, refresh_tokens, audit_logs tables +
  dev seed (bcrypt superadmin)
- web/src/app/(admin)/login: Velzon Bootstrap 5 login page (Next.js client
  component, credentials:include, HTTP-only cookie flow)
- docs/permission-matrix.md: full permission matrix + audit event catalogue
  + rate/payload limit table (BIT-183 acceptance criterion)

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 04:22:57 +00:00
1sonhadorandPaperclip d455a26333 chore: init errors.bitreport.pt repo
Co-Authored-By: Paperclip <[email protected]>
2026-03-22 04:18:09 +00:00