Class: LogBrew::RailsErrorSubscriber
- Inherits:
-
Object
- Object
- LogBrew::RailsErrorSubscriber
- Includes:
- TraceRailsErrorSubscriberMethods
- Defined in:
- lib/logbrew.rb
Overview
Rails.error subscriber for handled and manually reported Rails exceptions.
Register an instance with Rails.error.subscribe(...) from a Rails
initializer. This class avoids a hard Rails dependency so the core gem stays
usable in plain Ruby and Rack apps.
Constant Summary collapse
- DEFAULT_EVENT_ID_PREFIX =
"ruby_rails_error"- SEVERITY_TO_ISSUE_LEVEL =
{ "info" => "info", "warning" => "warning", "error" => "error" }.freeze
Instance Method Summary collapse
-
#initialize(client:, transport: nil, flush_on_report: false, event_id_prefix: DEFAULT_EVENT_ID_PREFIX, metadata: nil, timestamp_provider: nil, include_exception_backtrace: false, on_error: nil, raise_errors: false) ⇒ RailsErrorSubscriber
constructor
A new instance of RailsErrorSubscriber.
- #report(error, handled: true, severity: :error, context: nil, source: nil, **_options) ⇒ Object
Constructor Details
#initialize(client:, transport: nil, flush_on_report: false, event_id_prefix: DEFAULT_EVENT_ID_PREFIX, metadata: nil, timestamp_provider: nil, include_exception_backtrace: false, on_error: nil, raise_errors: false) ⇒ RailsErrorSubscriber
Returns a new instance of RailsErrorSubscriber.
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/logbrew.rb', line 547 def initialize( client:, transport: nil, flush_on_report: false, event_id_prefix: DEFAULT_EVENT_ID_PREFIX, metadata: nil, timestamp_provider: nil, include_exception_backtrace: false, on_error: nil, raise_errors: false ) Validation.require_non_empty("event id prefix", event_id_prefix) raise SdkError.new("validation_error", "metadata must be an object") unless .nil? || .is_a?(Hash) @client = client @transport = transport @flush_on_report = flush_on_report @event_id_prefix = event_id_prefix @metadata = || {} @timestamp_provider = @include_exception_backtrace = include_exception_backtrace @on_error = on_error @raise_errors = raise_errors @next_event_number = 0 end |
Instance Method Details
#report(error, handled: true, severity: :error, context: nil, source: nil, **_options) ⇒ Object
573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/logbrew.rb', line 573 def report(error, handled: true, severity: :error, context: nil, source: nil, **) capture_safely do @next_event_number += 1 @client.issue( "#{@event_id_prefix}_#{@next_event_number}", , title: error_title(error), level: issue_level(severity), message: (error), metadata: (error, handled, severity, context, source) ) flush_if_configured end end |