Sha256: eb2869d5557450736b6057f0f6644ed20b9fd5cf22ae57f46b6de652b88a1aaf

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

module OneApm
  class TransactionNamer

    def self.name_for(txn, traced_obj, category, options={})
      "#{prefix_for_category(txn, category)}#{path_name(traced_obj, options)}"
    end

    def self.prefix_for_category(txn, category = nil)
      category ||= (txn && txn.category)
      case category
      when :controller then ::OneApm::Transaction::OA_WEB_TRANSACTION_PREFIX
      when :task       then ::OneApm::Transaction::OA_TASK_PREFIX
      when :rack       then ::OneApm::Transaction::OA_RACK_PREFIX
      when :uri        then ::OneApm::Transaction::OA_WEB_TRANSACTION_PREFIX
      when :sinatra    then ::OneApm::Transaction::OA_SINATRA_PREFIX
      when :middleware then ::OneApm::Transaction::OA_MIDDLEWARE_PREFIX
      when :grape      then ::OneApm::Transaction::OA_GRAPE_PREFIX
      else "#{category.to_s}/" # for internal use only
      end
    end

    def self.path_name(traced_obj, options={})
      return options[:path] if options[:path]

      class_name = class_name(traced_obj, options)
      if options[:name]
        if class_name
          "#{class_name}/#{options[:name]}"
        else
          options[:name]
        end
      elsif traced_obj.respond_to?(:oneapm_metric_path)
        traced_obj.oneapm_metric_path
      else
        class_name
      end
    end

    def self.class_name(traced_obj, options={})
      return options[:class_name] if options[:class_name]
      if (traced_obj.is_a?(Class) || traced_obj.is_a?(Module))
        traced_obj.name
      else
        traced_obj.class.name
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/transaction/transaction_namer.rb
oneapm_rpm-1.4.1 lib/one_apm/transaction/transaction_namer.rb
oneapm_rpm-1.4.0 lib/one_apm/transaction/transaction_namer.rb
oneapm_rpm-1.3.7 lib/one_apm/transaction/transaction_namer.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/transaction/transaction_namer.rb