Class: LaunchDarkly::Config
- Inherits:
-
Object
- Object
- LaunchDarkly::Config
- Defined in:
- lib/ldclient-rb/config.rb
Overview
This class exposes advanced configuration options for the LaunchDarkly client library. Most users will not need to use a custom configuration– the default configuration sets sane defaults for most use cases.
Instance Attribute Summary collapse
-
#all_attributes_private ⇒ Boolean
readonly
True if all context attributes (other than the key) should be considered private.
-
#application ⇒ Hash
readonly
An object that allows configuration of application metadata.
-
#base_uri ⇒ String
readonly
The base URL for the LaunchDarkly server.
-
#big_segments ⇒ BigSegmentsConfig
readonly
Configuration options related to Big Segments.
-
#cache_store ⇒ Object
readonly
A store for HTTP caching (used only in polling mode).
-
#capacity ⇒ Integer
readonly
The capacity of the events buffer.
-
#connect_timeout ⇒ Float
readonly
The connect timeout for network connections in seconds.
-
#context_keys_capacity ⇒ Integer
(also: #user_keys_capacity)
readonly
The number of context keys that the event processor can remember at any one time.
-
#context_keys_flush_interval ⇒ Float
(also: #user_keys_flush_interval)
readonly
The interval in seconds at which the event processor will reset its set of known context keys.
-
#data_source ⇒ LaunchDarkly::Interfaces::DataSource|lambda
readonly
An object that is responsible for receiving feature flag data from LaunchDarkly.
-
#diagnostic_recording_interval ⇒ Float
readonly
The interval at which periodic diagnostic data is sent, in seconds.
-
#events_uri ⇒ String
readonly
The base URL for the LaunchDarkly events server.
-
#feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore
readonly
A store for feature flags and related data.
-
#flush_interval ⇒ Float
readonly
The number of seconds between flushes of the event buffer.
-
#initial_reconnect_delay ⇒ Float
readonly
The initial delay before reconnecting after an error in the SSE client.
-
#logger ⇒ Logger
readonly
The configured logger for the LaunchDarkly client.
-
#poll_interval ⇒ Float
readonly
The number of seconds to wait before polling for feature flag updates.
-
#private_attributes ⇒ Array<String>
(also: #private_attribute_names)
readonly
A list of context attribute names that should always be considered private.
-
#read_timeout ⇒ Float
readonly
The read timeout for network connections in seconds.
-
#send_events ⇒ Boolean
readonly
Whether to send events back to LaunchDarkly.
-
#socket_factory ⇒ #open
readonly
The factory used to construct sockets for HTTP operations.
-
#stream_uri ⇒ String
readonly
The base URL for the LaunchDarkly streaming server.
-
#wrapper_name ⇒ String
readonly
For use by wrapper libraries to set an identifying name for the wrapper being used.
-
#wrapper_version ⇒ String
readonly
For use by wrapper libraries to report the version of the library in use.
Class Method Summary collapse
-
.default ⇒ Config
The default LaunchDarkly client configuration.
-
.default_base_uri ⇒ String
The default value for #base_uri.
-
.default_cache_store ⇒ Object
The default value for #cache_store.
-
.default_capacity ⇒ Integer
The default value for #capacity.
-
.default_connect_timeout ⇒ Float
The default value for #connect_timeout.
-
.default_context_keys_capacity ⇒ Integer
(also: default_user_keys_capacity)
The default value for #context_keys_capacity.
-
.default_context_keys_flush_interval ⇒ Float
(also: default_user_keys_flush_interval)
The default value for #context_keys_flush_interval.
-
.default_diagnostic_recording_interval ⇒ Float
The default value for #diagnostic_recording_interval.
-
.default_events_uri ⇒ String
The default value for #events_uri.
-
.default_feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore
The default value for #feature_store.
-
.default_flush_interval ⇒ Float
The default value for #flush_interval.
-
.default_initial_reconnect_delay ⇒ Float
The default value for #initial_reconnect_delay.
-
.default_logger ⇒ Logger
The default value for #logger.
-
.default_offline ⇒ Boolean
The default value for #offline?.
-
.default_poll_interval ⇒ Float
The default value for #poll_interval.
-
.default_read_timeout ⇒ Float
The default value for #read_timeout.
-
.default_send_events ⇒ Boolean
The default value for #send_events.
-
.default_stream ⇒ Boolean
The default value for #stream?.
-
.default_stream_uri ⇒ String
The default value for #stream_uri.
-
.default_use_ldd ⇒ Boolean
The default value for #use_ldd?.
-
.minimum_diagnostic_recording_interval ⇒ Float
The minimum value for #diagnostic_recording_interval.
Instance Method Summary collapse
-
#diagnostic_opt_out? ⇒ Boolean
Set to true to opt out of sending diagnostics data.
-
#initialize(opts = {}) ⇒ Config
constructor
Constructor for creating custom LaunchDarkly configurations.
-
#offline? ⇒ Boolean
Whether the client should be initialized in offline mode.
-
#stream? ⇒ Boolean
Whether streaming mode should be enabled.
-
#use_ldd? ⇒ Boolean
Whether to use the LaunchDarkly relay proxy in daemon mode.
Constructor Details
#initialize(opts = {}) ⇒ Config
Constructor for creating custom LaunchDarkly configurations.
‘user_keys_capacity` and `user_keys_flush_interval` are deprecated configuration options. They exist to maintain backwards compatibility with previous configurations. Newer code should prefer their replacement options – `context_keys_capacity` and `context_keys_flush_interval`.
In the event both the user and context variations are provided, the context specific configuration option will take precedence.
Similarly, ‘private_attribute_names` is deprecated. Newer code should prefer `private_attributes`. If both are provided, `private_attributes` will take precedence.
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 |
# File 'lib/ldclient-rb/config.rb', line 61 def initialize(opts = {}) @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/") @stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/") @events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/") @capacity = opts[:capacity] || Config.default_capacity @logger = opts[:logger] || Config.default_logger @cache_store = opts[:cache_store] || Config.default_cache_store @flush_interval = opts[:flush_interval] || Config.default_flush_interval @connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout @read_timeout = opts[:read_timeout] || Config.default_read_timeout @initial_reconnect_delay = opts[:initial_reconnect_delay] || Config.default_initial_reconnect_delay @feature_store = opts[:feature_store] || Config.default_feature_store @stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream @use_ldd = opts.has_key?(:use_ldd) ? opts[:use_ldd] : Config.default_use_ldd @offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline @poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > Config.default_poll_interval ? opts[:poll_interval] : Config.default_poll_interval @all_attributes_private = opts[:all_attributes_private] || false @private_attributes = opts[:private_attributes] || opts[:private_attribute_names] || [] @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events @context_keys_capacity = opts[:context_keys_capacity] || opts[:user_keys_capacity] || Config.default_context_keys_capacity @context_keys_flush_interval = opts[:context_keys_flush_interval] || opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval @data_source = opts[:data_source] @diagnostic_opt_out = opts.has_key?(:diagnostic_opt_out) && opts[:diagnostic_opt_out] @diagnostic_recording_interval = opts.has_key?(:diagnostic_recording_interval) && opts[:diagnostic_recording_interval] > Config.minimum_diagnostic_recording_interval ? opts[:diagnostic_recording_interval] : Config.default_diagnostic_recording_interval @wrapper_name = opts[:wrapper_name] @wrapper_version = opts[:wrapper_version] @socket_factory = opts[:socket_factory] @big_segments = opts[:big_segments] || BigSegmentsConfig.new(store: nil) @application = LaunchDarkly::Impl::Util.validate_application_info(opts[:application] || {}, @logger) end |
Instance Attribute Details
#all_attributes_private ⇒ Boolean (readonly)
True if all context attributes (other than the key) should be considered private. This means that the attribute values will not be sent to LaunchDarkly in analytics events and will not appear on the LaunchDarkly dashboard.
227 228 229 |
# File 'lib/ldclient-rb/config.rb', line 227 def all_attributes_private @all_attributes_private end |
#application ⇒ Hash (readonly)
An object that allows configuration of application metadata.
Application metadata may be used in LaunchDarkly analytics or other product features, but does not affect feature flag evaluations.
If you want to set non-default values for any of these fields, provide the appropriately configured hash to the LaunchDarkly::Config object.
331 332 333 |
# File 'lib/ldclient-rb/config.rb', line 331 def application @application end |
#base_uri ⇒ String (readonly)
The base URL for the LaunchDarkly server. This is configurable mainly for testing purposes; most users should use the default value.
98 99 100 |
# File 'lib/ldclient-rb/config.rb', line 98 def base_uri @base_uri end |
#big_segments ⇒ BigSegmentsConfig (readonly)
Configuration options related to Big Segments.
Big Segments are a specific type of segments. For more information, read the LaunchDarkly documentation: docs.launchdarkly.com/home/users/big-segments
313 314 315 |
# File 'lib/ldclient-rb/config.rb', line 313 def big_segments @big_segments end |
#cache_store ⇒ Object (readonly)
A store for HTTP caching (used only in polling mode). This must support the semantics used by the [‘faraday-http-cache`](github.com/plataformatec/faraday-http-cache) gem, although the SDK no longer uses Faraday. Defaults to the Rails cache in a Rails environment, or a thread-safe in-memory store otherwise.
187 188 189 |
# File 'lib/ldclient-rb/config.rb', line 187 def cache_store @cache_store end |
#capacity ⇒ Integer (readonly)
The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded. Increasing the capacity means that events are less likely to be discarded, at the cost of consuming more memory.
178 179 180 |
# File 'lib/ldclient-rb/config.rb', line 178 def capacity @capacity end |
#connect_timeout ⇒ Float (readonly)
The connect timeout for network connections in seconds.
207 208 209 |
# File 'lib/ldclient-rb/config.rb', line 207 def connect_timeout @connect_timeout end |
#context_keys_capacity ⇒ Integer (readonly) Also known as: user_keys_capacity
The number of context keys that the event processor can remember at any one time. This reduces the amount of duplicate context details sent in analytics events.
265 266 267 |
# File 'lib/ldclient-rb/config.rb', line 265 def context_keys_capacity @context_keys_capacity end |
#context_keys_flush_interval ⇒ Float (readonly) Also known as: user_keys_flush_interval
The interval in seconds at which the event processor will reset its set of known context keys.
280 281 282 |
# File 'lib/ldclient-rb/config.rb', line 280 def context_keys_flush_interval @context_keys_flush_interval end |
#data_source ⇒ LaunchDarkly::Interfaces::DataSource|lambda (readonly)
An object that is responsible for receiving feature flag data from LaunchDarkly. By default, the client uses its standard polling or streaming implementation; this is customizable for testing purposes.
This may be set to either an object that conforms to Interfaces::DataSource, or a lambda (or Proc) that takes two parameters– SDK key and LaunchDarkly::Config– and returns such an object.
303 304 305 |
# File 'lib/ldclient-rb/config.rb', line 303 def data_source @data_source end |
#diagnostic_recording_interval ⇒ Float (readonly)
The interval at which periodic diagnostic data is sent, in seconds.
The default is 900 (every 15 minutes) and the minimum value is 60 (every minute).
352 353 354 |
# File 'lib/ldclient-rb/config.rb', line 352 def diagnostic_recording_interval @diagnostic_recording_interval end |
#events_uri ⇒ String (readonly)
The base URL for the LaunchDarkly events server. This is configurable mainly for testing purposes; most users should use the default value.
112 113 114 |
# File 'lib/ldclient-rb/config.rb', line 112 def events_uri @events_uri end |
#feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore (readonly)
A store for feature flags and related data. The client uses it to store all data received from LaunchDarkly, and uses the last stored data when evaluating flags. Defaults to InMemoryFeatureStore; for other implementations, see Integrations.
For more information, see [“Persistent data stores”](docs.launchdarkly.com/sdk/concepts/data-stores).
218 219 220 |
# File 'lib/ldclient-rb/config.rb', line 218 def feature_store @feature_store end |
#flush_interval ⇒ Float (readonly)
The number of seconds between flushes of the event buffer. Decreasing the flush interval means that the event buffer is less likely to reach capacity.
153 154 155 |
# File 'lib/ldclient-rb/config.rb', line 153 def flush_interval @flush_interval end |
#initial_reconnect_delay ⇒ Float (readonly)
The initial delay before reconnecting after an error in the SSE client. This only applies to the streaming connection.
201 202 203 |
# File 'lib/ldclient-rb/config.rb', line 201 def initial_reconnect_delay @initial_reconnect_delay end |
#logger ⇒ Logger (readonly)
The configured logger for the LaunchDarkly client. The client library uses the log to print warning and error messages. If not specified, this defaults to the Rails logger in a Rails environment, or stdout otherwise.
168 169 170 |
# File 'lib/ldclient-rb/config.rb', line 168 def logger @logger end |
#poll_interval ⇒ Float (readonly)
The number of seconds to wait before polling for feature flag updates. This option has no effect unless streaming is disabled.
160 161 162 |
# File 'lib/ldclient-rb/config.rb', line 160 def poll_interval @poll_interval end |
#private_attributes ⇒ Array<String> (readonly) Also known as: private_attribute_names
A list of context attribute names that should always be considered private. This means that the attribute values will not be sent to LaunchDarkly in analytics events and will not appear on the LaunchDarkly dashboard.
You can also specify the same behavior for an individual flag evaluation by providing the context object with a list of private attributes.
242 243 244 |
# File 'lib/ldclient-rb/config.rb', line 242 def private_attributes @private_attributes end |
#read_timeout ⇒ Float (readonly)
The read timeout for network connections in seconds. This does not apply to the streaming connection, which uses a longer timeout since the server does not send data constantly.
194 195 196 |
# File 'lib/ldclient-rb/config.rb', line 194 def read_timeout @read_timeout end |
#send_events ⇒ Boolean (readonly)
Whether to send events back to LaunchDarkly. This differs from #offline? in that it affects only the sending of client-side events, not streaming or polling for events from the server.
257 258 259 |
# File 'lib/ldclient-rb/config.rb', line 257 def send_events @send_events end |
#socket_factory ⇒ #open (readonly)
The factory used to construct sockets for HTTP operations. The factory must provide the method ‘open(uri, timeout)`. The `open` method must return a connected stream that implements the `IO` class, such as a `TCPSocket`.
Defaults to nil.
380 381 382 |
# File 'lib/ldclient-rb/config.rb', line 380 def socket_factory @socket_factory end |
#stream_uri ⇒ String (readonly)
The base URL for the LaunchDarkly streaming server. This is configurable mainly for testing purposes; most users should use the default value.
105 106 107 |
# File 'lib/ldclient-rb/config.rb', line 105 def stream_uri @stream_uri end |
#wrapper_name ⇒ String (readonly)
For use by wrapper libraries to set an identifying name for the wrapper being used.
This will be sent in User-Agent headers during requests to the LaunchDarkly servers to allow recording metrics on the usage of these wrapper libraries.
361 362 363 |
# File 'lib/ldclient-rb/config.rb', line 361 def wrapper_name @wrapper_name end |
#wrapper_version ⇒ String (readonly)
For use by wrapper libraries to report the version of the library in use.
If ‘wrapper_name` is not set, this field will be ignored. Otherwise the version string will be included in the User-Agent headers along with the `wrapper_name` during requests to the LaunchDarkly servers.
370 371 372 |
# File 'lib/ldclient-rb/config.rb', line 370 def wrapper_version @wrapper_version end |
Class Method Details
.default ⇒ Config
The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.
387 388 389 |
# File 'lib/ldclient-rb/config.rb', line 387 def self.default Config.new end |
.default_base_uri ⇒ String
The default value for #base_uri.
403 404 405 |
# File 'lib/ldclient-rb/config.rb', line 403 def self.default_base_uri "https://sdk.launchdarkly.com" end |
.default_cache_store ⇒ Object
The default value for #cache_store.
427 428 429 |
# File 'lib/ldclient-rb/config.rb', line 427 def self.default_cache_store defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new end |
.default_capacity ⇒ Integer
The default value for #capacity.
395 396 397 |
# File 'lib/ldclient-rb/config.rb', line 395 def self.default_capacity 10000 end |
.default_connect_timeout ⇒ Float
The default value for #connect_timeout.
459 460 461 |
# File 'lib/ldclient-rb/config.rb', line 459 def self.default_connect_timeout 2 end |
.default_context_keys_capacity ⇒ Integer Also known as: default_user_keys_capacity
The default value for #context_keys_capacity.
529 530 531 |
# File 'lib/ldclient-rb/config.rb', line 529 def self.default_context_keys_capacity 1000 end |
.default_context_keys_flush_interval ⇒ Float Also known as: default_user_keys_flush_interval
The default value for #context_keys_flush_interval.
537 538 539 |
# File 'lib/ldclient-rb/config.rb', line 537 def self.default_context_keys_flush_interval 300 end |
.default_diagnostic_recording_interval ⇒ Float
The default value for #diagnostic_recording_interval.
557 558 559 |
# File 'lib/ldclient-rb/config.rb', line 557 def self.default_diagnostic_recording_interval 900 end |
.default_events_uri ⇒ String
The default value for #events_uri.
419 420 421 |
# File 'lib/ldclient-rb/config.rb', line 419 def self.default_events_uri "https://events.launchdarkly.com" end |
.default_feature_store ⇒ LaunchDarkly::Interfaces::FeatureStore
The default value for #feature_store.
497 498 499 |
# File 'lib/ldclient-rb/config.rb', line 497 def self.default_feature_store InMemoryFeatureStore.new end |
.default_flush_interval ⇒ Float
The default value for #flush_interval.
435 436 437 |
# File 'lib/ldclient-rb/config.rb', line 435 def self.default_flush_interval 10 end |
.default_initial_reconnect_delay ⇒ Float
The default value for #initial_reconnect_delay.
451 452 453 |
# File 'lib/ldclient-rb/config.rb', line 451 def self.default_initial_reconnect_delay 1 end |
.default_logger ⇒ Logger
The default value for #logger.
467 468 469 470 471 472 473 474 475 |
# File 'lib/ldclient-rb/config.rb', line 467 def self.default_logger if defined?(Rails) && Rails.respond_to?(:logger) Rails.logger else log = ::Logger.new($stdout) log.level = ::Logger::WARN log end end |
.default_offline ⇒ Boolean
The default value for #offline?.
505 506 507 |
# File 'lib/ldclient-rb/config.rb', line 505 def self.default_offline false end |
.default_poll_interval ⇒ Float
The default value for #poll_interval.
513 514 515 |
# File 'lib/ldclient-rb/config.rb', line 513 def self.default_poll_interval 30 end |
.default_read_timeout ⇒ Float
The default value for #read_timeout.
443 444 445 |
# File 'lib/ldclient-rb/config.rb', line 443 def self.default_read_timeout 10 end |
.default_send_events ⇒ Boolean
The default value for #send_events.
521 522 523 |
# File 'lib/ldclient-rb/config.rb', line 521 def self.default_send_events true end |
.default_stream ⇒ Boolean
The default value for #stream?.
481 482 483 |
# File 'lib/ldclient-rb/config.rb', line 481 def self.default_stream true end |
.default_stream_uri ⇒ String
The default value for #stream_uri.
411 412 413 |
# File 'lib/ldclient-rb/config.rb', line 411 def self.default_stream_uri "https://stream.launchdarkly.com" end |
.default_use_ldd ⇒ Boolean
The default value for #use_ldd?.
489 490 491 |
# File 'lib/ldclient-rb/config.rb', line 489 def self.default_use_ldd false end |
.minimum_diagnostic_recording_interval ⇒ Float
The minimum value for #diagnostic_recording_interval.
565 566 567 |
# File 'lib/ldclient-rb/config.rb', line 565 def self.minimum_diagnostic_recording_interval 60 end |
Instance Method Details
#diagnostic_opt_out? ⇒ Boolean
Set to true to opt out of sending diagnostics data.
Unless ‘diagnostic_opt_out` is set to true, the client will send some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK improvements. These diagnostics consist of an initial payload containing some details of the SDK in use, the SDK’s configuration, and the platform the SDK is being run on, as well as periodic information on irregular occurrences such as dropped events.
342 343 344 |
# File 'lib/ldclient-rb/config.rb', line 342 def diagnostic_opt_out? @diagnostic_opt_out end |
#offline? ⇒ Boolean
Whether the client should be initialized in offline mode. In offline mode, default values are returned for all flags and no remote network requests are made.
144 145 146 |
# File 'lib/ldclient-rb/config.rb', line 144 def offline? @offline end |
#stream? ⇒ Boolean
Whether streaming mode should be enabled. Streaming mode asynchronously updates feature flags in real-time using server-sent events. Streaming is enabled by default, and should only be disabled on the advice of LaunchDarkly support.
120 121 122 |
# File 'lib/ldclient-rb/config.rb', line 120 def stream? @stream end |
#use_ldd? ⇒ Boolean
Whether to use the LaunchDarkly relay proxy in daemon mode. In this mode, the client does not use polling or streaming to get feature flag updates from the server, but instead reads them from the feature store, which is assumed to be a database that is populated by a LaunchDarkly relay proxy. For more information, see [“The relay proxy”](docs.launchdarkly.com/home/relay-proxy) and [“Using a persistent data stores”](docs.launchdarkly.com/sdk/concepts/data-stores).
All other properties related to streaming or polling are ignored if this option is set to true.
135 136 137 |
# File 'lib/ldclient-rb/config.rb', line 135 def use_ldd? @use_ldd end |