Sha256: f9ce5b4b35820ee0329193bf84eb53be3c2525ad5c1dbc73257fe4d46509e3e5

Contents?: true

Size: 1.06 KB

Versions: 34

Compression:

Stored size: 1.06 KB

Contents

module Honeybadger
  class Metric
    attr_reader :name, :attributes, :samples

    def self.metric_type
      name.split('::').last.downcase
    end

    def self.signature(metric_type, name, attributes)
      Digest::SHA1.hexdigest("#{metric_type}-#{name}-#{attributes.keys.join('-')}-#{attributes.values.join('-')}").to_sym
    end

    def self.register(registry, metric_name, attributes)
      registry.get(metric_type, metric_name, attributes) ||
        registry.register(new(metric_name, attributes))
    end

    def initialize(name, attributes)
      @name = name
      @attributes = attributes || {}
      @samples = 0
    end

    def metric_type
      self.class.metric_type
    end

    def signature
      self.class.signature(metric_type, name, attributes)
    end

    def base_payload
      attributes.merge({
        event_type: "metric.hb",
        metric_name: name,
        metric_type: metric_type,
        samples: samples
      })
    end

    def event_payloads
      payloads.map do |payload|
        base_payload.merge(payload)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
honeybadger-5.26.2 lib/honeybadger/metric.rb
honeybadger-5.26.1 lib/honeybadger/metric.rb
honeybadger-5.26.0 lib/honeybadger/metric.rb
honeybadger-5.25.0 lib/honeybadger/metric.rb
honeybadger-5.24.0 lib/honeybadger/metric.rb
honeybadger-5.23.0 lib/honeybadger/metric.rb
honeybadger-5.22.0 lib/honeybadger/metric.rb
honeybadger-5.21.0 lib/honeybadger/metric.rb
honeybadger-5.20.1 lib/honeybadger/metric.rb
honeybadger-5.20.0 lib/honeybadger/metric.rb
honeybadger-5.19.2 lib/honeybadger/metric.rb
honeybadger-5.19.1 lib/honeybadger/metric.rb
honeybadger-5.19.0 lib/honeybadger/metric.rb
honeybadger-5.18.0 lib/honeybadger/metric.rb
honeybadger-5.17.0 lib/honeybadger/metric.rb
honeybadger-5.16.0 lib/honeybadger/metric.rb
honeybadger-5.15.6 lib/honeybadger/metric.rb
honeybadger-5.15.5 lib/honeybadger/metric.rb
honeybadger-5.15.4 lib/honeybadger/metric.rb
honeybadger-5.15.3 lib/honeybadger/metric.rb