Sha256: ef8664b7b7e45705b6310d037ebcfd17aaf735dd4f5d01252694ec51b3921464

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module StatsD
  module Instrument
    module Helpers
      def capture_statsd_datagrams(client: nil, &block)
        client ||= StatsD.singleton_client
        client.capture(&block)
      end

      # For backwards compatibility
      alias_method :capture_statsd_calls, :capture_statsd_datagrams

      def self.add_tag(tags, key, value)
        tags = tags.dup || {}

        if tags.is_a?(String)
          tags = tags.empty? ? "#{key}:#{value}" : "#{tags},#{key}:#{value}"
        elsif tags.is_a?(Array)
          tags << "#{key}:#{value}"
        elsif tags.is_a?(Hash)
          tags[key] = value
        else
          raise ArgumentError, "add_tag only supports string, array or hash, #{tags.class} provided"
        end

        tags
      end

      def self.prefix_metric(metric_name, client: nil)
        client ||= StatsD.singleton_client
        client&.prefix ? "#{client.prefix}.#{metric_name}" : metric_name
      end

      def self.prefixed_metric?(metric_name, client: nil)
        client ||= StatsD.singleton_client
        return false unless client&.prefix

        metric_name =~ /\A#{Regexp.escape(client.prefix)}\./
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
statsd-instrument-3.5.9 lib/statsd/instrument/helpers.rb
statsd-instrument-3.5.8 lib/statsd/instrument/helpers.rb
statsd-instrument-3.5.7 lib/statsd/instrument/helpers.rb
statsd-instrument-3.5.6 lib/statsd/instrument/helpers.rb