Skip to content

feat: structured logs /api/webhooks with correlation IDs - #711

Open
codenerde wants to merge 1 commit into
Predictify-org:mainfrom
codenerde:task/webhooks-logs-v7
Open

feat: structured logs /api/webhooks with correlation IDs#711
codenerde wants to merge 1 commit into
Predictify-org:mainfrom
codenerde:task/webhooks-logs-v7

Conversation

@codenerde

Copy link
Copy Markdown

Summary

Add structured access logs on /api/webhooks with correlation ID support, following the same pattern used by all other API routes (/api/users, /api/auth, /api/markets, /api/feature-flags, etc.).

Changes

src/middleware/accessLog.ts

  • Added webhooks_access_log log name mapping for requests starting with /api/webhooks

src/routes/webhooks.ts

  • Imported and mounted accessLog middleware as the first middleware on the router
  • Updated JSDoc to document the structured access log behavior
  • All webhook endpoints now emit a structured webhooks_access_log entry on response finish
  • The X-Correlation-Id response header is set on all webhook responses

tests/webhooksAccessLog.test.ts (new)

  • 21 focused unit tests covering:
    • Log name emission (webhooks_access_log)
    • All HTTP methods (GET, POST, PATCH, DELETE)
    • Correlation ID resolution (header, fallback, UUID generation)
    • Status codes (200, 400, 404, 500)
    • Actor capture (authenticated + anonymous)
    • Response header echo
    • All required payload fields (method, path, statusCode, durationMs, ip, size, actor)
    • Sub-path handling under /api/webhooks
    • IP resolution (X-Forwarded-For + fallback)

Testing

  • All 21 new tests pass: npx jest tests/webhooksAccessLog.test.ts
  • ESLint passes with zero errors
  • Follows the same patterns used in tests/usersAccessLog.test.ts and tests/featureFlagsAccessLog.test.ts

Related

Closes #429

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@codenerde 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

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.

Add structured logs on /api/webhooks (v7)

2 participants