Class: OneApm::TransactionMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/transaction/transaction_metrics.rb

Constant Summary collapse

DEFAULT_PROC =
Proc.new { |hash, name| hash[name] = OneApm::Metrics::Stats.new }

Instance Method Summary collapse

Constructor Details

#initializeTransactionMetrics

Returns a new instance of TransactionMetrics.



12
13
14
15
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 12

def initialize
  @unscoped = Hash.new(&DEFAULT_PROC)
  @scoped   = Hash.new(&DEFAULT_PROC)
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 29

def [](key)
  @unscoped[key]
end

#_record_metrics(names, value, aux, target, &blk) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 41

def _record_metrics(names, value, aux, target, &blk)
  # This looks dumb, but we're avoiding an extra Array allocation.
  case names
  when Array
    names.each do |name|
      target[name].record(value, aux, &blk)
    end
  else
    target[names].record(value, aux, &blk)
  end
end

#each_scopedObject



37
38
39
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 37

def each_scoped
  @scoped.each { |name, stats| yield name, stats }
end

#each_unscopedObject



33
34
35
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 33

def each_unscoped
  @unscoped.each { |name, stats| yield name, stats }
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 25

def has_key?(key)
  @unscoped.has_key?(key)
end

#record_scoped(names, value = nil, aux = nil, &blk) ⇒ Object



17
18
19
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 17

def record_scoped(names, value=nil, aux=nil, &blk)
  _record_metrics(names, value, aux, @scoped, &blk)
end

#record_unscoped(names, value = nil, aux = nil, &blk) ⇒ Object



21
22
23
# File 'lib/one_apm/transaction/transaction_metrics.rb', line 21

def record_unscoped(names, value=nil, aux=nil, &blk)
  _record_metrics(names, value, aux, @unscoped, &blk)
end