-
Notifications
You must be signed in to change notification settings - Fork 3
Description
This project has some prior art around the possibility of global lifecycle hooks and this issue tracks work to implement them.
The following lifecycle hooks should be created and do nothing to begin with but allow for the user to provide their own plugins that hydrate them with actions. For example, if a user provided the on_request plugin that logs the path of the inbound request then it would apply to all routes. In a similar manner the following lifecycle hooks should be implemented:
on_requeston_responseon_error
There is some prior art in the lib/hooks/plugins/lifecycle.rb file but it currently doesn't do anything and is fairly outdated to the rest of the project now.
In addition to adding these lifecycle hooks, there should also be two new globally accessible components. These new components should be available to every part of the core application and also to the lifecycle hooks, handler plugins, and auth plugins. They should be called stats and failbot. The intention is that the global component stats could be used for submitting metrics to datadog, newrelic, etc. Same goes for failbot and it is a custom error metrics reporter for services like Sentry, etc. Neither of these global components should do anything to start and are intended to be implemented by the user if they chose to adopt them.
The idea is that the user could do something like
# frozen_string_literal: true
class Example < Hooks::Plugins::Handlers::Base
def call(payload:, headers:, config:)
if payload.nil?
failbot.report("oh no, the payload is nil for some reason!")
raise StandardError, "oh no the payload is nil"
end
{
status: "success",
handler: "Example",
timestamp: Time.now.iso8601
}
end
endBoth the lifecycle hooks and stats/failbot features are tightly coupled as they help to serve the same cause of getting metrics/exceptions out of the Hooks application and to third party services. This can either happen internally in the core parts of the Hooks app, or in the plugins that end users are writing so they need are highly dependent on each other.