Module: Shrine::Plugins::Instrumentation

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

Overview

Documentation lives in [doc/plugins/instrumentation.md] on GitHub.

[doc/plugins/instrumentation.md]: github.com/shrinerb/shrine/blob/master/doc/plugins/instrumentation.md

Defined Under Namespace

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

Constant Summary collapse

EVENTS =
%i[upload download 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, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shrine/plugins/instrumentation.rb', line 14

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

  # we assign it to the top-level so that it's duplicated on subclassing
  uploader.opts[:instrumentation_subscribers] ||= Hash.new { |h, k| h[k] = [] }

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