Skip to content

Instantly share code, notes, and snippets.

@luizpvas
Last active February 2, 2024 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizpvas/b9ec1ffc58f7aed39a38fccefe86549c to your computer and use it in GitHub Desktop.
Save luizpvas/b9ec1ffc58f7aed39a38fccefe86549c to your computer and use it in GitHub Desktop.
rails instrumentation
if Rails.env.development?
::ActiveSupport::Notifications.subscribe 'µ-case' do |*args|
result = args.extract_options![:result]
description = result.use_case.class.name
Rack::MiniProfiler.step("µ-case: #{description}") do
Rails.logger.warn "µ-case called: #{description}"
end
end
module Micro
class Case
class Result
class Transitions
MapEverything = ->(result, use_case_attributes) do
::ActiveSupport::Notifications.instrument 'µ-case', result: result do
{
use_case: { class: result.use_case.class, attributes: use_case_attributes },
result.to_sym => { type: result.type, result: result.data },
accessible_attributes: result.accessible_attributes
}
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment