Skip to content

feat(observability): add structured request logging, request IDs and latency metrics - #1765

Merged
1nonlypiece merged 2 commits into
Disciplr-Org:mainfrom
Viccodes11:feat/observability-request-logging-metrics
Oct 24, 2026
Merged

1nonlypiece merged 2 commits into
Disciplr-Org:mainfrom
Viccodes11:feat/observability-request-logging-metrics

Conversation

@Viccodes11

Copy link
Copy Markdown
Contributor

Closes #1700

Summary of Changes

Adds structured JSON request logging, request ID propagation, database latency tracking, and Server-Timing headers to the deployed API:

  • apilib/log.mjs:
    • Structured pino logger configuring JSON output, log level from LOG_LEVEL, and redaction for authorization, cookies, and secret/signedXdr fields.
    • Request ID middleware: reads x-request-id header (validates format and <= 64 chars) or generates a UUID, attaches child logger to req.log, sets x-request-id header on responses.
    • Access log on request finish with method, route pattern (/vaults/:id instead of raw URL to avoid cardinality and PII leaks), status, total latency, and store kind. Logs 5xx as error, 4xx as warn, 2xx/3xx as info.
    • Database timing: wrapPoolForTiming wraps pool and client queries to track cumulative DB duration per request and logs slow queries taking longer than SLOW_QUERY_MS (default 500ms) with statement fingerprints omitting parameter values.
    • Server-Timing header emitted on responses (db;dur=..., total;dur=...).
  • api/index.mjs:
    • Registers requestIdMiddleware().
    • Updates error handling wrapper to log { err: e } using req.log.error() and return { error: 'Internal error', requestId } on 500 errors.
  • apilib/store.mjs:
    • Wraps Postgres pool with wrapPoolForTiming.
  • .env.example:
    • Documents LOG_LEVEL and SLOW_QUERY_MS.
  • Tests:
    • apilib/__tests__/log.test.mjs: Unit tests for request ID validation, access logs, pino capture redaction, fingerprinting, and slow query logging with a stubbed pool.
    • api/__tests__/observability.test.mjs: HTTP-level integration tests for request ID echoing/replacement, Server-Timing header, and 500 error correlation ID.

Viccodes11 and others added 2 commits October 24, 2026 19:34
@1nonlypiece
1nonlypiece merged commit 1568d8f into Disciplr-Org:main Oct 24, 2026
2 of 5 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.

[observability] Add structured request logging, request IDs and latency metrics to the deployed API

2 participants