Sha256: 419103e03f51bb05bb11aab28521a25e899faa9e7e0fd8b450522e26446ebe7a

Contents?: true

Size: 796 Bytes

Versions: 5

Compression:

Stored size: 796 Bytes

Contents

# frozen_string_literal: true

module Kiev
  module RequestLogger
    module Mixin
      NEW_LINE = "\n"

      def wrap_request_logger(event, **data, &_block)
        began_at = Time.now
        error = nil

        begin
          return_value = yield
        rescue StandardError => exception
          error = exception
        end

        begin
          data[:request_duration] = ((Time.now - began_at) * 1000).round(3)
          if error
            data[:error_class] = error.class.name
            data[:error_message] = error.message[0..5000]
            data[:error_backtrace] = Array(error.backtrace).join(NEW_LINE)[0..5000]
          end

          Kiev.event(event, data)
        ensure
          raise error if error
          return_value
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kiev-4.2.0 lib/kiev/request_logger.rb
kiev-4.1.0 lib/kiev/request_logger.rb
kiev-4.0.0 lib/kiev/request_logger.rb
kiev-3.0.0 lib/kiev/request_logger.rb
kiev-2.8.0 lib/kiev/request_logger.rb