Skip to content

Implement API Request Logging to Database#137

Open
quickweb-stack wants to merge 2 commits into
Pidoko257:mainfrom
quickweb-stack:api-request
Open

Implement API Request Logging to Database#137
quickweb-stack wants to merge 2 commits into
Pidoko257:mainfrom
quickweb-stack:api-request

Conversation

@quickweb-stack

Copy link
Copy Markdown

Close: #103

Description

I've successfully implemented API request logging to the database. Here's what was done:

  1. Created a database migration ( migrations/20260630_create_request_logs_table.sql ):

    • Defined request_logs table with required columns: id , request_id , method , path , status_code , duration_ms , api_key_id , user_id , ip_address , user_agent , and created_at .
    • Added appropriate indexes for efficient querying.
  2. Created request logging middleware ( src/middleware/requestLogger.ts ):

    • Fires after response is sent using res.on("finish") to avoid blocking response time.
    • Captures all required fields: request ID, method, path, status code, duration, API key ID, user ID, IP address, and user agent.
    • Excludes sensitive paths: /health , /health/lb , /ready , /metrics .
    • Logs asynchronously to the database using queryWrite .
    • Fails gracefully if logging fails (only logs to console).
  3. Applied the middleware ( src/index.ts ):

    • Imported the requestLogger middleware.
    • Added it after requestId middleware to ensure request ID is available.
      To use this implementation:
  4. Run the migration with npm run migrate:up to create the request_logs table.

  5. The middleware will automatically log all API requests.

Related Issue

Fixes #(issue number)

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Performance improvement

Changes Made

Testing

How did you test these changes?

Checklist

  • Code follows project style
  • Self-reviewed my code
  • Commented complex code
  • Updated documentation
  • No new warnings
  • Added tests (if applicable)

Screenshots (if applicable)

Additional Notes

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@quickweb-stack Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@quickweb-stack

Copy link
Copy Markdown
Author

Done, Close: #137

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.

Implement API Request Logging to Database

1 participant