Class: InternalEventsSamplingUtil
- Inherits:
-
Object
- Object
- InternalEventsSamplingUtil
- Defined in:
- lib/wingify/utils/internal_events_sampling_util.rb
Overview
Helpers for reading and applying internal-events sampling settings.
Class Method Summary collapse
-
.get_debug_event_sampling_percent(settings) ⇒ Float
Reads the debug-event sampling percentage for the server runtime from settings.
-
.get_default_sampling_percent ⇒ Float
Returns the default server sampling percentage when settings omit the value.
-
.get_runtime_sampling_percent(runtime_sampling_config) ⇒ Float
Reads the server sampling percentage from a runtime sampling config object.
-
.get_usage_stats_sampling_percent(settings) ⇒ Float
Reads the usage-stats sampling percentage for the server runtime from settings.
-
.is_sampled_debug_error_template_key(message_template_key) ⇒ Boolean
Checks whether a debug error template key is in the sampled set.
-
.normalize_sampling_percent(sampling_value) ⇒ Float
Normalizes a sampling value to a valid percentage in the range [0, 100].
-
.passes_sampling_percent(sampling_percent, random_value) ⇒ Boolean
Evaluates whether an event qualifies under the configured sampling percentage.
-
.should_apply_sampling(settings) ⇒ Boolean
Determines whether sampling should be evaluated before send.
Class Method Details
.get_debug_event_sampling_percent(settings) ⇒ Float
Reads the debug-event sampling percentage for the server runtime from settings.
66 67 68 69 70 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 66 def get_debug_event_sampling_percent(settings) sampling = settings ? settings.get_sampling : nil debug_sampling = sampling ? sampling.get_debug : nil get_runtime_sampling_percent(debug_sampling) end |
.get_default_sampling_percent ⇒ Float
Returns the default server sampling percentage when settings omit the value.
24 25 26 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 24 def get_default_sampling_percent Constants::INTERNAL_EVENTS_DEFAULT_SAMPLING_PERCENT_SERVER end |
.get_runtime_sampling_percent(runtime_sampling_config) ⇒ Float
Reads the server sampling percentage from a runtime sampling config object.
46 47 48 49 50 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 46 def get_runtime_sampling_percent(runtime_sampling_config) return get_default_sampling_percent if runtime_sampling_config.nil? normalize_sampling_percent(runtime_sampling_config.get_server) end |
.get_usage_stats_sampling_percent(settings) ⇒ Float
Reads the usage-stats sampling percentage for the server runtime from settings.
56 57 58 59 60 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 56 def get_usage_stats_sampling_percent(settings) sampling = settings ? settings.get_sampling : nil usage_sampling = sampling ? sampling.get_usage : nil get_runtime_sampling_percent(usage_sampling) end |
.is_sampled_debug_error_template_key(message_template_key) ⇒ Boolean
Checks whether a debug error template key is in the sampled set.
104 105 106 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 104 def is_sampled_debug_error_template_key() SampledDebugErrorTemplateKeys.contains?() end |
.normalize_sampling_percent(sampling_value) ⇒ Float
Normalizes a sampling value to a valid percentage in the range [0, 100]. Falls back to the server default when the value is missing or invalid.
33 34 35 36 37 38 39 40 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 33 def normalize_sampling_percent(sampling_value) # Accept only numeric values that fall within 0–100 inclusive if !sampling_value.nil? && sampling_value.is_a?(Numeric) && sampling_value >= 0 && sampling_value <= 100 return sampling_value.to_f end get_default_sampling_percent end |
.passes_sampling_percent(sampling_percent, random_value) ⇒ Boolean
Evaluates whether an event qualifies under the configured sampling percentage.
94 95 96 97 98 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 94 def passes_sampling_percent(sampling_percent, random_value) # Map random [0, 1) to an integer percent bucket [0, 100] normalized_random_percent = (random_value * 101).floor normalized_random_percent <= sampling_percent end |
.should_apply_sampling(settings) ⇒ Boolean
Determines whether sampling should be evaluated before send. Controlled by alwaysApplySampling.server; defaults to false.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wingify/utils/internal_events_sampling_util.rb', line 77 def should_apply_sampling(settings) return Constants::INTERNAL_EVENTS_DEFAULT_ALWAYS_APPLY_SAMPLING if settings.nil? always_apply_sampling = settings.get_always_apply_sampling # Missing config or missing server flag → use default (do not sample) if always_apply_sampling.nil? || always_apply_sampling.get_server.nil? return Constants::INTERNAL_EVENTS_DEFAULT_ALWAYS_APPLY_SAMPLING end always_apply_sampling.get_server end |