Skip to content

feat(backend): add request ID propagation and structured JSON logging#595

Open
Aish-kul16 wants to merge 9 commits into
utksh1:mainfrom
Aish-kul16:feature/request-id-logging
Open

feat(backend): add request ID propagation and structured JSON logging#595
Aish-kul16 wants to merge 9 commits into
utksh1:mainfrom
Aish-kul16:feature/request-id-logging

Conversation

@Aish-kul16
Copy link
Copy Markdown
Contributor

Summary

This PR adds request ID propagation and structured JSON logging across backend API requests, audit logging, and background workflow execution.

Changes

  • Added request context management using ContextVar

  • Added request ID middleware that:

    • Accepts incoming X-Request-ID
    • Generates a request ID when absent
    • Returns the request ID in response headers
  • Added structured JSON logging support

  • Injected request IDs into log records

  • Propagated request IDs into workflow/background task execution

  • Added request ID tracking in audit log context

  • Added integration tests validating request ID persistence and audit log propagation

Testing

  • Verified successful audit log creation
  • Verified request ID persistence in audit context
  • Verified negative cases (404, unfinished tasks, generation failures)
  • Verified request ID propagation from API request into downstream processing

Notes

No operator configuration changes were introduced, so documentation updates were not required.

Closes #219

Copy link
Copy Markdown
Owner

@utksh1 utksh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR currently has merge conflicts (DIRTY / conflicting), so I cannot review or merge it reliably.

Please rebase/update against current main, resolve the conflicts in the backend logging/database/middleware files, and make sure CI stays green. I will re-review after the branch is clean.

@utksh1 utksh1 added level:advanced 55 pts difficulty label for advanced contributor PRs type:feature Feature work category bonus label area:backend Backend API, database, or service work type:bug Bug fix work category bonus label labels Jun 5, 2026
@Aish-kul16 Aish-kul16 force-pushed the feature/request-id-logging branch from 98af1ca to 0b27e8f Compare June 6, 2026 06:54
@Aish-kul16
Copy link
Copy Markdown
Contributor Author

Hi @utksh1 ,

I've addressed the requested changes and pushed the updates. All CI checks are now passing successfully.

Could you please review the PR again ?

Thank you.

Copy link
Copy Markdown
Owner

@utksh1 utksh1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the latest update. This still overlaps heavily with the request-id/error-payload work in #618/#633 and carries unrelated CI/frontend baseline edits. Please rebase on latest main after #629, scope this PR to structured logging/request-id propagation only, and avoid broad formatting or unrelated test-baseline changes.

@Aish-kul16
Copy link
Copy Markdown
Contributor Author

Re-reviewed the latest update. This still overlaps heavily with the request-id/error-payload work in #618/#633 and carries unrelated CI/frontend baseline edits. Please rebase on latest main after #629, scope this PR to structured logging/request-id propagation only, and avoid broad formatting or unrelated test-baseline changes.

Thanks for the review.

Understood. I'll rebase on the latest main after #629 and reduce the PR scope to only the structured logging/request-id propagation changes. I'll also remove the unrelated workflow, frontend test, and baseline updates that were pulled in while resolving conflicts.

I'll update the PR shortly.

@Aish-kul16
Copy link
Copy Markdown
Contributor Author

Hi @utksh1

I rebased locally against the latest main and found that most of the original request-id and structured logging changes now appear to already exist through the newer work that landed in main. The remaining differences on my branch are primarily workflow request-id propagation and some conflict-resolution/test changes that I understand should not be included.

Before I rework the branch further, could you clarify whether you'd like me to:

  1. Reduce this PR to only the remaining workflow request-id propagation changes, or
  2. Close/supersede this PR if the request-id/logging functionality is already covered by the newer merged work?

I want to avoid duplicating functionality that is now present in main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend Backend API, database, or service work level:advanced 55 pts difficulty label for advanced contributor PRs type:bug Bug fix work category bonus label type:feature Feature work category bonus label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BACKEND] Add request IDs and structured JSON logging across API and workers

2 participants