Class: Datadog::Configuration::Settings

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/ddtrace/configuration/settings.rb

Overview

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

Instance Method Summary collapse

Methods included from Base

included

Constructor Details

#initialize(*_) ⇒ Settings

Returns a new instance of Settings.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Method Details

#logger=(logger) ⇒ Object



134
135
136
# File 'lib/ddtrace/configuration/settings.rb', line 134

def logger=(logger)
  get_option(:logger).instance = logger
end

#runtime_metrics(options = nil) ⇒ Object

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



213
214
215
216
217
218
219
220
221
222
# File 'lib/ddtrace/configuration/settings.rb', line 213

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) ⇒ Object

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



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/ddtrace/configuration/settings.rb', line 358

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) ⇒ Object



402
403
404
# File 'lib/ddtrace/configuration/settings.rb', line 402

def tracer=(tracer)
  get_option(:tracer).instance = tracer
end