Sha256: 2bcbaba1c886e7e6a5a4dbba4a3326db0b2657fec265b90104323779dc4ffcb1

Contents?: true

Size: 1.38 KB

Versions: 22

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require_relative './tracing'
require_relative './error_logging'

module InstrumentAllTheThings
  module Instrumentors
    DEFAULT_ERROR_LOGGING_OPTIONS = {
      exclude_bundle_path: true,
      rescue_class: StandardError,
    }.freeze

    ERROR_LOGGER = lambda do |exception, backtrace_cleaner|
    end

    ERROR_LOGGING_WRAPPER = lambda do |opts, context|
      opts = if opts == true
               DEFAULT_ERROR_LOGGING_OPTIONS
             else
               DEFAULT_ERROR_LOGGING_OPTIONS.merge(opts)
             end

      backtrace_cleaner = if opts[:exclude_bundle_path] && defined?(Bundler)
                            bundle_path = Bundler.bundle_path.to_s
                            ->(trace) { trace.reject { |p| p.start_with?(bundle_path) } }
                          else
                            ->(trace) { trace }
                          end

      lambda do |klass, next_blk, actual_code|
        next_blk.call(klass, actual_code)
      rescue opts[:rescue_class] => e
        raise if e.instance_variable_get(:@_logged_by_iatt)

        e.instance_variable_set(:@_logged_by_iatt, true)

        InstrumentAllTheThings.logger&.error <<~ERROR
          An error occurred in #{context.trace_name(klass)}

          #{e.message}
          #{backtrace_cleaner.call(e.backtrace || []).join("\n")}
        ERROR

        raise
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
instrument_all_the_things-5.0.1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-5.0.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.4.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-4.0.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.1.2 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.1.2.pre1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.1.1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.1.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.1.0.pre1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.0.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-3.0.0.pre1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-2.0.2 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-2.0.1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-2.0.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.3.1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.3.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.2.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.1.1 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.1.0 lib/instrument_all_the_things/instrumentors/error_logging.rb
instrument_all_the_things-1.0.4 lib/instrument_all_the_things/instrumentors/error_logging.rb