class Datadog::Configuration::Settings

Global configuration settings for the trace library. rubocop:disable Metrics/ClassLength

Public Class Methods

new(*_) click to toggle source
Calls superclass method
# File lib/ddtrace/configuration/settings.rb, line 19
def initialize(*_)
  super

  # WORKAROUND: The values for services, version, and env can get set either directly OR as a side effect of
  # accessing tags (reading or writing). This is of course really confusing and error-prone, e.g. in an app
  # WITHOUT this workaround where you define `DD_TAGS=env:envenvtag,service:envservicetag,version:envversiontag`
  # and do:
  #
  # puts Datadog.configuration.instance_exec { "#{service} #{env} #{version}" }
  # Datadog.configuration.tags
  # puts Datadog.configuration.instance_exec { "#{service} #{env} #{version}" }
  #
  # the output will be:
  #
  # [empty]
  # envservicetag envenvtag envversiontag
  #
  # That is -- the proper values for service/env/version are only set AFTER something accidentally or not triggers
  # the resolution of the tags.
  # This is really confusing, error prone, etc, so calling tags here is a really hacky but effective way to
  # avoid this. I could not think of a better way of fixing this issue without massive refactoring of tags parsing
  # (so that the individual service/env/version get correctly set even from their tags values, not as a side
  # effect). Sorry :(
  tags
end

Public Instance Methods

logger=(logger) click to toggle source
# File lib/ddtrace/configuration/settings.rb, line 134
def logger=(logger)
  get_option(:logger).instance = logger
end
runtime_metrics(options = nil) click to toggle source

Backwards compatibility for configuring runtime metrics e.g. `c.runtime_metrics enabled: true`

# File lib/ddtrace/configuration/settings.rb, line 203
def runtime_metrics(options = nil)
  settings = get_option(:runtime_metrics)
  return settings if options.nil?

  # If options were provided (old style) then raise warnings and apply them:
  # TODO: Raise deprecation warning
  settings.enabled = options[:enabled] if options.key?(:enabled)
  settings.statsd = options[:statsd] if options.key?(:statsd)
  settings
end
tracer(options = nil) click to toggle source

Backwards compatibility for configuring tracer e.g. `c.tracer debug: true`

# File lib/ddtrace/configuration/settings.rb, line 348
def tracer(options = nil)
  settings = get_option(:tracer)
  return settings if options.nil?

  # If options were provided (old style) then raise warnings and apply them:
  options = options.dup

  if options.key?(:log)
    # TODO: Raise deprecation warning
    get_option(:logger).instance = options.delete(:log)
  end

  if options.key?(:tags)
    # TODO: Raise deprecation warning
    set_option(:tags, options.delete(:tags))
  end

  if options.key?(:env)
    # TODO: Raise deprecation warning
    set_option(:env, options.delete(:env))
  end

  if options.key?(:debug)
    # TODO: Raise deprecation warning
    get_option(:diagnostics).debug = options.delete(:debug)
  end

  if options.key?(:partial_flush)
    # TODO: Raise deprecation warning
    settings.partial_flush.enabled = options.delete(:partial_flush)
  end

  if options.key?(:min_spans_before_partial_flush)
    # TODO: Raise deprecation warning
    settings.partial_flush.min_spans_threshold = options.delete(:min_spans_before_partial_flush)
  end

  # Forward remaining options to settings
  options.each do |key, value|
    setter = :"#{key}="
    settings.send(setter, value) if settings.respond_to?(setter)
  end
end
tracer=(tracer) click to toggle source
# File lib/ddtrace/configuration/settings.rb, line 392
def tracer=(tracer)
  get_option(:tracer).instance = tracer
end