Sha256: 32267b0d8be4b911a09033350f3d6fb82da02995d96fb0722a2007c25523af59

Contents?: true

Size: 859 Bytes

Versions: 8

Compression:

Stored size: 859 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, **kwargs, &blk|
          @emitted_values[meth][args[0]] << {
            args: args[1..-1],
            tags: kwargs.fetch(:tags, []),
            kwargs: kwargs,
          }

          super(*args, **kwargs, &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

8 entries across 8 versions & 1 rubygems

Version Path
instrument_all_the_things-1.1.1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.1.0 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.0.4 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.0.3 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.0.2 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-1.0.1 lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-0.9.1.alpha lib/instrument_all_the_things/testing/stat_tracker.rb
instrument_all_the_things-0.9.0.alpha lib/instrument_all_the_things/testing/stat_tracker.rb