Code Monkey home page Code Monkey logo

active-record-query-trace's People

Contributors

avit avatar brunofacca avatar bryant1410 avatar carsonreinke avatar cvx avatar delphaber avatar eitoball avatar gr-eg avatar huguesbr avatar jvlara avatar mtyeh411 avatar palkan avatar ridiculous avatar ruckus avatar seanlinsley avatar sgbett avatar sponomarev avatar tinynumbers avatar tommyh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

active-record-query-trace's Issues

uninitialized constant ActiveRecordQueryTrace (NameError)

The awesome console is fine when I use rails s, but fails in rspec.

I put this code in config/initializers/active_record_query_trace.rb

if ENV['QUERY_TRACE'] == 'true'
  ActiveRecordQueryTrace.enabled = true
  ActiveRecordQueryTrace.colorize = 'light purple'
end

When I run rspec, it threw this error.

/config/initializers/active_record_query_trace.rb:2:in `<top (required)>': uninitialized constant ActiveRecordQueryTrace (NameError)
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:166:in `instrument'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/engine.rb:651:in `load_config_initializer'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/engine.rb:615:in `each'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:30:in `instance_exec'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:30:in `run'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:55:in `block in run_initializers'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `each'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `tsort_each_child'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:411:in `call'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `each'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `tsort_each_child'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:411:in `call'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:345:in `each'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:345:in `call'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
  from /Users/Coda/.rvm/rubies/ruby-2.1.10/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/initializable.rb:54:in `run_initializers'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/railties-4.2.7.1/lib/rails/application.rb:352:in `initialize!'
  from /Users/Coda/Desktop/my_project/config/environment.rb:5:in `<top (required)>'
  from /Users/Coda/Desktop/my_project/spec/rails_helper.rb:4:in `require'
  from /Users/Coda/Desktop/my_project/spec/rails_helper.rb:4:in `<top (required)>'
  from /Users/Coda/Desktop/my_project/spec/api/missions_controller_spec.rb:2:in `require'
  from /Users/Coda/Desktop/my_project/spec/api/missions_controller_spec.rb:2:in `<top (required)>'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `load'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/bin/rspec:23:in `load'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/bin/rspec:23:in `<main>'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/bin/ruby_executable_hooks:15:in `eval'
  from /Users/Coda/.rvm/gems/ruby-2.1.10@rails320/bin/ruby_executable_hooks:15:in `<main>'

Log in Rail's test env

I apologize if I'm missing this in the documentation but would it be possible to log to the test log in in the rails test env?

ActiveRecordQueryTrace.lines default value seems wrong

This is from the readme

ActiveRecordQueryTrace.lines = 10 # Default is 5. Setting to 0 includes entire trace.

When I enable :full scope, my log explodes.. is default actually 0?
I have not set it in my initializer

p.s. thanks a lot for this gem, just solved a major performance issue in a very short time thanks to this!

Version 1.5.2 has stopped working

Hi,

I just noticed now that my logs no longer contain "Called From" rows.
Locking the gem back with gem 'active_record_query_trace', '1.5' solves it

This is my initializer, and I know it is called.

# config/initializers/activerecord_query_trace.rb
if defined? ActiveRecordQueryTrace
  ActiveRecordQueryTrace.enabled = true
  ActiveRecordQueryTrace.level = :app
  ActiveRecordQueryTrace.ignore_cached_queries = true
  ActiveRecordQueryTrace.lines = 2
end

Is there some change I am unaware of in 1.5.2, or is this a bug?

Use in Rails 2

Hi all,

I'm working with an enormous legacy app (Rails 2.3) with some pretty muddled spaghetti code in certain parts. Having the functionality provided by this gem would make some debugging and refactoring efforts significantly easier. Does anyone have suggestions as to how I might make this gem work in Rails 2? I realize it's using core features provided in Rails 3 and trying to reimplement them in a Rails 2 app would be insane. Any thoughts or suggestions would be well received. Thanks!

Enabling to do query trace on gems.

I have developed my own gems to share logic along many projects. I run the rails console on my project containing the gem i want to do query trace.

I have enabled the active record query trace and it logs correctly on the logic of the project but it seems to be Randomly working on the code contained in the gem.

I have to restart the console and sometimes it logs the sql queries of the gem and some others it doesn't, which is puzzling.

The gem is in a private repository, so I am not sure what data to provide besides the ruby, rails and ARQT gem version:

gem 'rails', '~> 5.1', '>= 5.1.4'
active_record_query_trace (1.8)
Ruby 2.7

Thanks for any advice.

NameError: uninitialized constant ActiveRecordQueryTrace with test

Only use development

group :development do
  gem 'active_record_query_trace'
end

rails s is work

% bin/rails s

work!

RAILS_ENV=test bin/rails s is not work

RAILS_ENV=test bin/rails s

Error message

uninitialized constant ActiveRecordQueryTrace (NameError)

With RSpec is same error

% bundle exec rspec

Error message

bundler: failed to load command: rspec
NameError: uninitialized constant ActiveRecordQueryTrace

not changing how logs are shown

Hello,

I'm trying to figure out an N+1 queries issue, but I can't figure out how to get this gem working for me, on rails 6.1.6.1

Nothing I do seems to change how activerecord queries are logged.

that is:

2022-08-10 08:35:18.536410 D [74:puma srv tp 004] (0.006ms) ActiveRecord -- Model Load -- { :sql => "SELECT ....", :binds => { .... }, :allocations => 1, :cached => true }

here's my configuration of the gem:

if Rails.env.development?
  ActiveRecordQueryTrace.enabled = true
  ActiveRecordQueryTrace.level = :full
  ActiveRecordQueryTrace.colorize = true
  # Optional: other gem config options go here
end

I added a byebug line here, and it's called a bunch of times at rails boot up time (Flipper gem loading the features) which are not logged at all. but then it's not called anymore.

Any ideas?

Thanks.

Use Outside of Rails

I would like to use this gem in a non-rails app that uses AR. Not sure how to get this hooked into the app though.

Could you add some commentary to the README to address this?

Thanks.

Cache queries are logged even with option to not log them

Hi,
I'm using active_record_query_trace (1.5.4) with Rails 5.1.5.

This is my initializer config:

if Rails.env.development?
  ActiveRecordQueryTrace.enabled = true
  ActiveRecordQueryTrace.colorize = 'light purple'
  ActiveRecordQueryTrace.ignore_cached_queries = true
end

However, ignored cached queries is not working:

image

Any idea why?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

LogSubscriber muddling query trace

Hello! Just wanted to start a discussion on this. I noticed that the actual logging of each query is included in the trace. This muddles the trace. I was thinking of adding another filter to the trace cleaner to remove this plugin's additions to the trace. Thoughts?

Alternative mode: add a comment with file:number to the SQL query

Rather than printing traces to stdout, it'd be great to annotate queries with the stacktrace or the first non-framework frame:

SELECT 1; -- app/controllers/blah.rb:87

This way we're not spamming stdout with irrelevant data. Instead, we're annotating queries, and only when a query is slow and lands in the slowlog, the stacktrace is saved. It's a more storage-efficient and cost-efficient way of doing what the plugin currently does! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.