Skip to content

feat(infra): automated database query execution time logging for slow query detection (Closes #1365) - #1414

Closed
camesenin wants to merge 1 commit into
FinesseStudioLab:mainfrom
camesenin:feat/query-execution-logging-1365
Closed

camesenin wants to merge 1 commit into
FinesseStudioLab:mainfrom
camesenin:feat/query-execution-logging-1365

Conversation

@camesenin

Copy link
Copy Markdown

Summary

Closes #1365

This PR implements automated database query execution time logging for slow query detection (>200ms) with dual reporting to CloudWatch (via structured Pino logs) and Sentry.

Key Changes

  • Slow Query Monitoring Engine (backend/src/db/queryLogger.js):
    • Measures execution time across SQLite (better-sqlite3) and Postgres (pg.Pool).
    • Alerts when query execution exceeds threshold (default 200ms, configurable via SLOW_QUERY_THRESHOLD_MS).
    • Formats structured JSON log payloads for CloudWatch with duration, threshold, sanitized parameters, and SQL query.
    • Sends warning events to Sentry with context tags.
    • Parameter sanitizer masks sensitive data (passwords, tokens, API keys, secrets).
  • DAL Integration (backend/src/dal/index.js):
    • Automatically wraps SQLite and Postgres connections created via createDal.
  • Migration standard alignment:
    • Standardized numeric version exports on recent SQLite migrations.
  • Tests:
    • Comprehensive unit test suite in backend/src/db/queryLogger.test.js covering threshold filtering, parameter redaction, and both SQLite and PostgreSQL query interceptions.

@camesenin

Copy link
Copy Markdown
Author

Hi @Gbangbolaoluwagbemiga @joelpeace48-cell, this PR is ready for review with all tests passing. Could you please assign me to this issue on Drips Wave (@camesenin) so that it is properly tracked for Wave 9 before merging? Thank you!

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.

feat(infra): Automated database query execution time logging for slow query detection

2 participants