Module: SourceMonitor::Instrumentation
- Defined in:
- lib/source_monitor/instrumentation.rb
Constant Summary collapse
- FETCH_START_EVENT =
"source_monitor.fetch.start".freeze
- FETCH_FINISH_EVENT =
"source_monitor.fetch.finish".freeze
- ITEM_DUPLICATE_EVENT =
"source_monitor.items.duplicate".freeze
- ITEM_RETENTION_EVENT =
"source_monitor.items.retention".freeze
Class Method Summary collapse
- .fetch(payload = {}) ⇒ Object
- .fetch_finish(payload = {}) ⇒ Object
- .fetch_start(payload = {}) ⇒ Object
- .instrument(event_name, payload = {}) ⇒ Object
- .item_duplicate(payload = {}) ⇒ Object
- .item_retention(payload = {}) ⇒ Object
- .monotonic_time ⇒ Object
Class Method Details
.fetch(payload = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/source_monitor/instrumentation.rb', line 14 def fetch(payload = {}) payload = payload.dup instrument(FETCH_START_EVENT, payload) started_at = monotonic_time result = yield if block_given? duration_ms = ((monotonic_time - started_at) * 1000.0).round(2) instrument(FETCH_FINISH_EVENT, payload.merge(duration_ms: duration_ms)) result end |
.fetch_finish(payload = {}) ⇒ Object
30 31 32 |
# File 'lib/source_monitor/instrumentation.rb', line 30 def fetch_finish(payload = {}) instrument(FETCH_FINISH_EVENT, payload) end |
.fetch_start(payload = {}) ⇒ Object
26 27 28 |
# File 'lib/source_monitor/instrumentation.rb', line 26 def fetch_start(payload = {}) instrument(FETCH_START_EVENT, payload) end |
.instrument(event_name, payload = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/source_monitor/instrumentation.rb', line 42 def instrument(event_name, payload = {}) ActiveSupport::Notifications.instrument(event_name, payload) do yield if block_given? end end |
.item_duplicate(payload = {}) ⇒ Object
34 35 36 |
# File 'lib/source_monitor/instrumentation.rb', line 34 def item_duplicate(payload = {}) instrument(ITEM_DUPLICATE_EVENT, payload) end |
.item_retention(payload = {}) ⇒ Object
38 39 40 |
# File 'lib/source_monitor/instrumentation.rb', line 38 def item_retention(payload = {}) instrument(ITEM_RETENTION_EVENT, payload) end |
.monotonic_time ⇒ Object
48 49 50 |
# File 'lib/source_monitor/instrumentation.rb', line 48 def monotonic_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end |