Sha256: 04131aa4c9521b1fe5f933664238269cb04be6b4511428e8ad808f9d2475c9c1

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module ElasticAPM
  module Transport
    module Serializers
      # @api private
      class ErrorSerializer < Serializer
        # rubocop:disable Metrics/MethodLength
        def build(error)
          base = {
            id: error.id,
            transaction_id: error.transaction_id,
            trace_id: error.trace_id,
            parent_id: error.parent_id,

            culprit: error.culprit,
            timestamp: error.timestamp,
            context: error.context.to_h
          }

          if (exception = error.exception)
            base[:exception] = build_exception exception
          end

          if (log = error.log)
            base[:log] = build_log log
          end

          { error: base }
        end
        # rubocop:enable Metrics/MethodLength

        private

        def build_exception(exception)
          {
            message: exception.message,
            type: exception.type,
            module: exception.module,
            code: exception.code,
            attributes: exception.attributes,
            stacktrace: exception.stacktrace.to_a,
            handled: exception.handled
          }
        end

        def build_log(log)
          {
            message: log.message,
            level: log.level,
            logger_name: log.logger_name,
            param_message: log.param_message,
            stacktrace: log.stacktrace.to_a
          }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elastic-apm-2.0.1 lib/elastic_apm/transport/serializers/error_serializer.rb
elastic-apm-2.0.0 lib/elastic_apm/transport/serializers/error_serializer.rb