Sha256: d4b80a606f5785a21e3c37a742c6bfbb8d850753c0986f4cd4fa2c7d1cdffd12

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

require 'datadog/statsd'

module InstrumentAllTheThings
  module Testing
    class StatTracker < Clients::StatReporter::DataDog
      attr_reader :emitted_values
      %i[
      count
      distribution
      gauge
      histogram
      set
      time
      timing
      ].each do |meth|
        define_method(meth) do |*args, &blk|
          opts = args.last.is_a?(Hash) ? args.last : {}
          @emitted_values[meth][args[0]] << {
            args: args[1..-1],
            tags: opts.fetch(:tags, []),
          }

          super(*args, &blk)
        end
      end

      def initialize(*args, **kwargs, &blk)
        super
        reset!
      end

      def reset!
        @emitted_values = Hash.new do |h, k|
          h[k] = Hash.new do |h2, k2|
            h2[k2] = []
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
instrument_all_the_things-1.2.0 lib/instrument_all_the_things/testing/stat_tracker.rb