Class: CqlInstrumentation::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/cql_instrumentation/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_runtimeObject



26
27
28
29
# File 'lib/cql_instrumentation/log_subscriber.rb', line 26

def self.reset_runtime
  rt, self.runtime = runtime, 0
  rt
end

.runtimeObject



22
23
24
# File 'lib/cql_instrumentation/log_subscriber.rb', line 22

def self.runtime
  RuntimeRegistry.cql_runtime ||= 0
end

.runtime=(value) ⇒ Object



18
19
20
# File 'lib/cql_instrumentation/log_subscriber.rb', line 18

def self.runtime=(value)
  RuntimeRegistry.cql_runtime = value
end

Instance Method Details

#query(event) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/cql_instrumentation/log_subscriber.rb', line 8

def query(event)
  self.class.runtime += event.duration if self.class.calculate_runtime
  return unless logger.debug?

  cql = event.payload[:cql]
  binds = event.payload[:binds]
  name = "Cassandra Query (#{event.duration.round(1)}ms)"
  debug "  #{color(name, YELLOW, true)}  #{color(cql, nil, true)}  #{binds.any? ? binds.inspect : nil}"
end