Browse Source

active_record improved 1

main
pvincent 3 months ago
parent
commit
c665eb0d31
  1. 3
      config/initializers/backtrace_cleaning.rb
  2. 12
      config/initializers/instrumentalizing.rb
  3. 4
      lib/semantic/instrumentalizer.rb
  4. 4
      lib/semantic/subscribers/action_controller.rb
  5. 21
      lib/semantic/subscribers/active_record.rb

3
config/initializers/backtrace_cleaning.rb

@ -1,2 +1,3 @@
bc = Rails.backtrace_cleaner
bc.add_silencer { |line| %r{^lib/(monkey_patches|semantic)}.match?(line) }
# bc.add_silencer { |line| %r{^lib/(monkey_patches|semantic)}.match?(line) }
bc.add_silencer { |line| %r{^lib/(monkey_patches)}.match?(line) }

12
config/initializers/instrumentalizing.rb

@ -1,11 +1,5 @@
return unless Rails.application.server?
if Rails.env.development?
RailsSemanticLogger::Rack::Logger.logger.level = :info # useful for remaining log like "[Rack::Log] Started..."
SemanticLogger.clear_appenders!
Rails.logger.name = 'rails'
end
def build_instrumentation_config
{
action_controller: true,
@ -17,6 +11,12 @@ def build_instrumentation_config
end
Rails.configuration.after_initialize do
if Rails.env.development?
RailsSemanticLogger::Rack::Logger.logger.level = :info # useful for remaining log like "[Rack::Log] Started..."
SemanticLogger.clear_appenders!
Rails.logger.name = 'rails'
end
ActiveSupport::Notifications.subscribe('rolling.live_constant') do |event|
constants = event.payload[:changes].map { |change| change[:constant] }
if constants.intersection(%w[ACTIVE_RECORD ACTION_VIEW]).any?

4
lib/semantic/instrumentalizer.rb

@ -40,6 +40,8 @@ module Semantic
subscriber = ActiveSupport::Notifications.subscribe("#{hook}.#{event_group}") do |event|
# logger.debug("SEND #{log_subscriber} hook=#{hook}")
log_subscriber.send(hook, event)
rescue StandardError => e
logger.error('Error during instrumentation handling', e)
end
global_subscribers << subscriber
end
@ -49,7 +51,7 @@ module Semantic
classname = event_group.to_s.camelize
case classname
when 'ActionController'
Semantic::Subscribers.const_get(classname).new('toto1')
Semantic::Subscribers.const_get(classname).new('toto1') # FIXME: externalize session_key
else
Semantic::Subscribers.const_get(classname).new
end

4
lib/semantic/subscribers/action_controller.rb

@ -72,12 +72,10 @@ module Semantic
dimensions = case status_family
when 2
Semantic::FancyDimensions.new(rails: TERMINUS_STRING)
when 3
when 3, 5
Semantic::FancyDimensions.new(rails: '╙║╜')
when 4
Semantic::FancyDimensions.new(rails: '╙╨╜')
when 5
Semantic::FancyDimensions.new(rails: '╙║╜')
end
logger.info("Completed #{colorize(status, BOLD)} #{Rack::Utils::HTTP_STATUS_CODES[status]}", dimensions:)
logger.info(' ', dimensions: Semantic::FancyDimensions.new(rails: ' ║ ')) if status_family == 3

21
lib/semantic/subscribers/active_record.rb

@ -18,15 +18,24 @@ module Semantic
logger.debug("#{name} #{sql}")
end
def instantiation(event)
# class_name = event.payload[:class_name]
# record_count = event.payload[:record_count]
# logger.debug("instantiate #{class_name} #{record_count} times")
def start_transaction(event)
short_uuid = short_uuid(event.payload[:transaction].uuid)
logger.info("TRANSACTION Begin #{short_uuid}")
end
def transaction(event)
outcome = event.payload[:outcome]
short_uuid = short_uuid(event.payload[:transaction].uuid)
logger.info("TRANSACTION #{outcome.capitalize} #{short_uuid}")
end
def instantiation(event); end
def strict_loading_violation(event) = any_hook event
def start_transaction(event) = any_hook event
def transaction(event) = any_hook event
private
def short_uuid(uuid) = uuid.split('-').first
end
end
end
Loading…
Cancel
Save