Module: TemplateStreaming::NewRelic::TransactionSampler

Defined in:
lib/template_streaming/new_relic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



402
403
404
# File 'lib/template_streaming/new_relic.rb', line 402

def self.included(base)
  base.alias_method_chain :notice_scope_empty, :template_streaming
end

Instance Method Details

#finish_accumulatingObject



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/template_streaming/new_relic.rb', line 410

def finish_accumulating
  supersample = merge_accumulated_samples or
    return nil
  @accumulated_samples = nil

  # Taken from TransactionSampler#notice_scope_empty.
  @samples_lock.synchronize do
    @last_sample = supersample

    @random_sample = @last_sample if @random_sampling

    # ensure we don't collect more than a specified number of samples in memory
    @samples << @last_sample if ::NewRelic::Control.instance.developer_mode?
    @samples.shift while @samples.length > @max_samples

    if @slowest_sample.nil? || @slowest_sample.duration < @last_sample.duration
      @slowest_sample = @last_sample
    end
  end
end

#notice_scope_empty_with_template_streaming(time = Time.now.to_f) ⇒ Object



431
432
433
434
435
436
437
438
439
440
441
# File 'lib/template_streaming/new_relic.rb', line 431

def notice_scope_empty_with_template_streaming(time=Time.now.to_f)
  if @accumulated_samples
    last_builder = builder or
      return
    last_builder.finish_trace(time)
    @accumulated_samples << last_builder.sample
    clear_builder
  else
    notice_scope_empty_without_template_streaming(time)
  end
end

#start_accumulatingObject



406
407
408
# File 'lib/template_streaming/new_relic.rb', line 406

def start_accumulating
  @accumulated_samples = []
end