Class: InternalEventsSamplingService

Inherits:
Object
  • Object
show all
Defined in:
lib/wingify/services/internal_events_sampling_service.rb

Overview

Applies sampling rules for internal SDK events: vwo_sdkUsageStats and sampled vwo_sdkDebug.

Instance Method Summary collapse

Constructor Details

#initialize(random_value_provider = nil) ⇒ InternalEventsSamplingService

Creates a sampling service.

Parameters:

  • random_value_provider (Proc, nil) (defaults to: nil)

    Optional supplier returning a value in [0, 1) for sampling checks; overridable in tests.



24
25
26
27
# File 'lib/wingify/services/internal_events_sampling_service.rb', line 24

def initialize(random_value_provider = nil)
  # Use Kernel#rand by default; inject a custom provider when testing
  @random_value_provider = random_value_provider || -> { rand }
end

Instance Method Details

#should_send_sampled_debug_event(settings) ⇒ Boolean

Determines whether a sampled debug event should be sent. Only called for msg_t keys in the sampled set; always-send keys bypass this.

Parameters:

  • settings (SettingsModel, nil)

    Parsed settings from the server

Returns:

  • (Boolean)

    true when the sampled debug event should be sent



47
48
49
50
51
52
53
# File 'lib/wingify/services/internal_events_sampling_service.rb', line 47

def should_send_sampled_debug_event(settings)
  # Skip the percent check when alwaysApplySampling.server is off
  return true unless InternalEventsSamplingUtil.should_apply_sampling(settings)

  debug_sampling_percent = InternalEventsSamplingUtil.get_debug_event_sampling_percent(settings)
  InternalEventsSamplingUtil.passes_sampling_percent(debug_sampling_percent, @random_value_provider.call)
end

#should_send_usage_stats_event(settings) ⇒ Boolean

Determines whether the usage-stats event should be sent. On server, always sends unless alwaysApplySampling.server is enabled.

Parameters:

  • settings (SettingsModel, nil)

    Parsed settings from the server

Returns:

  • (Boolean)

    true when the usage-stats event should be sent



34
35
36
37
38
39
40
# File 'lib/wingify/services/internal_events_sampling_service.rb', line 34

def should_send_usage_stats_event(settings)
  # Skip the percent check when alwaysApplySampling.server is off
  return true unless InternalEventsSamplingUtil.should_apply_sampling(settings)

  usage_stats_sampling_percent = InternalEventsSamplingUtil.get_usage_stats_sampling_percent(settings)
  InternalEventsSamplingUtil.passes_sampling_percent(usage_stats_sampling_percent, @random_value_provider.call)
end