# encoding: utf-8 module OneApm class Transaction module InstanceHelpers def agent OneApm::Manager.agent end def transaction_sampler agent.transaction_sampler end def sql_sampler agent.sql_sampler end def recording_web_transaction? web_category?(@category) end def web_category?(category) Transaction::OA_WEB_TRANSACTION_CATEGORIES.include?(category) end def similar_category?(category) web_category?(@category) == web_category?(category) end def queue_time @apdex_start ? @start_time - @apdex_start : 0 end def had_error? !notable_exceptions.empty? end def notable_exceptions @exceptions.keys.select do |exception| !agent.error_collector.error_is_ignored?(exception) end end def add_custom_parameters(p) if OneApm::Manager.config[:high_security] OneApm::Manager.logger.debug("Unable to add custom attributes #{p.keys.inspect} while in high security mode.") return end custom_parameters.merge!(p) end # For the current web transaction, return the path of the URI minus the host part and query string, or nil. def uri @uri ||= self.class.uri_from_request(@request) unless @request.nil? end # For the current web transaction, return the full referer, minus the host string, or nil. def referer @referer ||= self.class.referer_from_request(@request) end def custom_parameters @custom_parameters ||= {} end HEX_DIGITS = (0..15).map{|i| i.to_s(16)} GUID_LENGTH = 16 # generate a random 16 length uuid def generate_guid guid = '' GUID_LENGTH.times do |a| guid << HEX_DIGITS[rand(16)] end guid end end end end