Sha256: f81e8cb7f79ea51e14feb2dde4f005c267f8f904142144e287586e9f74d7bd55

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

require 'ting_yun/agent/transaction/transaction_state'
require 'ting_yun/instrumentation/support/transaction_namer'
require 'ting_yun/agent/transaction'
require 'ting_yun/agent'


module TingYun
  module Instrumentation
    module Support
      module ControllerInstrumentation

        NR_DEFAULT_OPTIONS    = {}.freeze          unless defined?(NR_DEFAULT_OPTIONS   )

        def perform_action_with_tingyun_trace (*args, &block)

          state = TingYun::Agent::TransactionState.tl_get

          state.request = self.request
          trace_options = args.last.is_a?(Hash) ? args.last : NR_DEFAULT_OPTIONS
          category = trace_options[:category] || :controller
          txn_options = create_transaction_options(trace_options, category, state)

          begin
             txn = TingYun::Agent::Transaction.start(state, category, txn_options)
            begin
              yield
            rescue => e
              ::TingYun::Agent.notice_error(e)
              raise
            end
          ensure
            TingYun::Agent::Transaction.stop(state)
          end
        end

        private

        def create_transaction_options(trace_options, category, state)
          txn_options = {}

          txn_options[:request] ||= request if respond_to?(:request)
          txn_options[:filtered_params] = trace_options[:params]
          txn_options[:transaction_name] = TingYun::Instrumentation::Support::TransactionNamer.name_for(nil, self, category, trace_options)
          txn_options[:apdex_start_time] = Time.now

          txn_options
        end
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tingyun_rpm-1.1.0 lib/ting_yun/instrumentation/support/controller_instrumentation.rb
tingyun_rpm-1.0.7 lib/ting_yun/instrumentation/support/controller_instrumentation.rb
tingyun_rpm-1.0.6 lib/ting_yun/instrumentation/support/controller_instrumentation.rb