module TingYun::Agent::Transaction::ClassMethod

web transaction

Public Instance Methods

metrics() click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 13
def metrics
  txn = tl_current
  txn && txn.metrics
end
nested_transaction_name(name) click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 117
def nested_transaction_name(name)
  if name.start_with?(CONTROLLER_PREFIX) || name.start_with?(BACKGROUND_PREFIX)
    "#{SUBTRANSACTION_PREFIX}#{name}"
  else
    name
  end
end
notice_error(e, options={}) click to toggle source

See TingYun::Agent.notice_error for options and commentary

# File lib/ting_yun/agent/transaction/class_method.rb, line 25
def notice_error(e, options={})
  state = TingYun::Agent::TransactionState.tl_get
  txn = state.current_transaction
  if txn
    txn.exceptions.notice_error(e, options)
    state.transaction_sample_builder.trace.add_errors_to_current_node(state,e) rescue nil
  elsif TingYun::Agent.instance
    TingYun::Agent.instance.error_collector.notice_error(e, options)
  end
end
recording_web_transaction?() click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 19
def recording_web_transaction? #THREAD_LOCAL_ACCESS
  txn = tl_current
  txn && txn.web_category?(txn.category)
end
set_default_transaction_name(name, category = nil, node_name = nil) click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 125
def set_default_transaction_name(name, category = nil, node_name = nil) #THREAD_LOCAL_ACCESS
  txn  = tl_current
  name = txn.make_transaction_name(name, category)
  txn.name_last_frame(node_name || name)
  txn.set_default_transaction_name(name, category)
end
set_frozen_transaction_name!(name) click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 132
def set_frozen_transaction_name!(name) #THREAD_LOCAL_ACCESS
  txn  = tl_current
  txn.frozen_name = name
end
start(state, category, options) click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 97
def start(state, category, options)
  category ||= :controller
  txn = state.current_transaction
  if txn
    txn.create_nested_frame(state, category, options)
  else
    txn = start_new_transaction(state, category, options)
  end
  txn
rescue => e
  TingYun::Agent.logger.error("Exception during Transaction.start", e)
end
start_new_transaction(state, category, options) click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 110
def start_new_transaction(state, category, options)
  txn = Transaction.new(category, state.client_transaction_id, options)
  state.reset(txn)
  txn.start(state)
  txn
end
stop(state, end_time = Time.now.to_f, summary_metric_names=[]) click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 37
def stop(state, end_time = Time.now.to_f, summary_metric_names=[])

  txn = state.current_transaction

  unless txn
    TingYun::Agent.logger.error("Failed during Transaction.stop because there is no current transaction")
    return
  end

  nested_frame = txn.frame_stack.pop

  if txn.frame_stack.empty?
    txn.stop(state, end_time, nested_frame, summary_metric_names)
    state.reset
    TingYun::Agent.upload
  else
    nested_name = Transaction.nested_transaction_name nested_frame.name

    # if nested_name.start_with?(MIDDLEWARE_PREFIX)
    #   summary_metrics = MIDDLEWARE_SUMMARY_METRICS
    # else
    #   summary_metrics = EMPTY_SUMMARY_METRICS
    # end
    # summary_metrics = summary_metric_names unless summary_metric_names.empty?

    TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_footer(
        state,
        nested_frame.start_time,
        nested_name,
        EMPTY_SUMMARY_METRICS,
        nested_frame,
        NESTED_TRACE_STOP_OPTIONS,
        end_time)

  end

  :transaction_stopped
rescue => e
  state.reset
  TingYun::Agent.logger.error("Exception during Transaction.stop", e)
  nil
end
tl_current() click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 9
def tl_current
  TingYun::Agent::TransactionState.tl_get.current_transaction
end
wrap(state, name, category, options = {}, summary_metrics=[]) { || ... } click to toggle source
# File lib/ting_yun/agent/transaction/class_method.rb, line 80
def wrap(state, name, category, options = {}, summary_metrics=[])
  Transaction.start(state, category, options.merge(:transaction_name => name))

  begin
    # We shouldn't raise from Transaction.start, but only wrap the yield
    # to be absolutely sure we don't report agent problems as app errors
    yield
  rescue => e
    ::TingYun::Agent.notice_error(e,:type=> :exception)
    raise e
  ensure
    # when kafka consumer in task, drop original web_action
    Transaction.stop(state, Time.now.to_f, summary_metrics) if state.current_transaction
  end
end