Sha256: 5a340ed8fd97f4c74712d8edad31a3669eb1cfadcaef13587af4e91ff3419835

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8
require 'ting_yun/agent/transaction'
require 'ting_yun/agent/transaction/transaction_state'

TingYun::Support::LibraryDetection.defer do
  named :grape

  depends_on do
    defined?(::Grape) && defined?(::Grape::Endpoint)
  end

  executes do
    TingYun::Agent.logger.info 'Installing grape instrumentation'
  end


  executes do
    ::Grape::Endpoint.class_eval do
      def run_with_tingyun(*args)
        begin
          name = ["Grape",
                  self.options[:method].first,
                  self.options[:for].to_s,
                  self.namespace.sub(%r{\A/}, ''), # removing leading slashes
                  self.options[:path].first.sub(%r{\A/}, ''),
          ].compact.select{ |n| n.to_s unless n.to_s.empty? }.join("/")
          TingYun::Agent::Transaction.set_default_transaction_name(name, :controller)
          run_without_tingyun(*args)
        rescue => e
          TingYun::Agent.logger.info("Error getting Grape Endpoint Name. Error: #{e.message}. Options: #{self.options.inspect}")
        end

      end
      alias run_without_tingyun run
      alias run run_with_tingyun
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tingyun_rpm-1.4.2 lib/ting_yun/instrumentation/grape.rb
tingyun_rpm-1.4.1 lib/ting_yun/instrumentation/grape.rb
tingyun_rpm-1.3.1 lib/ting_yun/instrumentation/grape.rb
tingyun_rpm-1.3.0 lib/ting_yun/instrumentation/grape.rb