Class: ForgeOpsTracker::ErrorSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/forge_ops_tracker/error_subscriber.rb

Overview

Implements the subscriber interface Rails.error.subscribe expects (#report). An error reporter that itself raises while reporting an error is the worst possible failure mode, so every path here is wrapped to guarantee this never propagates an exception back into the host app's error-handling cycle.

Instance Method Summary collapse

Constructor Details

#initialize(configuration, delivery_queue: DeliveryQueue.new(configuration), event_builder: EventBuilder.new(configuration)) ⇒ ErrorSubscriber

Returns a new instance of ErrorSubscriber.



8
9
10
11
12
# File 'lib/forge_ops_tracker/error_subscriber.rb', line 8

def initialize(configuration, delivery_queue: DeliveryQueue.new(configuration), event_builder: EventBuilder.new(configuration))
  @configuration = configuration
  @delivery_queue = delivery_queue
  @event_builder = event_builder
end

Instance Method Details

#report(error, handled: true, severity: nil, context: {}, source: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/forge_ops_tracker/error_subscriber.rb', line 14

def report(error, handled: true, severity: nil, context: {}, source: nil)
  return unless configuration.enabled?

  delivery_queue.push(event_builder.build(error, context: context))
  nil
rescue StandardError => e
  configuration.logger&.debug { "[ForgeOpsTracker] report failed: #{e.class}: #{e.message}" }
  nil
end