Class: Honeybadger::ContextManager Private
- Inherits:
-
Object
- Object
- Honeybadger::ContextManager
- Includes:
- Conversions
- Defined in:
- lib/honeybadger/context_manager.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary
Constants included from Conversions
Honeybadger::Conversions::MAX_CONTEXT_DEPTH
Class Method Summary collapse
- .current ⇒ Object private
Instance Method Summary collapse
- #clear! ⇒ Object private
- #clear_context ⇒ Object private
- #clear_event_context ⇒ Object private
- #get_context ⇒ Object private
- #get_event_context ⇒ Object private
- #get_rack_env ⇒ Object private
- #get_request_id ⇒ Object private
-
#initialize ⇒ ContextManager
constructor
private
A new instance of ContextManager.
-
#set_context(hash, &block) ⇒ Object
private
Internal helpers.
- #set_event_context(hash, &block) ⇒ Object private
- #set_rack_env(env) ⇒ Object private
- #set_request_id(request_id) ⇒ Object private
Methods included from Conversions
Constructor Details
#initialize ⇒ ContextManager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ContextManager.
13 14 15 16 |
# File 'lib/honeybadger/context_manager.rb', line 13 def initialize @monitor = Monitor.new _initialize end |
Class Method Details
.current ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/honeybadger/context_manager.rb', line 9 def self.current Thread.current[:__hb_context_manager] ||= new end |
Instance Method Details
#clear! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/honeybadger/context_manager.rb', line 18 def clear! _initialize end |
#clear_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 59 60 61 |
# File 'lib/honeybadger/context_manager.rb', line 56 def clear_context @monitor.synchronize do @global_context = nil @local_context = nil end end |
#clear_event_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 |
# File 'lib/honeybadger/context_manager.rb', line 95 def clear_event_context @monitor.synchronize do @global_event_context = nil @local_event_context = nil end end |
#get_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 |
# File 'lib/honeybadger/context_manager.rb', line 48 def get_context @monitor.synchronize do return @global_context unless @local_context @global_context.merge(@local_context.inject({}, :merge)) end end |
#get_event_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 |
# File 'lib/honeybadger/context_manager.rb', line 87 def get_event_context @monitor.synchronize do return @global_event_context unless @local_event_context @global_event_context.merge(@local_event_context.inject({}, :merge)) end end |
#get_rack_env ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 |
# File 'lib/honeybadger/context_manager.rb', line 106 def get_rack_env @monitor.synchronize { @rack_env } end |
#get_request_id ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 |
# File 'lib/honeybadger/context_manager.rb', line 114 def get_request_id @monitor.synchronize { @request_id } end |
#set_context(hash, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helpers
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/honeybadger/context_manager.rb', line 24 def set_context(hash, &block) local = block_given? @monitor.synchronize do @global_context ||= {} @local_context ||= [] new_context = Context(hash) if local @local_context << new_context else @global_context.update(new_context) end end if local begin yield ensure @monitor.synchronize { @local_context&.pop } end end end |
#set_event_context(hash, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/honeybadger/context_manager.rb', line 63 def set_event_context(hash, &block) local = block_given? @monitor.synchronize do @global_event_context ||= {} @local_event_context ||= [] new_context = Context(hash) if local @local_event_context << new_context else @global_event_context.update(new_context) end end if local begin yield ensure @monitor.synchronize { @local_event_context&.pop } end end end |
#set_rack_env(env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'lib/honeybadger/context_manager.rb', line 102 def set_rack_env(env) @monitor.synchronize { @rack_env = env } end |
#set_request_id(request_id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 |
# File 'lib/honeybadger/context_manager.rb', line 110 def set_request_id(request_id) @monitor.synchronize { @request_id = request_id } end |