Class: Datadog::Tracing::Configuration::Dynamic::SimpleOption

Inherits:
Option
  • Object
show all
Defined in:
lib/datadog/tracing/configuration/dynamic/option.rb

Overview

A dynamic configuration option that can directly mapped to a ‘Datadog.configuration` option and changing such option is the only requirement to apply the configuration locally.

Instance Attribute Summary

Attributes inherited from Option

#env_var, #name

Instance Method Summary collapse

Constructor Details

#initialize(name, env_var, setting_key) ⇒ SimpleOption

DEV: ‘Datadog.configuration` cannot be an argument default value because DEV: it is dynamic. Also, it is not yet declared when this method is parsed by Ruby.

Parameters:

  • name (String)

    dynamic configuration option name. This must match the remote configuration payload.

  • env_var (String)

    the canonical environment variable that represents this option. This is used for telemetry reporting.

  • setting_key (Symbol)

    option from ‘Datadog.configuration.tracing` that will be modified



35
36
37
38
# File 'lib/datadog/tracing/configuration/dynamic/option.rb', line 35

def initialize(name, env_var, setting_key)
  super(name, env_var)
  @setting_key = setting_key
end

Instance Method Details

#call(value) ⇒ Object

Reconfigures the provided option, setting its value to ‘value`.

Parameters:

  • value (Object, nil)

    the new value for this option



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/tracing/configuration/dynamic/option.rb', line 43

def call(value)
  Datadog.logger.debug { "Reconfigured tracer option `#{@setting_key}` with value `#{value}`" }

  if value.nil?
    # Restore the local configuration value
    configuration_object.unset_option(
      @setting_key,
      precedence: Core::Configuration::Option::Precedence::REMOTE_CONFIGURATION
    )
  else
    configuration_object.set_option(
      @setting_key,
      value,
      precedence: Core::Configuration::Option::Precedence::REMOTE_CONFIGURATION
    )
  end
end