Module: Pinot::Instrumentation
- Defined in:
- lib/pinot/instrumentation.rb
Class Method Summary collapse
- .instrument(table:, query:) ⇒ Object
- .notify(event) ⇒ Object
- .on_query ⇒ Object
-
.on_query=(callback) ⇒ Object
Called around every query execution.
Class Method Details
.instrument(table:, query:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pinot/instrumentation.rb', line 20 def self.instrument(table:, query:) start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = yield duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000 notify(table: table, query: query, duration_ms: duration_ms, success: true, error: nil) result rescue => e duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start) * 1000 notify(table: table, query: query, duration_ms: duration_ms, success: false, error: e) raise end |
.notify(event) ⇒ Object
32 33 34 |
# File 'lib/pinot/instrumentation.rb', line 32 def self.notify(event) @on_query&.call(event) end |
.on_query ⇒ Object
16 17 18 |
# File 'lib/pinot/instrumentation.rb', line 16 def self.on_query @on_query end |
.on_query=(callback) ⇒ Object
Called around every query execution. Implement by setting Pinot::Instrumentation.on_query = proc { |event| … } event is a Hash:
:table => String
:query => String
:duration_ms => Float
:success => Boolean
:error => Exception or nil
12 13 14 |
# File 'lib/pinot/instrumentation.rb', line 12 def self.on_query=(callback) @on_query = callback end |