Class: Sentry::Metrics::LocalAggregator

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/metrics/local_aggregator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocalAggregator

Returns a new instance of LocalAggregator.



9
10
11
# File 'lib/sentry/metrics/local_aggregator.rb', line 9

def initialize
  @buckets = {}
end

Instance Attribute Details

#bucketsObject (readonly)

exposed only for testing



7
8
9
# File 'lib/sentry/metrics/local_aggregator.rb', line 7

def buckets
  @buckets
end

Instance Method Details

#add(key, value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sentry/metrics/local_aggregator.rb', line 13

def add(key, value)
  if @buckets[key]
    @buckets[key].add(value)
  else
    @buckets[key] = GaugeMetric.new(value)
  end
end

#to_hashObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sentry/metrics/local_aggregator.rb', line 21

def to_hash
  return nil if @buckets.empty?

  @buckets.map do |bucket_key, metric|
    type, key, unit, tags = bucket_key

    payload_key = "#{type}:#{key}@#{unit}"
    payload_value = {
      tags: deserialize_tags(tags),
      min: metric.min,
      max: metric.max,
      count: metric.count,
      sum: metric.sum
    }

    [payload_key, payload_value]
  end.to_h
end