class TingYun::Agent::Collector::TransactionSampler

Attributes

last_sample[RW]

Public Class Methods

new() click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 19
def initialize
  @lock = Mutex.new
  @sample_buffers = []
  @sample_buffers << TingYun::Agent::Collector::TransactionSampler::SlowestSampleBuffer.new
end

Public Instance Methods

harvest!() click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 25
def harvest!
  return [] unless TingYun::Agent.config[:'action_tracer.enabled']

  samples = @lock.synchronize do
    @last_sample = nil
    harvest_from_sample_buffers
  end

  prepare_samples(samples)
end
harvest_from_sample_buffers() click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 35
def harvest_from_sample_buffers
  result = []
  @sample_buffers.each { |buffer| result.concat(buffer.harvest_samples) }
  result.uniq
end
merge!(previous) click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 52
def merge!(previous)
  @lock.synchronize do
    @sample_buffers.each do |buffer|
      buffer.store_previous(previous)
    end
  end
end
on_finishing_transaction(state, txn, time=Time.now.to_f, exceptions) click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 65
def on_finishing_transaction(state, txn, time=Time.now.to_f, exceptions)

  last_builder = state.transaction_sample_builder
  return unless last_builder && TingYun::Agent.config[:'action_tracer.enabled']

  last_builder.finish_trace(time)

  final_trace = last_builder.trace
  final_trace.attributes = txn.attributes
  final_trace.array_size = exceptions.errors_and_exceptions
  final_trace.add_errors(exceptions.errors.keys)


  @lock.synchronize do
    @last_sample = final_trace

    store_sample(@last_sample)
    @last_sample
  end
end
prepare_samples(samples) click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 40
def prepare_samples(samples)
  samples.select do |sample|
    begin
      sample.prepare_to_send!
    rescue => e
      TingYun::Agent.logger.error('Failed to prepare transaction trace. Error: ', e)
      false
    else
      true
    end
  end
end
reset!() click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 59
def reset!
  @lock.synchronize do
    @sample_buffers.each { |sample| sample.reset! }
  end
end
store_sample(sample) click to toggle source
# File lib/ting_yun/agent/collector/transaction_sampler.rb, line 85
def store_sample(sample)
  @sample_buffers.each do |sample_buffer|
    sample_buffer.store(sample)
  end
end