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.
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/logbrew.rb', line 603 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
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/logbrew.rb', line 632 def report(error, handled: true, severity: :error, context: nil, source: nil, **) capture_safely do attributes = if error.is_a?(Exception) IssueDiagnostics.from_exception( error, title: error_title(error), level: issue_level(severity), message: @include_exception_message ? (error) : nil, mechanism_type: "rails.error_reporter", handled: handled, metadata: (error, handled, severity, context, source) ) else { title: error_title(error), level: issue_level(severity), metadata: (error, handled, severity, context, source) }.tap do |fallback| fallback[:message] = (error) if @include_exception_message end end @client.issue(next_event_id, , attributes) flush_if_configured end end |