|
@ -1,12 +1,13 @@ |
|
|
module Semantic |
|
|
module Semantic |
|
|
# enable/disable instrumentation callbacks |
|
|
|
|
|
class Instrumentalizer |
|
|
|
|
|
NOTIFICATIONS = { |
|
|
NOTIFICATIONS = { |
|
|
action_controller: %i[start_processing process_action redirect_to], |
|
|
action_controller: %i[start_processing process_action redirect_to], |
|
|
action_view: %i[render_partial render_template render_collection render_layout], |
|
|
action_view: %i[render_partial render_template render_collection render_layout], |
|
|
active_record: %i[sql strict_loading instantiation start_transaction transaction] |
|
|
active_record: %i[sql strict_loading instantiation start_transaction transaction] |
|
|
}.freeze |
|
|
}.freeze |
|
|
|
|
|
|
|
|
|
|
|
# enable/disable instrumentation callbacks |
|
|
|
|
|
class Instrumentalizer |
|
|
|
|
|
include SemanticLogger::Loggable |
|
|
class << self |
|
|
class << self |
|
|
def activate(*event_groups) |
|
|
def activate(*event_groups) |
|
|
reset |
|
|
reset |
|
@ -15,24 +16,28 @@ module Semantic |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
|
|
|
|
|
|
|
def logger = @logger ||= SemanticLogger[:instrumentation] |
|
|
|
|
|
|
|
|
def global_subscribers = $global_subscribers ||= [] # rubocop:disable Style/GlobalVars |
|
|
|
|
|
|
|
|
def reset |
|
|
def reset |
|
|
|
|
|
global_subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
|
|
global_subscribers.clear |
|
|
|
|
|
|
|
|
NOTIFICATIONS.each do |event_group, hooks| |
|
|
NOTIFICATIONS.each do |event_group, hooks| |
|
|
hooks.each { |hook| ActiveSupport::Notifications.unsubscribe("#{hook}.#{event_group}") } |
|
|
|
|
|
|
|
|
hooks.each do |hook| |
|
|
|
|
|
hook_full_name = "#{hook}.#{event_group}" |
|
|
|
|
|
ActiveSupport::Notifications.unsubscribe(hook_full_name) |
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def enable(event_group) |
|
|
def enable(event_group) |
|
|
logger.debug { "enabling: #{event_group}" } |
|
|
|
|
|
|
|
|
|
|
|
log_subscriber = build_log_subscriber_from(event_group) |
|
|
log_subscriber = build_log_subscriber_from(event_group) |
|
|
NOTIFICATIONS[event_group].each do |hook| |
|
|
NOTIFICATIONS[event_group].each do |hook| |
|
|
logger.info("subscribe to #{hook}.#{event_group}") |
|
|
|
|
|
ActiveSupport::Notifications.subscribe("#{hook}.#{event_group}") do |event| |
|
|
|
|
|
|
|
|
subscriber = ActiveSupport::Notifications.subscribe("#{hook}.#{event_group}") do |event| |
|
|
# logger.debug("SEND #{log_subscriber} hook=#{hook}") |
|
|
# logger.debug("SEND #{log_subscriber} hook=#{hook}") |
|
|
log_subscriber.send(hook, event) |
|
|
log_subscriber.send(hook, event) |
|
|
end |
|
|
end |
|
|
|
|
|
global_subscribers << subscriber |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|