|
@ -5,6 +5,7 @@ module Semantic |
|
|
# def logger = SemanticLogger['Rails'] |
|
|
# def logger = SemanticLogger['Rails'] |
|
|
|
|
|
|
|
|
INTERNAL_PARAMS = %i[controller action format _method only_path].freeze |
|
|
INTERNAL_PARAMS = %i[controller action format _method only_path].freeze |
|
|
|
|
|
DEFAULT_DEV_HOSTS = ['127.0.0.1', 'localhost'].freeze |
|
|
|
|
|
|
|
|
def initialize(session_key) |
|
|
def initialize(session_key) |
|
|
@session_key = session_key |
|
|
@session_key = session_key |
|
@ -38,7 +39,7 @@ module Semantic |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def finish_processing(event) |
|
|
def finish_processing(event) |
|
|
session_value = @transactions.delete(event.transaction_id) # get previous session_value from start_processing |
|
|
|
|
|
|
|
|
session_value = @transactions.delete(event.transaction_id) # delete previous session_value from start_processing |
|
|
SemanticLogger.tagged(session_value) do |
|
|
SemanticLogger.tagged(session_value) do |
|
|
payload = event.payload |
|
|
payload = event.payload |
|
|
additions = ActionController::Base.log_process_action(payload) |
|
|
additions = ActionController::Base.log_process_action(payload) |
|
@ -63,8 +64,38 @@ module Semantic |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def redirect_to(event) |
|
|
|
|
|
SemanticLogger.tagged(@transactions[event.transaction_id]) do |
|
|
|
|
|
location = capture_path(event.payload[:location]) |
|
|
|
|
|
logger.debug("Redirected to #{colorize(location, BOLD)}") |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def any_hook(event) |
|
|
|
|
|
SemanticLogger.tagged(@transactions[event.transaction_id]) do |
|
|
|
|
|
logger.warn("action_controller hook=<#{event.name.split('.')[0]}> needs a proper message handling!", |
|
|
|
|
|
event.payload.keys) |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
def redirect_regex |
|
|
|
|
|
return @redirect_regex if defined?(@redirect_regex) |
|
|
|
|
|
|
|
|
|
|
|
options = Rails.application.routes.default_url_options |
|
|
|
|
|
dev_hosts = DEFAULT_DEV_HOSTS + Array.wrap(options[:host]) |
|
|
|
|
|
dev_hosts_or = dev_hosts.uniq.join('|') |
|
|
|
|
|
dev_from = "http://(?:#{dev_hosts_or}):#{options[:port]}(.*)" |
|
|
|
|
|
|
|
|
|
|
|
@redirect_regex = /^#{dev_from}/ |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def capture_path(url) |
|
|
|
|
|
m = redirect_regex.match(url) |
|
|
|
|
|
m.nil? ? url : m[1] |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def session_value(event) = event.payload[:headers]['rack.session'].fetch(@session_key, nil) |
|
|
def session_value(event) = event.payload[:headers]['rack.session'].fetch(@session_key, nil) |
|
|
def process_duration(event, additions) = "Processed in #{event.duration.round}ms (#{additions.join(' | ')})" |
|
|
def process_duration(event, additions) = "Processed in #{event.duration.round}ms (#{additions.join(' | ')})" |
|
|
end |
|
|
end |
|
|