Sha256: d533a4a156ec6bafaac5adeec11e8eafed71f9a9e9a8557e666edf26f0cca5c2

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 KB

Contents

require "set"

module Bugsnag::Breadcrumbs
  class OnBreadcrumbCallbackList
    def initialize(configuration)
      @callbacks = Set.new
      @mutex = Mutex.new
      @configuration = configuration
    end

    ##
    # @param callback [Proc, Method, #call]
    # @return [void]
    def add(callback)
      @mutex.synchronize do
        @callbacks.add(callback)
      end
    end

    ##
    # @param callback [Proc, Method, #call]
    # @return [void]
    def remove(callback)
      @mutex.synchronize do
        @callbacks.delete(callback)
      end
    end

    ##
    # @param breadcrumb [Breadcrumb]
    # @return [void]
    def call(breadcrumb)
      @callbacks.each do |callback|
        begin
          should_continue = callback.call(breadcrumb)
        rescue StandardError => e
          @configuration.warn("Error occurred in on_breadcrumb callback: '#{e}'")
          @configuration.warn("on_breadcrumb callback stacktrace: #{e.backtrace.inspect}")
        end

        # only stop if should_continue is explicity 'false' to allow callbacks
        # to return 'nil'
        if should_continue == false
          breadcrumb.ignore!
          break
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
bugsnag-6.26.4 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.26.3 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.26.2 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.26.1 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.26.0 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.25.2 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.25.1 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.25.0 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.24.2 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.24.1 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.24.0 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb
bugsnag-6.23.0 lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb