Last active
August 7, 2024 21:11
-
-
Save romanbsd/60fbc0827ce668b1ac8b2c5f1f7f13d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExternalApiRuntime | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def log_process_action(payload) | |
messages = super | |
api_runtime = payload[:api_runtime] | |
messages << (format('ExternalAPI: %.1fms', api_runtime.to_f)) if api_runtime | |
messages | |
end | |
end | |
attr_internal :api_runtime | |
def initialize(...) | |
super | |
self.api_runtime = 0 | |
ActiveSupport::Notifications.subscribe('external_api.call') do |_name, starts, ends, _, _env| | |
self.api_runtime += 1000 * (ends - starts) | |
end | |
end | |
def append_info_to_payload(payload) | |
super | |
payload[:api_runtime] = api_runtime | |
self.api_runtime = 0 | |
end | |
end |
Author
romanbsd
commented
Aug 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment