aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_storage/service.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-09 17:04:28 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-09 17:04:28 +0200
commit4bfe7af68f1e1a7d02ace760ac1a5c5a4462edb2 (patch)
tree62e0823e734c6a2e573811e2c483e771b70529f2 /lib/active_storage/service.rb
parent57fd9d2247ea4c5058cad1998e4ec32325c4c7e3 (diff)
downloadrails-4bfe7af68f1e1a7d02ace760ac1a5c5a4462edb2.tar.gz
rails-4bfe7af68f1e1a7d02ace760ac1a5c5a4462edb2.tar.bz2
rails-4bfe7af68f1e1a7d02ace760ac1a5c5a4462edb2.zip
Instrument and log the services
Diffstat (limited to 'lib/active_storage/service.rb')
-rw-r--r--lib/active_storage/service.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/active_storage/service.rb b/lib/active_storage/service.rb
index 86f867c293..f50849b694 100644
--- a/lib/active_storage/service.rb
+++ b/lib/active_storage/service.rb
@@ -1,3 +1,5 @@
+require_relative "log_subscriber"
+
# Abstract class serving as an interface for concrete services.
#
# The available services are:
@@ -35,6 +37,8 @@ class ActiveStorage::Service
extend ActiveSupport::Autoload
autoload :Configurator
+ class_attribute :logger
+
class << self
# Configure an Active Storage service by name from a set of configurations,
# typically loaded from a YAML file. The Active Storage engine uses this
@@ -73,4 +77,16 @@ class ActiveStorage::Service
def url(key, expires_in:, disposition:, filename:)
raise NotImplementedError
end
+
+ private
+ def instrument(operation, key, payload = {}, &block)
+ ActiveSupport::Notifications.instrument(
+ "service_#{operation}.active_storage",
+ payload.merge(key: key, service: service_name), &block)
+ end
+
+ def service_name
+ # ActiveStorage::Service::DiskService => Disk
+ self.class.name.split("::").third.remove("Service")
+ end
end