⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@jason-raitz
Copy link
Contributor

This pull request introduces a system for propagating the current HTTP request ID through background jobs, enabling improved traceability and logging. The main changes include capturing the request ID in controllers, passing it to jobs, and logging it with job metadata. Comprehensive tests are also added to verify this behavior.

Request ID propagation and logging:

  • Added a new Current model using ActiveSupport::CurrentAttributes to store the request_id for the current thread/request.
  • Updated ApplicationController to set Current.request_id before each request, ensuring the request ID is available throughout the request lifecycle. [1] [2]
  • Enhanced ApplicationJob to append the request_id to job arguments before enqueueing, extract and set it during job execution, and log it alongside the job ID for improved traceability.

Testing enhancements:

  • Added a new spec (application_job_spec.rb) to verify that jobs correctly handle the presence or absence of request_id, including argument manipulation and logging behavior.

Closes AP-513 & AP-186

Co-authored-by @steve-sullivan

When active_jobs are enqueued, this will add current_attributes for jobid, request_id, and ip_address.
 - removes remote_ip from log message
 - only add a request_id to the job if there is a request_id
   specs tend not to stub out request_id
- tests request_id manipulation around queues
- tests attaching activejob_id and request_id to logs
@jason-raitz
Copy link
Contributor Author

I'll rebase if needed before merging.

Copy link
Member

@anarchivist anarchivist left a comment

Choose a reason for hiding this comment

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

a few questions, but mostly looks good!

- adding a note to the inclusion of Current class
- improving Current.request_id testing
@jason-raitz jason-raitz merged commit f0f5ce3 into main Feb 12, 2026
5 checks passed
@jason-raitz jason-raitz deleted the AP-513_improve_log_tracing branch February 12, 2026 20:25
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.

3 participants