Skip to content

feat(sdk): enrich collected metrics — granular status codes, TTFB, request size, inflight#9

Merged
Fabien83560 merged 1 commit into
mainfrom
dev
May 29, 2026
Merged

feat(sdk): enrich collected metrics — granular status codes, TTFB, request size, inflight#9
Fabien83560 merged 1 commit into
mainfrom
dev

Conversation

@Fabien83560
Copy link
Copy Markdown
Member

feat(sdk): enrich collected metrics — granular status codes, TTFB, request size, inflight

Context

The current schema aggregated HTTP status codes into three fixed buckets (2xx/4xx/5xx),
making it impossible to distinguish a 401 from a 429 or a 404 at the insight level.
This PR extends the data collection layer with higher-value signals while keeping the
privacy-first guarantee intact — no body content, no PII, sizes only.

Also fixes a silent bug: lat_avg was computed in the aggregator but never written to SQLite.

Changes

  • status_3xx — redirections tracked as a dedicated counter
  • status_dist — per-code granular distribution stored as JSON ({"200":45,"404":3})
  • lat_ttfb_p50/p90/p99 — Time To First Byte captured via res.write/res.end patch
  • request_size_avg — request body size from req.headers['content-length']
  • inflight_avg / inflight_max — concurrent request count snapshot at processing time
  • lat_avg — bug fix: was computed but missing from INSERT statement and schema
  • Automatic migrations for all new columns (silent ALTER TABLE on existing databases)
  • Version bumped 2.1.22.2.0

How to test

npm install
npm run tests   # 82/82 pass

Manual validation: add the middleware to any Express app, make a few requests with
different status codes, then query .apiforge.db:

SELECT route, status_dist, lat_ttfb_p90, inflight_max FROM api_metrics LIMIT 5;

Checklist

  • Tests added / updated (82 pass, 20 new tests)
  • Documentation updated
  • No breaking change (new nullable columns, backward-compatible migrations)
  • Reviewed locally

@Fabien83560 Fabien83560 merged commit aa175b7 into main May 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant