lib/elastic_apm/error_builder.rb in elastic-apm-0.6.2 vs lib/elastic_apm/error_builder.rb in elastic-apm-0.7.0

- old
+ new

@@ -1,19 +1,22 @@ # frozen_string_literal: true module ElasticAPM # @api private class ErrorBuilder - def initialize(config) - @config = config + def initialize(agent) + @agent = agent end def build_exception(exception, handled: true) error = Error.new error.exception = Error::Exception.new(exception, handled: handled) - add_stacktrace error, :exception, exception.backtrace + if exception.backtrace + add_stacktrace error, :exception, exception.backtrace + end + add_transaction_id error if (transaction = ElasticAPM.current_transaction) error.context = transaction.context.dup end @@ -23,19 +26,24 @@ def build_log(message, backtrace: nil, **attrs) error = Error.new error.log = Error::Log.new(message, **attrs) - add_stacktrace error, :log, backtrace + if backtrace + add_stacktrace error, :log, backtrace + end + add_transaction_id error error end private def add_stacktrace(error, kind, backtrace) - return unless (stacktrace = Stacktrace.build(@config, backtrace, :error)) + stacktrace = + @agent.stacktrace_builder.build(backtrace, type: :error) + return unless stacktrace case kind when :exception error.exception.stacktrace = stacktrace when :log