Module: Datadog::OpenFeature::Configuration::Settings

Included in:
Core::Configuration::Settings
Defined in:
lib/datadog/open_feature/configuration.rb

Overview

A settings class for the OpenFeature component.

Constant Summary collapse

DEFAULT_POLL_INTERVAL_SECONDS =
30
DEFAULT_REQUEST_TIMEOUT_SECONDS =
5
DEFAULT_INITIALIZATION_TIMEOUT_MS =
30_000
MAX_REQUEST_TIMEOUT_SECONDS =
300
MAX_INITIALIZATION_TIMEOUT_MS =
2_147_483_647

Class Method Summary collapse

Class Method Details

.add_settings!(base) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/datadog/open_feature/configuration.rb', line 32

def self.add_settings!(base)
  base.class_eval do
    # Steep does not update `self` for this `class_eval` block.
    # @type self: Datadog::Core::Configuration::Base::_DslContext
    settings :open_feature do
      # Deprecated switch retained for existing Remote Configuration adopters.
      option :enabled do |o|
        o.type :bool
        o.env "DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED"
        o.default false
        o.after_set do |_, _, precedence|
          next if precedence == Core::Configuration::Option::Precedence::DEFAULT

          Datadog.logger.warn(
            "DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED is deprecated; use " \
            "DD_FEATURE_FLAGS_ENABLED and DD_FEATURE_FLAGS_CONFIGURATION_SOURCE instead",
          )
        end
      end

      # Opt-in gate for APM feature-flag span enrichment. When enabled,
      # the provider attaches `ffe_*` tags to the local root APM span on
      # finish. Distinct from `:enabled` (the provider gate) and off by
      # default so it can be rolled out independently.
      #
      # TODO: benchmark the per-span-finish overhead on a high-span-count
      # trace with this gate on before enabling it by default.
      option :span_enrichment_enabled do |o|
        o.type :bool
        o.env "DD_EXPERIMENTAL_FLAGGING_PROVIDER_SPAN_ENRICHMENT_ENABLED"
        o.default false
      end

      # Killswitch for the EVP `flagevaluation` emission path only. Default on; when
      # disabled the existing OTel `feature_flag.evaluations` metric is unaffected.
      option :evaluation_counts_enabled do |o|
        o.type :bool
        o.env "DD_FLAGGING_EVALUATION_COUNTS_ENABLED"
        o.default true
      end
    end

    settings :feature_flags do
      option :experimentation_opt_out_mode do |o|
        o.type :string
        o.env "DD_FEATURE_FLAGS_EXPERIMENTATION_OPT_OUT_MODE"
        o.default "disabled"
      end

      option :enabled do |o|
        o.type :bool
        o.env "DD_FEATURE_FLAGS_ENABLED"
        o.default true
      end

      option :evaluation_telemetry_per_subject_opt_out_enabled do |o|
        o.type :bool
        o.env "DD_FEATURE_FLAGS_EVALUATION_TELEMETRY_PER_SUBJECT_OPT_OUT_ENABLED"
        o.default false
      end

      # Sends exposure events to Datadog.
      option :exposures_datadog_logging_enabled do |o|
        o.type :bool
        o.env "DD_FEATURE_FLAGS_EXPOSURES_DATADOG_LOGGING_ENABLED"
        o.default true
      end

      option :configuration_source do |o|
        o.type :string
        o.env "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE"
        o.default "agentless"
        o.setter do |value|
          value.to_s.strip.downcase
        end
      end

      settings :agentless do
        option :base_url do |o|
          o.type :string, nilable: true
          o.env "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL"
          o.skip_telemetry true
          o.setter do |value|
            next unless value

            stripped_value = value.to_s.strip
            stripped_value.empty? ? nil : stripped_value
          end
        end

        option :poll_interval_seconds do |o|
          Settings.configure_integer_option(
            o,
            environment_variable: "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_POLL_INTERVAL_SECONDS",
            default: Settings::DEFAULT_POLL_INTERVAL_SECONDS,
            setting_name: "Feature Flags agentless poll interval",
          )
          o.setter do |value|
            if value.is_a?(Integer) && value > 0
              value
            else
              Datadog.logger.warn(
                "Feature Flags agentless poll interval must be positive; using the default",
              )
              Settings::DEFAULT_POLL_INTERVAL_SECONDS
            end
          end
        end

        option :request_timeout_seconds do |o|
          Settings.configure_integer_option(
            o,
            environment_variable: "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_REQUEST_TIMEOUT_SECONDS",
            default: Settings::DEFAULT_REQUEST_TIMEOUT_SECONDS,
            setting_name: "Feature Flags agentless request timeout",
          )
          o.setter do |value|
            if value.is_a?(Integer) && value > 0 && value <= Settings::MAX_REQUEST_TIMEOUT_SECONDS
              value
            else
              Datadog.logger.warn(
                "Feature Flags agentless request timeout must be within (0, " \
                "#{Settings::MAX_REQUEST_TIMEOUT_SECONDS}]; using the default",
              )
              Settings::DEFAULT_REQUEST_TIMEOUT_SECONDS
            end
          end
        end
      end

      option :initialization_timeout_ms do |o|
        Settings.configure_integer_option(
          o,
          environment_variable: "DD_EXPERIMENTAL_FLAGGING_PROVIDER_INITIALIZATION_TIMEOUT_MS",
          default: Settings::DEFAULT_INITIALIZATION_TIMEOUT_MS,
          setting_name: "Feature Flags provider initialization timeout",
        )
        o.setter do |value|
          if value.is_a?(Integer) && value > 0 && value <= Settings::MAX_INITIALIZATION_TIMEOUT_MS
            value
          else
            Datadog.logger.warn(
              "Feature Flags provider initialization timeout must be within (0, " \
              "#{Settings::MAX_INITIALIZATION_TIMEOUT_MS}]; using the default",
            )
            Settings::DEFAULT_INITIALIZATION_TIMEOUT_MS
          end
        end
      end
    end
  end
end

.configure_integer_option(option, environment_variable:, default:, setting_name:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/datadog/open_feature/configuration.rb', line 15

def self.configure_integer_option(option, environment_variable:, default:, setting_name:)
  option.type :int
  option.env environment_variable
  option.env_parser do |value|
    Integer(value, 10)
  rescue ArgumentError
    Datadog.logger.warn("#{setting_name} must be an integer; using the default")
    default
  end
  option.default default
end

.extended(base) ⇒ Object



27
28
29
30
# File 'lib/datadog/open_feature/configuration.rb', line 27

def self.extended(base)
  base = base.singleton_class unless base.is_a?(Class)
  add_settings!(base)
end