class TingYun::Agent::Transaction

web transaction

Constants

BACKGROUND_PREFIX
CABLE_PREFIX
CONTROLLER_PREFIX
COSS_CONTROLLER_PREFIX
EMPTY_SUMMARY_METRICS
GRAPE_PREFIX
MIDDLEWARE_PREFIX
MIDDLEWARE_SUMMARY_METRICS
NESTED_TRACE_STOP_OPTIONS
RACK_PREFIX
RAKE_PREFIX
RAKE_TRANSACTION_PREFIX
SINATRA_PREFIX
SUBTRANSACTION_PREFIX
TASK_PREFIX
TRACE_OPTIONS_SCOPED
TRACE_OPTIONS_UNSCOPED

Attributes

apdex[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

attributes[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

base_quantile_hash[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

category[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

default_name[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

exceptions[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

frame_stack[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

guid[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

metrics[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

request_attributes[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

start_time[R]

A Time instance used for calculating the apdex score, which might end up being @start, or it might be further upstream if we can find a request header for the queue entry time

Public Class Methods

new(category, client_transaction_id, options) click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 69
def initialize(category, client_transaction_id, options)
  @start_time = Time.now.to_f
  @exceptions = TingYun::Agent::Transaction::Exceptions.new
  @metrics = TingYun::Agent::TransactionMetrics.new
  @attributes = TingYun::Agent::Transaction::Attributes.new
  @apdex = TingYun::Agent::Transaction::Apdex.new(options[:apdex_start_time], @start_time)

  @has_children = false
  @category = category
  @is_mq = options[:mq] || false

  @guid = client_transaction_id || generate_guid
  @frame_stack = []
  @frozen_name = nil
  @base_quantile_hash = {}
  @default_name = TingYun::Helper.correctly_encoded(options[:transaction_name])

  if request = options[:request]
    @request_attributes = TingYun::Agent::Transaction::RequestAttributes.new request
    @attributes.merge_request_header(@request_attributes.header.select{|k,v|k.start_with?("HTTP")})
  else
    @request_attributes = nil
  end
end

Public Instance Methods

commit(state, end_time, outermost_node_name) click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 170
def commit(state, end_time, outermost_node_name)

  assign_agent_attributes(state)


  TingYun::Agent.instance.transaction_sampler.on_finishing_transaction(state, self, end_time,@exceptions)

  TingYun::Agent.instance.sql_sampler.on_finishing_transaction(state, @frozen_name)
  #
  # record_summary_metrics(state, outermost_node_name, end_time) unless @exceptions.had_error?
  # @apdex.record_apdex(@frozen_name, end_time, @exceptions.had_error?)
  # @exceptions.record_exceptions(@attributes)
  #
  #
  # TingYun::Agent.instance.stats_engine.merge_transaction_metrics!(@metrics, best_name)
  # TingYun::Agent.instance.stats_engine.record_base_quantile(@base_quantile_hash) unless @exceptions.had_error?
end
commitV2(state, end_time, outermost_node_name) click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 152
def commitV2(state, end_time, outermost_node_name)

  assign_agent_attributes(state)


  TingYun::Agent.instance.transaction_sampler.on_finishing_transaction(state, self, end_time,@exceptions)

  TingYun::Agent.instance.sql_sampler.on_finishing_transaction(state, @frozen_name)

  record_summary_metrics(state, outermost_node_name, end_time) unless @exceptions.had_error?
  @apdex.record_apdex(@frozen_name, end_time, @exceptions.had_error?)
  @exceptions.record_exceptions(@attributes)


  TingYun::Agent.instance.stats_engine.merge_transaction_metrics!(@metrics, best_name)
  TingYun::Agent.instance.stats_engine.record_base_quantile(@base_quantile_hash) unless @exceptions.had_error?
end
frozen_name=(name) click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 102
def frozen_name=(name)
  @frozen_name = name
end
request_path() click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 94
def request_path
  @request_attributes && @request_attributes.request_path
end
request_port() click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 98
def request_port
  @request_attributes && @request_attributes.port
end
start(state) click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 106
def start(state)
  return if !state.execution_traced?
  ::TingYun::Agent.instance.events.notify(:start_transaction) # Dispatcher调用

  ::TingYun::Agent::Collector::TransactionSampler.on_start_transaction(state, start_time)
  ::TingYun::Agent::Collector::SqlSampler.on_start_transaction(state, request_path)

  frame_stack.push TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_header(state, Time.now.to_f)
  name_last_frame @default_name
  freeze_name_and_execute if @default_name.start_with?(RAKE_TRANSACTION_PREFIX)
end
stop(state, end_time, outermost_frame, summary_metrics = []) click to toggle source
# File lib/ting_yun/agent/transaction.rb, line 121
def stop(state, end_time, outermost_frame, summary_metrics = [])
  freeze_name_and_execute

  if @has_children or @is_mq
    name = Transaction.nested_transaction_name(outermost_frame.name)
    trace_options = TRACE_OPTIONS_SCOPED
  else
    name = @frozen_name
    trace_options = TRACE_OPTIONS_UNSCOPED
  end

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

  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_footer(
      state,
      start_time,
      name,
      EMPTY_SUMMARY_METRICS,
      outermost_frame,
      trace_options,
      end_time)

  commit(state, end_time, name)
end