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

Options Hash (opts):



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

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
  @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_attribute_names = opts[:private_attribute_names] || []
  @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
  @user_keys_capacity = opts[:user_keys_capacity] || Config.default_user_keys_capacity
  @user_keys_flush_interval = opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
  @inline_users_in_events = opts[:inline_users_in_events] || false
  @data_source = opts[:data_source] || opts[:update_processor] || opts[:update_processor_factory]
  @update_processor = opts[:update_processor]
  @update_processor_factory = opts[:update_processor_factory]
  @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]
end

Instance Attribute Details

#all_attributes_privateBoolean (readonly)

True if all user 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:



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

def all_attributes_private
  @all_attributes_private
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)


81
82
83
# File 'lib/ldclient-rb/config.rb', line 81

def base_uri
  @base_uri
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)


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

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)


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

def capacity
  @capacity
end

#connect_timeoutFloat (readonly)

The connect timeout for network connections in seconds.

Returns:

  • (Float)


183
184
185
# File 'lib/ldclient-rb/config.rb', line 183

def connect_timeout
  @connect_timeout
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.



261
262
263
# File 'lib/ldclient-rb/config.rb', line 261

def data_source
  @data_source
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)


288
289
290
# File 'lib/ldclient-rb/config.rb', line 288

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)


95
96
97
# File 'lib/ldclient-rb/config.rb', line 95

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 "Using a persistent feature store".



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

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)


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

def flush_interval
  @flush_interval
end

#inline_users_in_eventsBoolean (readonly)

Whether to include full user details in every analytics event. By default, events will only include the user key, except for one "index" event that provides the full details for the user. The only reason to change this is if you are using the Analytics Data Stream.

Returns:

  • (Boolean)


247
248
249
# File 'lib/ldclient-rb/config.rb', line 247

def inline_users_in_events
  @inline_users_in_events
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)


151
152
153
# File 'lib/ldclient-rb/config.rb', line 151

def logger
  @logger
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)


143
144
145
# File 'lib/ldclient-rb/config.rb', line 143

def poll_interval
  @poll_interval
end

#private_attribute_namesArray<String> (readonly)

A list of user 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 storing an array of attribute names in the :privateAttributeNames property (note camelcase name) of the user object.

Returns:

  • (Array<String>)

See Also:



217
218
219
# File 'lib/ldclient-rb/config.rb', line 217

def private_attribute_names
  @private_attribute_names
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)


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

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)


224
225
226
# File 'lib/ldclient-rb/config.rb', line 224

def send_events
  @send_events
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)


88
89
90
# File 'lib/ldclient-rb/config.rb', line 88

def stream_uri
  @stream_uri
end

#update_processorObject (readonly)

Deprecated.

This is replaced by #data_source.



264
265
266
# File 'lib/ldclient-rb/config.rb', line 264

def update_processor
  @update_processor
end

#update_processor_factoryObject (readonly)

Deprecated.

This is replaced by #data_source.



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

def update_processor_factory
  @update_processor_factory
end

#user_keys_capacityInteger (readonly)

The number of user keys that the event processor can remember at any one time. This reduces the amount of duplicate user details sent in analytics events.

Returns:

  • (Integer)

See Also:



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

def user_keys_capacity
  @user_keys_capacity
end

#user_keys_flush_intervalFloat (readonly)

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

Returns:

  • (Float)

See Also:



239
240
241
# File 'lib/ldclient-rb/config.rb', line 239

def user_keys_flush_interval
  @user_keys_flush_interval
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)


297
298
299
# File 'lib/ldclient-rb/config.rb', line 297

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)


306
307
308
# File 'lib/ldclient-rb/config.rb', line 306

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.



313
314
315
# File 'lib/ldclient-rb/config.rb', line 313

def self.default
  Config.new
end

.default_base_uriString

The default value for #base_uri.

Returns:



329
330
331
# File 'lib/ldclient-rb/config.rb', line 329

def self.default_base_uri
  "https://app.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



353
354
355
# File 'lib/ldclient-rb/config.rb', line 353

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

.default_capacityInteger

The default value for #capacity.

Returns:

  • (Integer)

    10000



321
322
323
# File 'lib/ldclient-rb/config.rb', line 321

def self.default_capacity
  10000
end

.default_connect_timeoutFloat

The default value for #connect_timeout.

Returns:

  • (Float)

    10



377
378
379
# File 'lib/ldclient-rb/config.rb', line 377

def self.default_connect_timeout
  2
end

.default_diagnostic_recording_intervalFloat

The default value for #diagnostic_recording_interval.

Returns:

  • (Float)

    900



463
464
465
# File 'lib/ldclient-rb/config.rb', line 463

def self.default_diagnostic_recording_interval
  900
end

.default_events_uriString

The default value for #events_uri.

Returns:



345
346
347
# File 'lib/ldclient-rb/config.rb', line 345

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

.default_feature_storeLaunchDarkly::Interfaces::FeatureStore

The default value for #feature_store.



415
416
417
# File 'lib/ldclient-rb/config.rb', line 415

def self.default_feature_store
  InMemoryFeatureStore.new
end

.default_flush_intervalFloat

The default value for #flush_interval.

Returns:

  • (Float)

    10



361
362
363
# File 'lib/ldclient-rb/config.rb', line 361

def self.default_flush_interval
  10
end

.default_loggerLogger

The default value for #logger.

Returns:

  • (Logger)

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



385
386
387
388
389
390
391
392
393
# File 'lib/ldclient-rb/config.rb', line 385

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_offlineBoolean

The default value for #offline?.

Returns:

  • (Boolean)

    false



423
424
425
# File 'lib/ldclient-rb/config.rb', line 423

def self.default_offline
  false
end

.default_poll_intervalFloat

The default value for #poll_interval.

Returns:

  • (Float)

    30



431
432
433
# File 'lib/ldclient-rb/config.rb', line 431

def self.default_poll_interval
  30
end

.default_read_timeoutFloat

The default value for #read_timeout.

Returns:

  • (Float)

    10



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

def self.default_read_timeout
  10
end

.default_send_eventsBoolean

The default value for #send_events.

Returns:

  • (Boolean)

    true



439
440
441
# File 'lib/ldclient-rb/config.rb', line 439

def self.default_send_events
  true
end

.default_streamBoolean

The default value for #stream?.

Returns:

  • (Boolean)

    true



399
400
401
# File 'lib/ldclient-rb/config.rb', line 399

def self.default_stream
  true
end

.default_stream_uriString

The default value for #stream_uri.

Returns:



337
338
339
# File 'lib/ldclient-rb/config.rb', line 337

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

.default_use_lddBoolean

The default value for #use_ldd?.

Returns:

  • (Boolean)

    false



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

def self.default_use_ldd
  false
end

.default_user_keys_capacityInteger

The default value for #user_keys_capacity.

Returns:

  • (Integer)

    1000



447
448
449
# File 'lib/ldclient-rb/config.rb', line 447

def self.default_user_keys_capacity
  1000
end

.default_user_keys_flush_intervalFloat

The default value for #user_keys_flush_interval.

Returns:

  • (Float)

    300



455
456
457
# File 'lib/ldclient-rb/config.rb', line 455

def self.default_user_keys_flush_interval
  300
end

.minimum_diagnostic_recording_intervalFloat

The minimum value for #diagnostic_recording_interval.

Returns:

  • (Float)

    60



471
472
473
# File 'lib/ldclient-rb/config.rb', line 471

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)


278
279
280
# File 'lib/ldclient-rb/config.rb', line 278

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)


127
128
129
# File 'lib/ldclient-rb/config.rb', line 127

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)


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

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 feature store".

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

Returns:

  • (Boolean)


118
119
120
# File 'lib/ldclient-rb/config.rb', line 118

def use_ldd?
  @use_ldd
end