Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

active_record_tracer

> 后端框架
Open source

A tracer for Active Record queries

200 stars0 likes2 views
WebsiteGitHub

About

A tracer for Active Record queries

ActiveRecordTracer

A tracer for Active Record queries You identified (or suspect) that the reason for the slowness of some code is Active Record, specifically lots of queries and/or loaded records. How do you easily detect which queries, which records are loaded the most, and the sources of those? This tool to the rescue!

Requirements

  • ruby 3.1+
  • activerecord 7.1+

Installation

Add this line to your application's Gemfile:

ruby
gem "active_record_tracer", group: [:development, :test]

And then execute:

bash
$ bundle

Or install it yourself as:

bash
$ gem install active_record_tracer

Usage

ruby
require "active_record_tracer"
report = ActiveRecordTracer.report do
  # run your code here
end

report.pretty_print

Or, you can use the .start/.stop API as well:

ruby
require "active_record_tracer"

ActiveRecordTracer.start

# run your code

report = ActiveRecordTracer.stop
report.pretty_print

NOTE: .start/.stop can only be run once per report, and .stop will be the only time you can retrieve the report using this API.

Tracing tests

To trace tests, use the following in test_helper.rb for Minitest:

ruby
ActiveRecordTracer.start
Minitest.after_run do
  report = ActiveRecordTracer.stop
  report.pretty_print(to_file: "tmp/active_record_tracer-tests.txt")
end

Options

report

The report method can take a few options:

  • top: maximum number of entries to display in a report (default is 50)
  • backtrace_lines: maximum number of backtrace lines to include in the report (default is 5)
  • ignore_cached_queries: whether to ignore cached queries (default is false)
  • ignore_schema_queries: whether to ignore schema queries (default is true)

Check out Reporter#new for more details.

pretty_print

The pretty_print method can take a few options:

  • to_file: a path to your log file - can be given a String
  • detailed_report: whether to include detailed information - can be given a Boolean

Check out Report#pretty_print for more details.

Example output

…

Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rake test to run the tests. This project uses multiple Gemfiles to test against multiple versions of Active Record; you can run the tests against the specific version with BUNDLE_GEMFILE=gemfiles/activerecord_70.gemfile bundle exec rake test.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fatkodima/active_record_tracer.

License

The gem is available as open source under the terms of the MIT License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyactiverecordgemrailsruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架