Sha256: 622828dfebef0bb7780738fa160da9226e7a5ca3808e93f13964604363e9ec40

Contents?: true

Size: 1.71 KB

Versions: 16

Compression:

Stored size: 1.71 KB

Contents

module  AppOpticsAPM
  module API
    module Metrics

      ##
      # Internal: method to send duration for a transaction
      # it checks if it can send metrics with the current transaction name
      # or a default transaction name and sets the transaction name accordingly
      #
      # === Arguments:
      #
      # * +span+ the name of the current span (used to construct a transaction name if none is defined)
      # * +kvs+ A hash containing key/value pairs, only the value of :TransactionName will be relevant
      #
      # === Returns:
      # The result of the block.
      #
      # === Assigns:
      # The transaction_name to kvs[:TransactionName]

      def send_metrics(span, kvs)
        start = Time.now
        yield
      ensure
        duration = (1000 * 1000 * (Time.now - start)).to_i
        transaction_name = determine_transaction_name(span, kvs)
        kvs[:TransactionName] = AppOpticsAPM::Span.createSpan(transaction_name, nil, duration)
        AppOpticsAPM.transaction_name = nil
      end

      private

      ##
      # Determine the transaction name to be set on the trace.
      #
      # === Argument:
      # * +span+ the name of the current span (used to construct a transaction name if none is defined)
      # * +kvs+ (hash, optional) the hash that may have values for 'Controller' and 'Action'
      #
      # === Returns:
      # (string) the determined transaction name
      #
      def determine_transaction_name(span, kvs = {})
        if AppOpticsAPM.transaction_name
          AppOpticsAPM.transaction_name
        elsif kvs['Controller'] && kvs['Action']
          [kvs['Controller'], kvs['Action']].join('.')
        else
          "custom-#{span}"
        end
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
appoptics_apm-4.11.1 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.11.0 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.10.1 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.10.0 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.9.0 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.8.4 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.8.3 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.8.2 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.8.1 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.8.0 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.7.0 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.6.0 lib/appoptics_apm/api/metrics.rb
appoptics_apm_mnfst-4.5.2 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.5.2 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.5.1 lib/appoptics_apm/api/metrics.rb
appoptics_apm-4.5.0 lib/appoptics_apm/api/metrics.rb