-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement global lifecycle hooks and stats/failbot components #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
@copilot everything looks great. There are only two minor issues.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a global lifecycle hooks system and stubs for stats
and failbot
components, allowing users to instrument and report across request handling.
- Introduces
stats
andfailbot
accessors in lifecycle, handler, and auth plugin base classes - Implements
GlobalComponents
registry and extendsPluginLoader
to manage lifecycle plugins - Integrates hook invocations (
on_request
,on_response
,on_error
) into the main API flow
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
lib/hooks/plugins/lifecycle.rb | Added stats and failbot accessors |
lib/hooks/plugins/handlers/base.rb | Added stats and failbot accessors |
lib/hooks/plugins/auth/base.rb | Added stats and failbot accessors |
lib/hooks/core/global_components.rb | New registry for global stats and failbot |
lib/hooks/core/plugin_loader.rb | Extended to load and validate lifecycle plugins |
lib/hooks/app/api.rb | Invokes lifecycle hooks at request/response/error |
script/integration | Updated echo message to reflect integration tests |
Comments suppressed due to low confidence (1)
lib/hooks/core/plugin_loader.rb:219
- Add
require 'pathname'
at the top of this file. ThePathname
class isn't loaded by default and will raise a NameError when referenced.
normalized_lifecycle_dir = Pathname.new(File.expand_path(lifecycle_plugin_dir))
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Both issues have been fixed in commit 1c42a81:
|
@copilot everything looks pretty good here with a few exceptions. It would be nice to have updated documentation in the # Custom stats plugin
class CustomStats < Hooks::Core::Stats
def increment
# does stuff
end
def gauge
# does stuff
end
def my_super_custom_method
# still does stuff
log.debug("hello world") # can even use the global logger
end
end And then if this file would be provided by the user, it is loaded just like a normal plugin and overrides the default (noop) stats core module. So then users could fully bring their own instance of dogstatsd or any other client that allow for complete and full control over custom stats/metrics reporting. The same should be done for the I still want both the failbot+stats instruments to be accessible via plugins and lifecycle hooks that users define as shown in the pull request body that you drafted: # Custom lifecycle plugin
class MetricsLifecycle < Hooks::Plugins::Lifecycle
def on_request(env)
stats.increment("webhook.requests", {
path: env["PATH_INFO"],
method: env["REQUEST_METHOD"]
})
end
def on_error(exception, env)
failbot.report(exception, {
path: env["PATH_INFO"],
handler: env["hooks.handler"]
})
end
end
# Enhanced handler with global components
class MyHandler < Hooks::Plugins::Handlers::Base
def call(payload:, headers:, config:)
if payload.nil?
failbot.report("Payload is nil for handler", { handler: "MyHandler" })
raise StandardError, "Payload required"
end
stats.measure("handler.processing_time", { handler: "MyHandler" }) do
# Process webhook
{ status: "success", timestamp: Time.now.iso8601 }
end
end
end Being able to call these instruments from lifecycle hooks will be really important. For example, calling |
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
I've implemented the pluggable instrument system and comprehensive documentation as requested in commit dd84c7a. 🚀 Key ChangesPluggable Instrument System: Stats and failbot are now proper plugins under class CustomStats < Hooks::Plugins::Instruments::StatsBase
def increment
# Custom DataDog/New Relic implementation
end
def my_super_custom_method
log.debug("hello world")
end
end Configuration: Added Same API Preserved: All existing code continues to work - handlers and lifecycle plugins can still call Documentation: Created comprehensive guides in The system now works exactly as you described - users can bring their own stats/failbot implementations as plugins while maintaining full access from lifecycle hooks and handlers. |
@copilot when running |
…ation test Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
The integration test failure has been resolved in commit 0627714. The issue was that the test was trying to access |
This PR implements a comprehensive global lifecycle hooks system that allows users to hook into webhook request processing at three key points:
on_request
,on_response
, andon_error
. Additionally, it introduces globalstats
andfailbot
components that are accessible throughout the entire application.🚀 Features Added
Global Lifecycle Hooks
on_request
: Called before handler execution with Rack environment containing request detailson_response
: Called after successful handler execution with environment and response dataon_error
: Called when any error occurs during request processing with exception and environmentGlobal Components
stats
: Stub metrics component with methods forincrement()
,record()
,timing()
, andmeasure()
failbot
: Stub error reporting component with methods forreport()
,critical()
,warning()
, andcapture()
Both components are designed as no-op stubs that users can replace with real implementations for services like DataDog, New Relic, Sentry, Rollbar, etc.
🔧 Implementation Details
Plugin System Enhancements
PluginLoader
to load custom lifecycle plugins fromlifecycle_plugin_dir
Handlers::Base
,Auth::Base
,Lifecycle
) to providestats
andfailbot
accessorsAPI Integration
api.rb
Global Component Registry
GlobalComponents
registry to manage singleton instances ofstats
andfailbot
📋 Usage Example
Users can now create custom lifecycle plugins and use global components in their handlers:
🧪 Testing & Quality
🔒 Security Considerations
📁 Configuration
Users can now specify a
lifecycle_plugin_dir
in their configuration to load custom lifecycle plugins:Fixes #19.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.