# encoding: utf-8 module OneApm class EventAnalyticData include OneApm::Coerce OA_ERROR_ALL_KEY = 'Errors/all'.freeze attr_reader :start_time, :guid, :refer_guid, :trip_guid, :call_count, :duration attr_reader :errors, :apdex, :request_url, :bytes_sent, :bytes_rec, :has_trace, :exec_time, :call_type def initialize(payload = {}) @start_time = payload[:start_timestamp].to_f * 1000 @guid = payload[:guid] @refer_guid = payload[:referring_transaction_guid] @trip_guid = payload[:cat_trip_id] || @refer_guid || @guid @call_count = payload[:call_count] || 1 @duration = payload[:duration] @errors = error_times(payload[:metrics]) @apdex = payload[:apdex_perf_zone] @request_url = payload[:request_url] @bytes_sent = 0 @bytes_rec = 0 @has_trace = apdex != Transaction::OA_APDEX_S ? 1 : 0 @exec_time = payload[:duration] @call_type = 0 # 0: syn , 1: asyn end def error_times(txn_metrics) return txn_metrics[OA_ERROR_ALL_KEY].call_count if txn_metrics.has_key?(OA_ERROR_ALL_KEY) rescue 0 return 0 end def to_collector_array(encoder = nil) [ start_time, guid, refer_guid, trip_guid, call_count, duration, errors, apdex, request_url, bytes_sent, bytes_rec, has_trace, exec_time, call_type ] end end end