Perfect 👍
Here’s a clean, professional, RubyGems-ready README that fits the quality of the gem you’re building.
You can copy-paste this directly into README.md.
Rails API Profiler is a lightweight, middleware-based performance profiling tool for Rails API applications. It provides request-level insights such as response time, database query count, and database execution time — with zero changes to your controllers or business logic.
Designed to be simple, fast, and production-safe, it supports Rails 5 and above.
- 🚀 Measures API request duration
- 🗄️ Tracks ActiveRecord query count
- ⏱️ Tracks total database execution time
- ⚙️ Middleware-based (no controller code required)
- 🔕 Can be enabled/disabled via configuration
- 🧪 Safe for development, staging, and debugging
- 🧩 Works with Rails 5+
Add the gem to your Gemfile:
gem "rails_api_profiler", group: [:development, :staging]Then install:
bundle installThat’s it — no further setup required.
You can optionally configure the profiler in an initializer:
# config/initializers/rails_api_profiler.rb
RailsApiProfiler.configure do |config|
config.enabled = true
config.slow_request_threshold = 500 # milliseconds
end| Option | Description | Default |
|---|---|---|
enabled |
Enable or disable profiling | true |
slow_request_threshold |
Threshold for slow request warnings (ms) | 500 |
logger |
Custom logger instance | Rails.logger |
[RailsApiProfiler] {:method=>"GET",
:path=>"/api/v1/users",
:status=>200,
:duration_ms=>183.21,
:db_queries=>7,
:db_time_ms=>41.8}
For slow requests:
[RailsApiProfiler] SLOW REQUEST {:method=>"POST",
:path=>"/api/v1/orders",
:status=>201,
:duration_ms=>812.44,
:db_queries=>18,
:db_time_ms=>220.3}
- Uses a Rack middleware to measure request duration
- Hooks into ActiveSupport::Notifications to track SQL queries
- Stores per-request stats using thread-local storage
- Automatically attaches via a Rails Railtie
No monkey-patching. No controller hooks. No overhead outside requests.
- Rails: 5.0+
- Ruby: 2.4+
This gem is ideal when you want to:
- Identify slow API endpoints
- Detect excessive database queries
- Debug performance regressions
- Profile APIs in development or staging
- Keep instrumentation lightweight
- As a full APM replacement (Datadog, New Relic, etc.)
- For deep flamegraph analysis
- For long-running background jobs
This gem focuses on request-level clarity, not heavy analytics.
Planned improvements:
- JSON / structured log formatter
- N+1 query detection
- Prometheus exporter
- Memory usage tracking
- Optional endpoint filtering
Contributions are welcome!
- Fork the repository
- Create a feature branch
- Add tests
- Submit a pull request
Please ensure all specs pass before submitting.
This project is licensed under the MIT License.
Sparsh Garg GitHub: https://github.com/sparsh9