Class: Lumberjack::Rack::RequestId

Inherits:
Object
  • Object
show all
Defined in:
lib/lumberjack/rack/request_id.rb

Overview

Support for using the Rails ActionDispatch request id in the log. The format is expected to be a random UUID and only the first chunk is used for terseness if the abbreviated argument is true.

Constant Summary collapse

REQUEST_ID =
"action_dispatch.request_id"

Instance Method Summary collapse

Constructor Details

#initialize(app, abbreviated = false) ⇒ RequestId

Returns a new instance of RequestId.



11
12
13
14
# File 'lib/lumberjack/rack/request_id.rb', line 11

def initialize(app, abbreviated = false)
  @app = app
  @abbreviated = abbreviated
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/lumberjack/rack/request_id.rb', line 16

def call(env)
  request_id = env[REQUEST_ID]
  if request_id && @abbreviated
    request_id = request_id.split('-', 2).first
  end
  Lumberjack.unit_of_work(request_id) do
    @app.call(env)
  end
end