Class: InternalEventsSamplingService
- Inherits:
-
Object
- Object
- InternalEventsSamplingService
- 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
-
#initialize(random_value_provider = nil) ⇒ InternalEventsSamplingService
constructor
Creates a sampling service.
-
#should_send_sampled_debug_event(settings) ⇒ Boolean
Determines whether a sampled debug event should be sent.
-
#should_send_usage_stats_event(settings) ⇒ Boolean
Determines whether the usage-stats event should be sent.
Constructor Details
#initialize(random_value_provider = nil) ⇒ InternalEventsSamplingService
Creates a sampling service.
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.
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.
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 |