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_message: true, 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_message: true, include_exception_backtrace: false, on_error: nil, raise_errors: false) ⇒ RailsErrorSubscriber
Returns a new instance of RailsErrorSubscriber.
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/logbrew.rb', line 575 def initialize( client:, transport: nil, flush_on_report: false, event_id_prefix: DEFAULT_EVENT_ID_PREFIX, metadata: nil, timestamp_provider: nil, include_exception_message: true, 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_message = @include_exception_backtrace = include_exception_backtrace @on_error = on_error @raise_errors = raise_errors @next_event_number = 0 @event_id_mutex = Mutex.new end |
Instance Method Details
#report(error, handled: true, severity: :error, context: nil, source: nil, **_options) ⇒ Object
604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/logbrew.rb', line 604 def report(error, handled: true, severity: :error, context: nil, source: nil, **) capture_safely do attributes = { title: error_title(error), level: issue_level(severity), metadata: (error, handled, severity, context, source) } attributes[:message] = (error) if @include_exception_message @client.issue(next_event_id, , attributes) flush_if_configured end end |