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.15.2 lib/honeybadger/metric.rb
honeybadger-5.15.1 lib/honeybadger/metric.rb
honeybadger-5.15.0 lib/honeybadger/metric.rb
honeybadger-5.14.2 lib/honeybadger/metric.rb
honeybadger-5.14.1 lib/honeybadger/metric.rb
honeybadger-5.14.0 lib/honeybadger/metric.rb
honeybadger-5.13.3 lib/honeybadger/metric.rb
honeybadger-5.13.2 lib/honeybadger/metric.rb
honeybadger-5.13.1 lib/honeybadger/metric.rb
honeybadger-5.13.0 lib/honeybadger/metric.rb
honeybadger-5.12.0 lib/honeybadger/metric.rb
honeybadger-5.11.2 lib/honeybadger/metric.rb
honeybadger-5.11.1 lib/honeybadger/metric.rb
honeybadger-5.11.0 lib/honeybadger/metric.rb