Module: Shrine::Plugins::Instrumentation

Defined in:
lib/shrine/plugins/instrumentation.rb

Overview

Documentation can be found on shrinerb.com/docs/plugins/instrumentation

Defined Under Namespace

Modules: ClassMethods, FileMethods, InstanceMethods Classes: Event, LogSubscriber, Notifications

Constant Summary collapse

EVENTS =
%i[upload download open exists delete metadata].freeze
LOG_SUBSCRIBER =

We use a proc in order to be able identify listeners.

-> (event) { LogSubscriber.call(event) }

Class Method Summary collapse

Class Method Details

.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/shrine/plugins/instrumentation.rb', line 12

def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
  uploader.opts[:instrumentation] ||= { log_events: EVENTS, subscribers: {} }
  uploader.opts[:instrumentation].merge!(opts)
  uploader.opts[:instrumentation][:notifications] ||= ::ActiveSupport::Notifications

  uploader.opts[:instrumentation][:log_events].each do |event_name|
    uploader.subscribe(event_name, &log_subscriber)
  end
end