Class: Statsig::Diagnostics
- Inherits:
-
Object
- Object
- Statsig::Diagnostics
- Defined in:
- lib/diagnostics.rb
Defined Under Namespace
Classes: Tracker
Constant Summary collapse
- API_CALL_KEYS =
{ :check_gate => true, :get_config => true, :get_experiment => true, :get_layer => true }.freeze
Instance Attribute Summary collapse
-
#markers ⇒ Object
readonly
Returns the value of attribute markers.
-
#sample_rates ⇒ Object
Returns the value of attribute sample_rates.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_markers(context) ⇒ Object
-
#initialize ⇒ Diagnostics
constructor
A new instance of Diagnostics.
- #mark(key, action, step, tags, context) ⇒ Object
- #serialize_with_sampling(context) ⇒ Object
- #track(context, key, step = nil, tags = {}) ⇒ Object
Constructor Details
#initialize ⇒ Diagnostics
Returns a new instance of Diagnostics.
7 8 9 10 |
# File 'lib/diagnostics.rb', line 7 def initialize() @markers = {:initialize => [], :api_call => [], :config_sync => []} @sample_rates = {} end |
Instance Attribute Details
#markers ⇒ Object (readonly)
Returns the value of attribute markers.
3 4 5 |
# File 'lib/diagnostics.rb', line 3 def markers @markers end |
#sample_rates ⇒ Object
Returns the value of attribute sample_rates.
5 6 7 |
# File 'lib/diagnostics.rb', line 5 def sample_rates @sample_rates end |
Class Method Details
.sample(rate_over_ten_thousand) ⇒ Object
57 58 59 |
# File 'lib/diagnostics.rb', line 57 def self.sample(rate_over_ten_thousand) rand * 10_000 < rate_over_ten_thousand end |
Instance Method Details
#clear_markers(context) ⇒ Object
53 54 55 |
# File 'lib/diagnostics.rb', line 53 def clear_markers(context) @markers[context].clear end |
#mark(key, action, step, tags, context) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/diagnostics.rb', line 12 def mark(key, action, step, , context) marker = { key: key, action: action, timestamp: (Time.now.to_f * 1000).to_i } if !step.nil? marker[:step] = step end .each do |key, val| unless val.nil? marker[key] = val end end if @markers[context].nil? @markers[context] = [] end @markers[context].push(marker) end |
#serialize_with_sampling(context) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/diagnostics.rb', line 38 def serialize_with_sampling(context) marker_keys = @markers[context].map { |e| e[:key] } unique_marker_keys = marker_keys.uniq { |e| e } sampled_marker_keys = unique_marker_keys.select do |key| @sample_rates.key?(key) && !self.class.sample(@sample_rates[key]) end final_markers = @markers[context].select do |marker| !sampled_marker_keys.include?(marker[:key]) end { context: context.clone, markers: final_markers.clone } end |