Sha256: 2abfe954912b09bef45e8976bdb7fc202e01915a94865da192f73cd7cdb0672b
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 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) IATT.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
2 entries across 2 versions & 1 rubygems