Class: Chronos::Rails::NotificationsSubscriber
- Inherits:
-
Object
- Object
- Chronos::Rails::NotificationsSubscriber
- Defined in:
- lib/chronos/rails/notifications_subscriber.rb
Overview
Converts public ActiveSupport notifications into bounded Chronos telemetry.
Constant Summary collapse
- EVENTS =
rubocop:disable Metrics/ClassLength
%w( process_action.action_controller render_template.action_view sql.active_record deliver.action_mailer perform.active_job cache_read.active_support cache_write.active_support cache_fetch_hit.active_support ).freeze
Class Attribute Summary collapse
-
.installed_buses ⇒ Object
readonly
Returns the value of attribute installed_buses.
-
.mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
- #handle(name, arguments) ⇒ Object
-
#initialize(notifier = Chronos, notifications = nil, options = {}) ⇒ NotificationsSubscriber
constructor
A new instance of NotificationsSubscriber.
- #install ⇒ Object
Constructor Details
#initialize(notifier = Chronos, notifications = nil, options = {}) ⇒ NotificationsSubscriber
Returns a new instance of NotificationsSubscriber.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 29 def initialize(notifier = Chronos, notifications = nil, = {}) @notifier = notifier @notifications = notifications || active_support_notifications @sql_normalizer = Core::SqlNormalizer.new @query_analyzer = [:query_analyzer] || Core::SqlQueryAnalyzer.new @query_inspector = [:query_inspector] || default_query_inspector @query_inspection_mutex = Mutex.new @query_inspections = {} @query_analyses = {} @clock = [:clock] || proc { Process.clock_gettime(Process::CLOCK_MONOTONIC) } @transaction_mutex = Mutex.new @transactions = {} = notifier.respond_to?(:cache_integration_options) ? notifier. : {} @cache_normalizer = Core::CacheNormalizer.new( [:project_id].to_s, [:key_mode] || :none ) end |
Class Attribute Details
.installed_buses ⇒ Object (readonly)
Returns the value of attribute installed_buses.
26 27 28 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 26 def installed_buses @installed_buses end |
.mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
26 27 28 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 26 def mutex @mutex end |
Instance Method Details
#handle(name, arguments) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 61 def handle(name, arguments) event = notification_event(name, arguments) dispatch(name, event[:payload], event[:duration_ms]) rescue StandardError false end |
#install ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chronos/rails/notifications_subscriber.rb', line 47 def install return false unless @notifications && @notifications.respond_to?(:subscribe) self.class.mutex.synchronize do return false if self.class.installed_buses[@notifications.object_id] event_names.each { |name| subscribe(name) } self.class.installed_buses[@notifications.object_id] = true end true rescue StandardError false end |