module RequestId
Constants
- VERSION
Public Class Methods
configuration()
click to toggle source
# File lib/request_id.rb, line 76 def configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
Public: Configure RequestId
.
Examples
RequestId.configure do |config| config.generate = false end
# File lib/request_id.rb, line 87 def configure yield configuration end
get(id_key)
click to toggle source
request_id()
click to toggle source
Public: Retrieve the current request_id
, which is generally set by the Rack
or Sidekiq
middleware.
Examples
RequestId.request_id # => "0b482498be0d6084d2b634cd6523418d"
Returns the String request id.
# File lib/request_id.rb, line 22 def request_id get(:request_id) end
request_id=(request_id)
click to toggle source
Internal: Set the current request_id.
Examples
RequestId.request_id = SecureRandom.hex # => "2297456c027c536d0eb3eb86583fe5a9"
Returns the new String request id.
# File lib/request_id.rb, line 34 def request_id=(request_id) set(:request_id, request_id) end
set(id_key, id_value)
click to toggle source
Public: Set the given id to the given value
# File lib/request_id.rb, line 72 def set(id_key, id_value) Thread.current[id_key] = id_value end
with(id_key, id_value) { || ... }
click to toggle source
Public: Runs the block with the given id key and value set.
# File lib/request_id.rb, line 57 def with(id_key, id_value) last_id = RequestId.get(id_key) RequestId.set(id_key, id_value) yield ensure RequestId.set(id_key, last_id) end
with_request_id(request_id, &block)
click to toggle source
Public: Runs the block with the given request id set.
Examples
RequestId.request_id # => "9fee77ec37b483983839fe7a753b64d9" RequestId.with_request_id('c8ee330973663097f50686eb17d3324e') do RequestId.request_id # => "c8ee330973663097f50686eb17d3324e" end RequestId.request_id # => "9fee77ec37b483983839fe7a753b64d9"
# File lib/request_id.rb, line 52 def with_request_id(request_id, &block) with(:request_id, request_id, &block) end