Sha256: bf45bff4c119d421280ec6a5866a5c69a38d623fbb76c19683a4e168c1048750

Contents?: true

Size: 878 Bytes

Versions: 16

Compression:

Stored size: 878 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..],
            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

16 entries across 16 versions & 1 rubygems

Version Path
instrument_all_the_things-5.0.1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-5.0.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.4.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-4.0.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.1.2 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.1.2.pre1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.1.1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.1.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.1.0.pre1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.0.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-3.0.0.pre1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-2.0.2 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-2.0.1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-2.0.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.3.1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.3.0 lib/instrument_all_the_things/testing/stat_tracker.rb