Sha256: 25c74664a9ae3b294c39c87cb6333887bce9e921bc8f9dfaf4459948eb116bc9

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  class ErrorBuilder
    def initialize(config)
      @config = config
    end

    def build_exception(exception, handled: true)
      error = Error.new
      error.exception = Error::Exception.new(exception, handled: handled)

      add_stacktrace error, :exception, exception.backtrace
      add_transaction_id error

      if (transaction = ElasticAPM.current_transaction)
        error.context = transaction.context.dup
      end

      error
    end

    def build_log(message, backtrace: nil, **attrs)
      error = Error.new
      error.log = Error::Log.new(message, **attrs)

      add_stacktrace error, :log, backtrace
      add_transaction_id error

      error
    end

    private

    def add_stacktrace(error, kind, backtrace)
      return unless (stacktrace = Stacktrace.build(@config, backtrace, :error))

      case kind
      when :exception
        error.exception.stacktrace = stacktrace
      when :log
        error.log.stacktrace = stacktrace
      end

      error.culprit = stacktrace.frames.first.function
    end

    def add_transaction_id(error)
      return unless (transaction = ElasticAPM.current_transaction)
      error.transaction_id = transaction.id
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
elastic-apm-0.6.2 lib/elastic_apm/error_builder.rb
elastic-apm-0.6.1 lib/elastic_apm/error_builder.rb
elastic-apm-0.5.1 lib/elastic_apm/error_builder.rb
elastic-apm-0.5.0 lib/elastic_apm/error_builder.rb
elastic-apm-0.4.5 lib/elastic_apm/error_builder.rb
elastic-apm-0.4.4 lib/elastic_apm/error_builder.rb
elastic-apm-0.4.3 lib/elastic_apm/error_builder.rb
elastic-apm-0.4.2 lib/elastic_apm/error_builder.rb
elastic-apm-0.4.1 lib/elastic_apm/error_builder.rb
elastic-apm-0.4.0 lib/elastic_apm/error_builder.rb