Sha256: d36e07e346aaff84c9d17a37b3550b9d087a895568dc24064b75f8c961d24ec4

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

# 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 64 bit uuid
      def generate_guid
        guid = ''
        GUID_LENGTH.times do |a|
          guid << HEX_DIGITS[rand(16)]
        end
        guid
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oneapm_rpm-1.3.7 lib/one_apm/transaction/instance_helpers.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/transaction/instance_helpers.rb