|
@ -3,24 +3,49 @@ module Semantic |
|
|
include SemanticLogger::Loggable |
|
|
include SemanticLogger::Loggable |
|
|
# def logger = SemanticLogger['Rails'] |
|
|
# def logger = SemanticLogger['Rails'] |
|
|
|
|
|
|
|
|
SESSION_KEY = 'toto1'.freeze |
|
|
|
|
|
|
|
|
EMPTY = 'none'.freeze |
|
|
|
|
|
|
|
|
def initialize |
|
|
|
|
|
|
|
|
def initialize(session_key) |
|
|
|
|
|
@session_key = session_key |
|
|
|
|
|
@transactions = {} |
|
|
|
|
|
super() |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def start_processing(event) |
|
|
def start_processing(event) |
|
|
request = event.payload[:request] |
|
|
|
|
|
rack_session = event.payload[:headers]['rack.session'] |
|
|
|
|
|
session_value = rack_session.fetch(SESSION_KEY, 'EMPTY') |
|
|
|
|
|
|
|
|
|
|
|
format = event.payload[:format] |
|
|
|
|
|
format = format.to_s.upcase if format.is_a?(Symbol) |
|
|
|
|
|
format = '*/*' if format.nil? |
|
|
|
|
|
|
|
|
session_value = session_value(event) |
|
|
|
|
|
@transactions[event.transaction_id] = session_value # preserve session_value to help finish_processing |
|
|
|
|
|
|
|
|
SemanticLogger.tagged(session_value) do |
|
|
SemanticLogger.tagged(session_value) do |
|
|
|
|
|
request = event.payload[:request] |
|
|
logger.info("Started #{request.raw_request_method} #{request.filtered_path}") |
|
|
logger.info("Started #{request.raw_request_method} #{request.filtered_path}") |
|
|
|
|
|
|
|
|
|
|
|
format = event.payload[:format] |
|
|
|
|
|
format = format.to_s.upcase if format.is_a?(Symbol) |
|
|
|
|
|
format = '*/*' if format.nil? |
|
|
logger.debug("Processing by #{event.payload[:controller]}##{event.payload[:action]} as #{format}") |
|
|
logger.debug("Processing by #{event.payload[:controller]}##{event.payload[:action]} as #{format}") |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def finish_processing(event) |
|
|
|
|
|
session_value = @transactions.delete(event.transaction_id) # get previous session_value from start_processing |
|
|
|
|
|
SemanticLogger.tagged(session_value) do |
|
|
|
|
|
payload = event.payload |
|
|
|
|
|
additions = ActionController::Base.log_process_action(payload) |
|
|
|
|
|
status = payload[:status] |
|
|
|
|
|
|
|
|
|
|
|
if status.nil? && (exception_class_name = payload[:exception]&.first) |
|
|
|
|
|
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
additions << "GC: #{event.gc_time.round(1)}ms" |
|
|
|
|
|
|
|
|
|
|
|
logger.info("Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms " \ |
|
|
|
|
|
"(#{additions.join(' | ')})") |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
def session_value(event) = event.payload[:headers]['rack.session'].fetch(@session_key, EMPTY) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |