Module: Statsig

Extended by:
T::Sig
Defined in:
lib/id_list.rb,
lib/network.rb,
lib/statsig.rb,
lib/evaluator.rb,
lib/hash_utils.rb,
lib/spec_store.rb,
lib/diagnostics.rb,
lib/config_result.rb,
lib/error_boundary.rb,
lib/statsig_errors.rb,
lib/statsig_logger.rb,
lib/evaluation_details.rb,
lib/interfaces/data_store.rb

Overview

typed: true

Defined Under Namespace

Modules: EvaluationReason, Interfaces Classes: ConfigResult, Diagnostics, ErrorBoundary, EvaluationDetails, Evaluator, HashUtils, IDList, Network, NetworkError, SpecStore, StatsigLogger, UninitializedError, ValueError

Class Method Summary collapse

Class Method Details

.check_gate(user, gate_name) ⇒ Object

Gets the boolean result of a gate, evaluated against the given user. An exposure event will automatically be logged for the gate.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • gate_name

    The name of the gate being checked



35
36
37
38
# File 'lib/statsig.rb', line 35

def self.check_gate(user, gate_name)
  ensure_initialized
  @shared_instance&.check_gate(user, gate_name)
end

.check_gate_with_exposure_logging_disabled(user, gate_name) ⇒ Object

Gets the boolean result of a gate, evaluated against the given user.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • gate_name

    The name of the gate being checked



46
47
48
49
# File 'lib/statsig.rb', line 46

def self.check_gate_with_exposure_logging_disabled(user, gate_name)
  ensure_initialized
  @shared_instance&.check_gate(user, gate_name, StatsigDriver::CheckGateOptions.new(log_exposure: false))
end

.get_client_initialize_response(user, hash: 'sha256', client_sdk_key: nil) ⇒ Object

Note:

See Ruby Documentation: docs.statsig.com/server/rubySDK)

Gets all evaluated values for the given user. These values can then be given to a Statsig Client SDK via bootstrapping.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • hash (defaults to: 'sha256')

    The type of hashing algorithm to use (‘sha256’, ‘djb2’, ‘none’)

  • client_sdk_key (defaults to: nil)

    A optional client sdk key to be used for the evaluation



231
232
233
234
# File 'lib/statsig.rb', line 231

def self.get_client_initialize_response(user, hash: 'sha256', client_sdk_key: nil)
  ensure_initialized
  @shared_instance&.get_client_initialize_response(user, hash, client_sdk_key)
end

.get_config(user, dynamic_config_name) ⇒ Object

Get the values of a dynamic config, evaluated against the given user. An exposure event will automatically be logged for the dynamic config.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • dynamic_config_name

    The name of the dynamic config



68
69
70
71
# File 'lib/statsig.rb', line 68

def self.get_config(user, dynamic_config_name)
  ensure_initialized
  @shared_instance&.get_config(user, dynamic_config_name)
end

.get_config_with_exposure_logging_disabled(user, dynamic_config_name) ⇒ Object

Get the values of a dynamic config, evaluated against the given user.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • dynamic_config_name

    The name of the dynamic config



79
80
81
82
# File 'lib/statsig.rb', line 79

def self.get_config_with_exposure_logging_disabled(user, dynamic_config_name)
  ensure_initialized
  @shared_instance&.get_config(user, dynamic_config_name, StatsigDriver::GetConfigOptions.new(log_exposure: false))
end

.get_experiment(user, experiment_name) ⇒ Object

Get the values of an experiment, evaluated against the given user. An exposure event will automatically be logged for the experiment.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • experiment_name

    The name of the experiment



101
102
103
104
# File 'lib/statsig.rb', line 101

def self.get_experiment(user, experiment_name)
  ensure_initialized
  @shared_instance&.get_experiment(user, experiment_name)
end

.get_experiment_with_exposure_logging_disabled(user, experiment_name) ⇒ Object

Get the values of an experiment, evaluated against the given user.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • experiment_name

    The name of the experiment



112
113
114
115
# File 'lib/statsig.rb', line 112

def self.get_experiment_with_exposure_logging_disabled(user, experiment_name)
  ensure_initialized
  @shared_instance&.get_experiment(user, experiment_name, StatsigDriver::GetExperimentOptions.new(log_exposure: false))
end

.get_layer(user, layer_name) ⇒ Object

Get the values of a layer, evaluated against the given user. Exposure events will be fired when get or get_typed is called on the resulting Layer class.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • layer_name

    The name of the layer



135
136
137
138
# File 'lib/statsig.rb', line 135

def self.get_layer(user, layer_name)
  ensure_initialized
  @shared_instance&.get_layer(user, layer_name)
end

.get_layer_with_exposure_logging_disabled(user, layer_name) ⇒ Object

Get the values of a layer, evaluated against the given user.

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • layer_name

    The name of the layer



146
147
148
149
# File 'lib/statsig.rb', line 146

def self.get_layer_with_exposure_logging_disabled(user, layer_name)
  ensure_initialized
  @shared_instance&.get_layer(user, layer_name, StatsigDriver::GetLayerOptions.new(log_exposure: false))
end

.get_statsig_metadataObject

Internal Statsig metadata for this SDK



239
240
241
242
243
244
# File 'lib/statsig.rb', line 239

def self.
  {
    'sdkType' => 'ruby-server',
    'sdkVersion' => '1.28.0',
  }
end

.initialize(secret_key, options = nil, error_callback = nil) ⇒ Object

Initializes the Statsig SDK.

Parameters:

  • secret_key

    The server SDK key copied from console.statsig.com

  • options (defaults to: nil)

    The StatsigOptions object used to configure the SDK

  • error_callback (defaults to: nil)

    A callback function, called if the initialize network call fails



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/statsig.rb', line 17

def self.initialize(secret_key, options = nil, error_callback = nil)
  unless @shared_instance.nil?
    puts 'Statsig already initialized.'
    @shared_instance.maybe_restart_background_threads
    return @shared_instance
  end

  self.bind_sorbet_loggers(options)

  @shared_instance = StatsigDriver.new(secret_key, options, error_callback)
end

.log_event(user, event_name, value = nil, metadata = nil) ⇒ Object

Logs an event to Statsig with the provided values.

Parameters:

  • user

    A StatsigUser object to be included in the log

  • event_name

    The name given to the event

  • value (defaults to: nil)

    A top level value for the event

  • metadata (defaults to: nil)

    Any extra values to be logged



174
175
176
177
# File 'lib/statsig.rb', line 174

def self.log_event(user, event_name, value = nil,  = nil)
  ensure_initialized
  @shared_instance&.log_event(user, event_name, value, )
end

.manually_log_config_exposure(user, dynamic_config) ⇒ Object

Logs an exposure event for the dynamic config

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • dynamic_config_name

    The name of the dynamic config



90
91
92
93
# File 'lib/statsig.rb', line 90

def self.manually_log_config_exposure(user, dynamic_config)
  ensure_initialized
  @shared_instance&.manually_log_config_exposure(user, dynamic_config)
end

.manually_log_experiment_exposure(user, experiment_name) ⇒ Object

Logs an exposure event for the experiment

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • experiment_name

    The name of the experiment



123
124
125
126
# File 'lib/statsig.rb', line 123

def self.manually_log_experiment_exposure(user, experiment_name)
  ensure_initialized
  @shared_instance&.manually_log_config_exposure(user, experiment_name)
end

.manually_log_gate_exposure(user, gate_name) ⇒ Object

Logs an exposure event for the gate

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • gate_name

    The name of the gate being checked



57
58
59
60
# File 'lib/statsig.rb', line 57

def self.manually_log_gate_exposure(user, gate_name)
  ensure_initialized
  @shared_instance&.manually_log_gate_exposure(user, gate_name)
end

.manually_log_layer_parameter_exposure(user, layer_name, parameter_name) ⇒ Object

Logs an exposure event for the parameter in the given layer

Parameters:

  • user

    A StatsigUser object used for the evaluation

  • layer_name

    The name of the layer

  • parameter_name

    The name of the parameter in the layer



158
159
160
161
# File 'lib/statsig.rb', line 158

def self.manually_log_layer_parameter_exposure(user, layer_name, parameter_name)
  ensure_initialized
  @shared_instance&.manually_log_layer_parameter_exposure(user, layer_name, parameter_name)
end

.override_config(config_name, config_value) ⇒ Object

Sets a value to be returned for the given dynamic config/experiment instead of the actual evaluated value.

Parameters:

  • config_name

    The name of the dynamic config or experiment to be overridden

  • config_value

    The value that will be returned



216
217
218
219
# File 'lib/statsig.rb', line 216

def self.override_config(config_name, config_value)
  ensure_initialized
  @shared_instance&.override_config(config_name, config_value)
end

.override_gate(gate_name, gate_value) ⇒ Object

Sets a value to be returned for the given gate instead of the actual evaluated value.

Parameters:

  • gate_name

    The name of the gate to be overridden

  • gate_value

    The value that will be returned



205
206
207
208
# File 'lib/statsig.rb', line 205

def self.override_gate(gate_name, gate_value)
  ensure_initialized
  @shared_instance&.override_gate(gate_name, gate_value)
end

.shutdownObject

Stops all Statsig activity and flushes any pending events.



192
193
194
195
196
197
# File 'lib/statsig.rb', line 192

def self.shutdown
  if defined? @shared_instance and !@shared_instance.nil?
    @shared_instance.shutdown
  end
  @shared_instance = nil
end

.sync_idlistsObject



184
185
186
187
# File 'lib/statsig.rb', line 184

def self.sync_idlists
  ensure_initialized
  @shared_instance&.manually_sync_idlists
end

.sync_rulesetsObject



179
180
181
182
# File 'lib/statsig.rb', line 179

def self.sync_rulesets
  ensure_initialized
  @shared_instance&.manually_sync_rulesets
end