Module: RequestId
- Defined in:
- lib/request_id.rb,
lib/request_id/version.rb,
lib/request_id/configuration.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
'0.4.3'
Class Method Summary collapse
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Public: Configure RequestId.
-
.get(id_key) ⇒ Object
Public: Retrieve the given id, which is generally set by the Rack or Sidekiq middleware.
-
.request_id ⇒ Object
Public: Retrieve the current request_id, which is generally set by the Rack or Sidekiq middleware.
-
.request_id=(request_id) ⇒ Object
Internal: Set the current request_id.
-
.set(id_key, id_value) ⇒ Object
Public: Set the given id to the given value.
-
.with(id_key, id_value) ⇒ Object
Public: Runs the block with the given id key and value set.
-
.with_request_id(request_id, &block) ⇒ Object
Public: Runs the block with the given request id set.
Class Method Details
.configuration ⇒ Object
76 77 78 |
# File 'lib/request_id.rb', line 76 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
87 88 89 |
# File 'lib/request_id.rb', line 87 def configure yield configuration end |
.get(id_key) ⇒ Object
Public: Retrieve the given id, which is generally set by the Rack or Sidekiq middleware.
67 68 69 |
# File 'lib/request_id.rb', line 67 def get(id_key) Thread.current[id_key] end |
.request_id ⇒ Object
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.
22 23 24 |
# File 'lib/request_id.rb', line 22 def request_id get(:request_id) end |
.request_id=(request_id) ⇒ Object
Internal: Set the current request_id.
Examples
RequestId.request_id = SecureRandom.hex
# => "2297456c027c536d0eb3eb86583fe5a9"
Returns the new String request id.
34 35 36 |
# File 'lib/request_id.rb', line 34 def request_id=(request_id) set(:request_id, request_id) end |
.set(id_key, id_value) ⇒ Object
Public: Set the given id to the given value
72 73 74 |
# 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) ⇒ Object
Public: Runs the block with the given id key and value set.
57 58 59 60 61 62 63 |
# 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) ⇒ Object
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"
52 53 54 |
# File 'lib/request_id.rb', line 52 def with_request_id(request_id, &block) with(:request_id, request_id, &block) end |