Class: Quilt::Performance::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/quilt_rails/performance/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
# File 'lib/quilt_rails/performance/client.rb', line 6

def initialize(report)
  @report = report
  @base_tags = {
    browser_connection_type: report.connection.effective_type,
  }.freeze

  @distribution_callback = proc { |_name, _value, _tags| nil }
  @event_callback = proc { |_event, _tags| {} }
  @navigation_callback = proc { |_navigation, _tags| {} }
end

Class Method Details

.send!(report) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/quilt_rails/performance/client.rb', line 17

def self.send!(report)
  client = Client.new(report)

  # Allow the user to customize things
  if block_given?
    yield(client)
  end

  client.send(:process_report!)
end

Instance Method Details

#distribution(metric_name, value, tags = {}) ⇒ Object



28
29
30
31
# File 'lib/quilt_rails/performance/client.rb', line 28

def distribution(metric_name, value, tags = {})
  @distribution_callback.call(metric_name, value, tags)
  StatsD.distribution(metric_name, value, tags: tags) unless Rails.env.dev?
end

#on_distribution(&block) ⇒ Object



41
42
43
# File 'lib/quilt_rails/performance/client.rb', line 41

def on_distribution(&block)
  @distribution_callback = block
end

#on_event(&block) ⇒ Object



37
38
39
# File 'lib/quilt_rails/performance/client.rb', line 37

def on_event(&block)
  @event_callback = block
end

#on_navigation(&block) ⇒ Object



33
34
35
# File 'lib/quilt_rails/performance/client.rb', line 33

def on_navigation(&block)
  @navigation_callback = block
end