Class: LaunchDarkly::Config

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Constructor for creating custom LaunchDarkly configurations.

Parameters:

  • opts (Hash) (defaults to: {})

    the configuration options

  • hooks (Hash)

    a customizable set of options

  • plugins (Hash)

    a customizable set of options

Options Hash (opts):



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
# File 'lib/ldclient-rb/config.rb', line 52

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] || []
  @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
  @compress_events = opts.has_key?(:compress_events) ? opts[:compress_events] : Config.default_compress_events
  @context_keys_capacity = opts[:context_keys_capacity] || Config.default_context_keys_capacity
  @context_keys_flush_interval = opts[:context_keys_flush_interval] || Config.default_context_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)
  @payload_filter_key = LaunchDarkly::Impl::Util.validate_payload_filter_key(opts[:payload_filter_key] , @logger)
  @hooks = (opts[:hooks] || []).keep_if { |hook| hook.is_a? Interfaces::Hooks::Hook }
  @plugins = (opts[:plugins] || []).keep_if { |plugin| plugin.is_a? Interfaces::Plugins::Plugin }
  @omit_anonymous_contexts = opts.has_key?(:omit_anonymous_contexts) && opts[:omit_anonymous_contexts]
  @datasystem_config = opts[:datasystem_config]
  @data_source_update_sink = nil
  @instance_id = nil
end

Instance Attribute Details

#all_attributes_privateBoolean (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.

Returns:

  • (Boolean)

See Also:



252
253
254
# File 'lib/ldclient-rb/config.rb', line 252

def all_attributes_private
  @all_attributes_private
end

#applicationHash (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.

Examples:

Configuring application information

opts[:application] = {
  id: "MY APPLICATION ID",
  version: "MY APPLICATION VERSION"
}
config = LDConfig.new(opts)

Returns:

  • (Hash)


343
344
345
# File 'lib/ldclient-rb/config.rb', line 343

def application
  @application
end

#base_uriString (readonly)

The base URL for the LaunchDarkly server. This is configurable mainly for testing purposes; most users should use the default value.

Returns:

  • (String)


123
124
125
# File 'lib/ldclient-rb/config.rb', line 123

def base_uri
  @base_uri
end

#big_segmentsBigSegmentsConfig (readonly)

Configuration options related to Big Segments.

Big Segments are a specific type of segments. For more information, read the LaunchDarkly documentation: https://docs.launchdarkly.com/home/users/big-segments

Returns:



325
326
327
# File 'lib/ldclient-rb/config.rb', line 325

def big_segments
  @big_segments
end

#cache_storeObject (readonly)

A store for HTTP caching (used only in polling mode). This must support the semantics used by the 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.

Returns:

  • (Object)


212
213
214
# File 'lib/ldclient-rb/config.rb', line 212

def cache_store
  @cache_store
end

#capacityInteger (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.

Returns:

  • (Integer)


203
204
205
# File 'lib/ldclient-rb/config.rb', line 203

def capacity
  @capacity
end

#compress_eventsBoolean (readonly)

Should the event payload sent to LaunchDarkly use gzip compression. By default this is false to prevent backward breaking compatibility issues with older versions of the relay proxy.

Customers not using the relay proxy are strongly encouraged to enable this feature to reduce egress bandwidth cost.

Returns:

  • (Boolean)


285
286
287
# File 'lib/ldclient-rb/config.rb', line 285

def compress_events
  @compress_events
end

#connect_timeoutFloat (readonly)

The connect timeout for network connections in seconds.

Returns:

  • (Float)


232
233
234
# File 'lib/ldclient-rb/config.rb', line 232

def connect_timeout
  @connect_timeout
end

#context_keys_capacityInteger (readonly)

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.

Returns:

  • (Integer)

See Also:



293
294
295
# File 'lib/ldclient-rb/config.rb', line 293

def context_keys_capacity
  @context_keys_capacity
end

#context_keys_flush_intervalFloat (readonly)

The interval in seconds at which the event processor will reset its set of known context keys.

Returns:

  • (Float)

See Also:



300
301
302
# File 'lib/ldclient-rb/config.rb', line 300

def context_keys_flush_interval
  @context_keys_flush_interval
end

#data_sourceLaunchDarkly::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.



315
316
317
# File 'lib/ldclient-rb/config.rb', line 315

def data_source
  @data_source
end

#data_source_update_sinkObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the component that allows a data source to push data into the SDK.

This property should only be set by the SDK. Long term access of this property is not supported; it is temporarily being exposed to maintain backwards compatibility while the SDK structure is updated.

Custom data source implementations should integrate with this sink if they want to provide support for data source status listeners.



104
105
106
# File 'lib/ldclient-rb/config.rb', line 104

def data_source_update_sink
  @data_source_update_sink
end

#datasystem_configDataSystemConfig? (readonly)

Configuration for the upcoming enhanced data system design. This is experimental and should not be set without direction from LaunchDarkly support.

Returns:



443
444
445
# File 'lib/ldclient-rb/config.rb', line 443

def datasystem_config
  @datasystem_config
end

#diagnostic_recording_intervalFloat (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).

Returns:

  • (Float)


379
380
381
# File 'lib/ldclient-rb/config.rb', line 379

def diagnostic_recording_interval
  @diagnostic_recording_interval
end

#events_uriString (readonly)

The base URL for the LaunchDarkly events server. This is configurable mainly for testing purposes; most users should use the default value.

Returns:

  • (String)


137
138
139
# File 'lib/ldclient-rb/config.rb', line 137

def events_uri
  @events_uri
end

#feature_storeLaunchDarkly::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".



243
244
245
# File 'lib/ldclient-rb/config.rb', line 243

def feature_store
  @feature_store
end

#flush_intervalFloat (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.

Returns:

  • (Float)


178
179
180
# File 'lib/ldclient-rb/config.rb', line 178

def flush_interval
  @flush_interval
end

#hooksObject (readonly)

Initial set of hooks for the client.

Hooks provide entrypoints which allow for observation of SDK functions.

LaunchDarkly provides integration packages, and most applications will not need to implement their own hooks. Refer to the launchdarkly-server-sdk-otel gem for instrumentation.



418
419
420
# File 'lib/ldclient-rb/config.rb', line 418

def hooks
  @hooks
end

#initial_reconnect_delayFloat (readonly)

The initial delay before reconnecting after an error in the SSE client. This only applies to the streaming connection.

Returns:

  • (Float)


226
227
228
# File 'lib/ldclient-rb/config.rb', line 226

def initial_reconnect_delay
  @initial_reconnect_delay
end

#instance_idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the unique identifier for this instance of the SDK.

This property should only be set by the SDK. Long term access of this property is not supported; it is temporarily being exposed to maintain backwards compatibility while the SDK structure is updated.



116
117
118
# File 'lib/ldclient-rb/config.rb', line 116

def instance_id
  @instance_id
end

#loggerLogger (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.

Returns:

  • (Logger)


193
194
195
# File 'lib/ldclient-rb/config.rb', line 193

def logger
  @logger
end

#omit_anonymous_contextsBoolean (readonly)

Sets whether anonymous contexts should be omitted from index and identify events.

The default value is false. Anonymous contexts will be included in index and identify events.

Returns:

  • (Boolean)


434
435
436
# File 'lib/ldclient-rb/config.rb', line 434

def omit_anonymous_contexts
  @omit_anonymous_contexts
end

#payload_filter_keyObject (readonly)

LaunchDarkly Server SDKs historically downloaded all flag configuration and segments for a particular environment during initialization.

For some customers, this is an unacceptably large amount of data, and has contributed to performance issues within their products.

Filtered environments aim to solve this problem. By allowing customers to specify subsets of an environment's flags using a filter key, SDKs will initialize faster and use less memory.

This payload filter key only applies to the default streaming and polling data sources. It will not affect TestData or FileData data sources, nor will it be applied to any data source provided through the #data_source config property.



358
359
360
# File 'lib/ldclient-rb/config.rb', line 358

def payload_filter_key
  @payload_filter_key
end

#pluginsObject (readonly)

Initial set of plugins for the client.

Plugins provide an interface which allows for initialization, access to credentials, and hook registration in a single interface.



426
427
428
# File 'lib/ldclient-rb/config.rb', line 426

def plugins
  @plugins
end

#poll_intervalFloat (readonly)

The number of seconds to wait before polling for feature flag updates. This option has no effect unless streaming is disabled.

Returns:

  • (Float)


185
186
187
# File 'lib/ldclient-rb/config.rb', line 185

def poll_interval
  @poll_interval
end

#private_attributesArray<String> (readonly)

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.



267
268
269
# File 'lib/ldclient-rb/config.rb', line 267

def private_attributes
  @private_attributes
end

#read_timeoutFloat (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.

Returns:

  • (Float)


219
220
221
# File 'lib/ldclient-rb/config.rb', line 219

def read_timeout
  @read_timeout
end

#send_eventsBoolean (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.

Returns:

  • (Boolean)


274
275
276
# File 'lib/ldclient-rb/config.rb', line 274

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.

Returns:

  • (#open)


407
408
409
# File 'lib/ldclient-rb/config.rb', line 407

def socket_factory
  @socket_factory
end

#stream_uriString (readonly)

The base URL for the LaunchDarkly streaming server. This is configurable mainly for testing purposes; most users should use the default value.

Returns:

  • (String)


130
131
132
# File 'lib/ldclient-rb/config.rb', line 130

def stream_uri
  @stream_uri
end

#wrapper_nameString (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.

Returns:

  • (String)


388
389
390
# File 'lib/ldclient-rb/config.rb', line 388

def wrapper_name
  @wrapper_name
end

#wrapper_versionString (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.

Returns:

  • (String)


397
398
399
# File 'lib/ldclient-rb/config.rb', line 397

def wrapper_version
  @wrapper_version
end

Class Method Details

.defaultConfig

The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.

Returns:

  • (Config)

    The default LaunchDarkly configuration.



451
452
453
# File 'lib/ldclient-rb/config.rb', line 451

def self.default
  Config.new
end

.default_base_uriString

The default value for #base_uri.

Returns:



467
468
469
# File 'lib/ldclient-rb/config.rb', line 467

def self.default_base_uri
  "https://sdk.launchdarkly.com"
end

.default_cache_storeObject

The default value for #cache_store.

Returns:

  • (Object)

    the Rails cache if in Rails, or a simple in-memory implementation otherwise



491
492
493
# File 'lib/ldclient-rb/config.rb', line 491

def self.default_cache_store
  defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : Impl::ThreadSafeMemoryStore.new
end

.default_capacityInteger

The default value for #capacity.

Returns:

  • (Integer)

    10000



459
460
461
# File 'lib/ldclient-rb/config.rb', line 459

def self.default_capacity
  10000
end

.default_compress_eventsBoolean

The default value for #compress_events.

Returns:

  • (Boolean)

    false



593
594
595
# File 'lib/ldclient-rb/config.rb', line 593

def self.default_compress_events
  false
end

.default_connect_timeoutFloat

The default value for #connect_timeout.

Returns:

  • (Float)

    2



523
524
525
# File 'lib/ldclient-rb/config.rb', line 523

def self.default_connect_timeout
  2
end

.default_context_keys_capacityInteger

The default value for #context_keys_capacity.

Returns:

  • (Integer)

    1000



601
602
603
# File 'lib/ldclient-rb/config.rb', line 601

def self.default_context_keys_capacity
  1000
end

.default_context_keys_flush_intervalFloat

The default value for #context_keys_flush_interval.

Returns:

  • (Float)

    300



609
610
611
# File 'lib/ldclient-rb/config.rb', line 609

def self.default_context_keys_flush_interval
  300
end

.default_diagnostic_recording_intervalFloat

The default value for #diagnostic_recording_interval.

Returns:

  • (Float)

    900



617
618
619
# File 'lib/ldclient-rb/config.rb', line 617

def self.default_diagnostic_recording_interval
  900
end

.default_events_uriString

The default value for #events_uri.

Returns:



483
484
485
# File 'lib/ldclient-rb/config.rb', line 483

def self.default_events_uri
  "https://events.launchdarkly.com"
end

.default_feature_storeLaunchDarkly::Interfaces::FeatureStore

The default value for #feature_store.



561
562
563
# File 'lib/ldclient-rb/config.rb', line 561

def self.default_feature_store
  InMemoryFeatureStore.new
end

.default_flush_intervalFloat

The default value for #flush_interval.

Returns:

  • (Float)

    10



499
500
501
# File 'lib/ldclient-rb/config.rb', line 499

def self.default_flush_interval
  10
end

.default_initial_reconnect_delayFloat

The default value for #initial_reconnect_delay.

Returns:

  • (Float)

    1



515
516
517
# File 'lib/ldclient-rb/config.rb', line 515

def self.default_initial_reconnect_delay
  1
end

.default_loggerLogger

The default value for #logger.

Returns:

  • (Logger)

    the Rails logger if in Rails, or a default Logger at WARN level otherwise



531
532
533
534
535
536
537
538
539
# File 'lib/ldclient-rb/config.rb', line 531

def self.default_logger
  if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
    Rails.logger
  else
    log = ::Logger.new($stdout)
    log.level = ::Logger::WARN
    log
  end
end

.default_offlineBoolean

The default value for #offline?.

Returns:

  • (Boolean)

    false



569
570
571
# File 'lib/ldclient-rb/config.rb', line 569

def self.default_offline
  false
end

.default_poll_intervalFloat

The default value for #poll_interval.

Returns:

  • (Float)

    30



577
578
579
# File 'lib/ldclient-rb/config.rb', line 577

def self.default_poll_interval
  30
end

.default_read_timeoutFloat

The default value for #read_timeout.

Returns:

  • (Float)

    10



507
508
509
# File 'lib/ldclient-rb/config.rb', line 507

def self.default_read_timeout
  10
end

.default_send_eventsBoolean

The default value for #send_events.

Returns:

  • (Boolean)

    true



585
586
587
# File 'lib/ldclient-rb/config.rb', line 585

def self.default_send_events
  true
end

.default_streamBoolean

The default value for #stream?.

Returns:

  • (Boolean)

    true



545
546
547
# File 'lib/ldclient-rb/config.rb', line 545

def self.default_stream
  true
end

.default_stream_uriString

The default value for #stream_uri.

Returns:



475
476
477
# File 'lib/ldclient-rb/config.rb', line 475

def self.default_stream_uri
  "https://stream.launchdarkly.com"
end

.default_use_lddBoolean

The default value for #use_ldd?.

Returns:

  • (Boolean)

    false



553
554
555
# File 'lib/ldclient-rb/config.rb', line 553

def self.default_use_ldd
  false
end

.minimum_diagnostic_recording_intervalFloat

The minimum value for #diagnostic_recording_interval.

Returns:

  • (Float)

    60



625
626
627
# File 'lib/ldclient-rb/config.rb', line 625

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.

Returns:

  • (Boolean)


369
370
371
# File 'lib/ldclient-rb/config.rb', line 369

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.

Returns:

  • (Boolean)


169
170
171
# File 'lib/ldclient-rb/config.rb', line 169

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.

Returns:

  • (Boolean)


145
146
147
# File 'lib/ldclient-rb/config.rb', line 145

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" and "Using a persistent data stores".

All other properties related to streaming or polling are ignored if this option is set to true.

Returns:

  • (Boolean)


160
161
162
# File 'lib/ldclient-rb/config.rb', line 160

def use_ldd?
  @use_ldd
end