Sha256: 29be68899d67dbcedd2eb8866194d9b4baf00168de13f42d70d7aac307621193

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

module DDTelemetry
  class Metric
    include Enumerable

    def initialize
      @basic_metrics = {}
    end

    def get(label)
      basic_metric_for(label, BasicCounter)
    end

    def labels
      @basic_metrics.keys
    end

    def each
      @basic_metrics.each_key do |label|
        yield(label, get(label))
      end
    end

    # @api private
    def basic_metric_for(label, basic_class)
      @basic_metrics.fetch(label) { @basic_metrics[label] = basic_class.new }
    end

    # @api private
    def validate_label(label)
      return if label.is_a?(Hash)
      raise ArgumentError, 'label argument must be a hash'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddtelemetry-1.0.0a3 lib/ddtelemetry/metric.rb