Browse Source

active_record

main
pvincent 2 months ago
parent
commit
9894abbac4
  1. 9
      config/initializers/instrumentalizing.rb
  2. 2
      lib/semantic/subscribers/action_view.rb
  3. 28
      lib/semantic/subscribers/active_record.rb

9
config/initializers/instrumentalizing.rb

@ -8,8 +8,8 @@ return unless Rails.application.server?
def build_instrumentation_config def build_instrumentation_config
{ {
action_controller: true, action_controller: true,
action_view: Live::Constants::ACTION_VIEW
# active_record: Live::Constants::ACTIVE_RECORD
action_view: Live::Constants::ACTION_VIEW,
active_record: Live::Constants::ACTIVE_RECORD
}.map do |key, value| }.map do |key, value|
key if value key if value
end.compact end.compact
@ -27,6 +27,9 @@ Rails.configuration.after_initialize do
end end
Rails.autoloaders.main.on_load('ApplicationController') do Rails.autoloaders.main.on_load('ApplicationController') do
Rails.logger.debug 'Zeitwerk RELOAD!'
Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1)
Rails.logger.fatal 'Zeitwerk RELOAD!', dimensions: Semantic::FancyDimensions.new(rails: '╠█╣')
Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╚═╝')
Semantic::Instrumentalizer.activate(*build_instrumentation_config) Semantic::Instrumentalizer.activate(*build_instrumentation_config)
end end

2
lib/semantic/subscribers/action_view.rb

@ -6,8 +6,6 @@ module Semantic
REGEX_BASEDIR = %r{^#{Rails.root}/(.*)} REGEX_BASEDIR = %r{^#{Rails.root}/(.*)}
attr_reader :logger
def render_partial(event) def render_partial(event)
identifier = pathname(event.payload[:identifier]) identifier = pathname(event.payload[:identifier])
# logger.debug("Rendered partial #{identifier}", event.payload[:locals]) if identifier # logger.debug("Rendered partial #{identifier}", event.payload[:locals]) if identifier

28
lib/semantic/subscribers/active_record.rb

@ -0,0 +1,28 @@
module Semantic
module Subscribers
# LogSubscriber for event_group :active_record
class ActiveRecord < LogSubscriber
include AnsiColors
def sql(event)
name = event.payload[:name]
return if name == 'SCHEMA'
sql = event.payload[:sql]
cached = event.payload[:cached]
row_count = event.payload[:row_count]
logger.debug("#{name}: #{sql} cached=#{cached} count=#{row_count}")
end
def instantiation(event)
class_name = event.payload[:class_name]
record_count = event.payload[:record_count]
logger.debug("instantiate #{class_name} #{record_count} times")
end
def strict_loading_violation(event) = any_hook event
def start_transaction(event) = any_hook event
def transaction(event) = any_hook event
end
end
end
Loading…
Cancel
Save