Module: Datadog::Core::Metrics::Options

Included in:
Client, Client
Defined in:
lib/datadog/core/metrics/options.rb

Overview

For defining and adding default options to metrics

Constant Summary collapse

DEFAULT =
{
  tags: DEFAULT_TAGS = [
    "#{Ext::TAG_LANG}:#{Environment::Identity.lang}".freeze,
    "#{Ext::TAG_LANG_INTERPRETER}:#{Environment::Identity.lang_interpreter}".freeze,
    "#{Ext::TAG_LANG_VERSION}:#{Environment::Identity.lang_version}".freeze,
    "#{Ext::TAG_TRACER_VERSION}:#{Environment::Identity.tracer_version}".freeze
  ].freeze
}.freeze

Instance Method Summary collapse

Instance Method Details

#default_metric_optionsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/datadog/core/metrics/options.rb', line 32

def default_metric_options
  # Return dupes, so that the constant isn't modified,
  # and defaults are unfrozen for mutation in Statsd.
  DEFAULT.dup.tap do |options|
    options[:tags] = options[:tags].dup

    env = Datadog.configuration.env
    options[:tags] << "#{Environment::Ext::TAG_ENV}:#{env}" unless env.nil?

    version = Datadog.configuration.version
    options[:tags] << "#{Environment::Ext::TAG_VERSION}:#{version}" unless version.nil?
  end
end

#metric_options(options = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/datadog/core/metrics/options.rb', line 19

def metric_options(options = nil)
  return default_metric_options if options.nil?

  default_metric_options.merge(options) do |key, old_value, new_value|
    case key
    when :tags
      old_value.dup.concat(new_value).uniq
    else
      new_value
    end
  end
end