Class: Chronos::Agent
- Inherits:
-
Object
- Object
- Chronos::Agent
- Defined in:
- lib/chronos/agent.rb
Overview
Runtime composition root for the framework-independent Chronos agent.
Constant Summary collapse
- DEFAULT_FLUSH_TIMEOUT =
5.0
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #add_breadcrumb(attributes = {}) ⇒ Object
- #close(timeout = DEFAULT_FLUSH_TIMEOUT) ⇒ Object
- #diagnostics ⇒ Object
- #flush(timeout = DEFAULT_FLUSH_TIMEOUT) ⇒ Object
-
#initialize(config, options = {}) ⇒ Agent
constructor
A new instance of Agent.
- #notify(exception, context = {}) ⇒ Object
- #notify_sync(exception, context = {}) ⇒ Object
- #with_context(context = {}, &block) ⇒ Object
Constructor Details
#initialize(config, options = {}) ⇒ Agent
Returns a new instance of Agent.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/chronos/agent.rb', line 19 def initialize(config, = {}) @config = config @logger = [:logger] || Internal::SafeLogger.new(config.logger) @context_store = [:context_store] || build_context_store(config.context_store) unless Ports::ContextStore.compatible?(@context_store) raise ArgumentError, "context store does not implement the Chronos context-store port" end @transport = [:transport] || Adapters::NetHttpTransport.new(config, @logger) unless Ports::Transport.compatible?(@transport) raise ArgumentError, "transport does not implement the Chronos transport port" end = {} [:queue] = [:queue] if [:queue] [:worker_pool] = [:worker_pool] if [:worker_pool] @delivery_pipeline = [:delivery_pipeline] || Application::DeliveryPipeline.new( config, @transport, @logger, ) @capture = [:capture] || Application::CaptureException.new(config, @delivery_pipeline, @logger) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/chronos/agent.rb', line 17 def config @config end |
Instance Method Details
#add_breadcrumb(attributes = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chronos/agent.rb', line 54 def (attributes = {}) context = @context_store.get buffer = context[:__chronos_breadcrumbs] buffer ||= Core::BreadcrumbBuffer.new(@config., @config.) buffer.add(attributes) @context_store.set(context.merge(:__chronos_breadcrumbs => buffer)) true rescue StandardError => error @logger.warn("Chronos breadcrumb failed: #{error.class}") false end |
#close(timeout = DEFAULT_FLUSH_TIMEOUT) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/chronos/agent.rb', line 73 def close(timeout = DEFAULT_FLUSH_TIMEOUT) @delivery_pipeline.close(timeout) rescue StandardError => error @logger.warn("Chronos close failed: #{error.class}") false end |
#diagnostics ⇒ Object
80 81 82 83 |
# File 'lib/chronos/agent.rb', line 80 def diagnostics details = @delivery_pipeline.diagnostics details[:queue].merge(details) end |
#flush(timeout = DEFAULT_FLUSH_TIMEOUT) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/chronos/agent.rb', line 66 def flush(timeout = DEFAULT_FLUSH_TIMEOUT) @delivery_pipeline.flush(timeout) rescue StandardError => error @logger.warn("Chronos flush failed: #{error.class}") false end |
#notify(exception, context = {}) ⇒ Object
42 43 44 |
# File 'lib/chronos/agent.rb', line 42 def notify(exception, context = {}) @capture.call(exception, context_for_capture(context)) end |
#notify_sync(exception, context = {}) ⇒ Object
46 47 48 |
# File 'lib/chronos/agent.rb', line 46 def notify_sync(exception, context = {}) @capture.call_sync(exception, context_for_capture(context)) end |
#with_context(context = {}, &block) ⇒ Object
50 51 52 |
# File 'lib/chronos/agent.rb', line 50 def with_context(context = {}, &block) @context_store.with_context(context, &block) end |