Class: Kiev::ContextReader
- Inherits:
-
Object
- Object
- Kiev::ContextReader
- Defined in:
- lib/kiev/context_reader.rb
Overview
Abstracts common details about reading tracing context into Kiev’s request store. Subclass and override #[] to change field lookup.
Direct Known Subclasses
Constant Summary collapse
- REQUEST_ID =
"request_id"- REQUEST_DEPTH =
"request_depth"- TREE_PATH =
"tree_path"
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(subject) ⇒ ContextReader
constructor
A new instance of ContextReader.
- #request_depth ⇒ Object
- #request_id ⇒ Object
- #tree_path ⇒ Object
- #tree_root? ⇒ Boolean
Constructor Details
#initialize(subject) ⇒ ContextReader
Returns a new instance of ContextReader.
12 13 14 |
# File 'lib/kiev/context_reader.rb', line 12 def initialize(subject) @subject = subject end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 |
# File 'lib/kiev/context_reader.rb', line 16 def [](key) subject[key] end |
#request_depth ⇒ Object
28 29 30 |
# File 'lib/kiev/context_reader.rb', line 28 def request_depth tree_root? ? 0 : (self[REQUEST_DEPTH].to_i + 1) end |
#request_id ⇒ Object
20 21 22 |
# File 'lib/kiev/context_reader.rb', line 20 def request_id self[REQUEST_ID] || SecureRandom.uuid end |
#tree_path ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/kiev/context_reader.rb', line 32 def tree_path if tree_root? SubrequestHelper.root_path(synchronous: false) else self[TREE_PATH] end end |
#tree_root? ⇒ Boolean
24 25 26 |
# File 'lib/kiev/context_reader.rb', line 24 def tree_root? !self[REQUEST_ID] end |