Skip to content

Commit 5a771ee

Browse files
committed
better request_id passing
- removes remote_ip from log message
1 parent 2d4a88f commit 5a771ee

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

app/controllers/application_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
33
include AuthSupport
44
include ExceptionHandling
55

6-
before_action :set_current_request_id_and_ip_address
6+
before_action :set_current_request_id
77

88
# @!group Class Attributes
99
# @!attribute [rw]
@@ -21,9 +21,8 @@ class ApplicationController < ActionController::Base
2121

2222
private
2323

24-
def set_current_request_id_and_ip_address
24+
def set_current_request_id
2525
Current.request_id = request.request_id
26-
Current.ip_address = request.remote_ip
2726
end
2827

2928
helper_method :authenticated?

app/jobs/application_job.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class ApplicationJob < ActiveJob::Base
2+
attr_reader :request_id
3+
24
before_enqueue do
3-
self.arguments << { current_attributes: Current.attributes }
5+
self.arguments << { request_id: Current.request_id }
46
end
57

68
around_perform do |job, block|
7-
current_attributes = job.arguments.pop[:current_attributes] || {}
8-
Current.set(current_attributes) do
9-
block.call
10-
end
9+
@request_id = job.arguments.pop[:request_id] || ''
10+
block.call
1111
end
1212

1313
around_perform :log_activejob_id
@@ -18,7 +18,7 @@ def today
1818

1919
# AP-186: Add the ActiveJob ID to job logs
2020
def log_activejob_id
21-
logger.with_fields = { activejob_id: job_id, request_id: Current.request_id, ip_address: Current.ip_address }
21+
logger.with_fields = { activejob_id: job_id, request_id: @request_id }
2222
yield
2323
end
2424

app/models/current.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Current < ActiveSupport::CurrentAttributes
2-
attribute :request_id, :ip_address
2+
attribute :request_id
33

44
end

0 commit comments

Comments
 (0)