New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

query_track

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

query_track

  • 0.0.14
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

QueryTrack

Gem Version Maintainability

Tool for finding time-consuming database queries for ActiveRecord-based Rails Apps. Provides Slack notifications with backtrace, raw SQL, time duration, etc.

Installation

Add this line to your application's Gemfile and then execute bundle install:

gem 'query_track'

Usage

SQL Duration Limit

Specify SQL duration query limit (in seconds):

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
end

Console Log

Enable console logs from config:

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
  config.logs = true
end

Log Example

Filters

To avoid noisy warnings from used gems, and places where fat queries are justified, you can filters SQL by backtrace. For example, you have installed activeadmin and want to skip everything from app/admin:

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
  config.filters = ['app/admin']
end

App Directory

QueryTrack finds the trace by filtering the caller by the app directory. By default, the app directory is set to 'app', the default for Rails apps. For apps that have a non-stanard app directory, this can be set with the app_dir config field:

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
  config.app_dir = 'backend'
end

Enable/Disable toggle

Enable/disable with ENV variables to turn it on/off without code push. By default QueryTrack is enabled.

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
  config.enabled = ENV['QUERY_TRACK_ENABLED']
end

Slack Notifications

To receive notifications about slow queries into Slack, you need to install incoming-webhooks and put link into config file:

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
  config.notifications.slack = 'https://hooks.slack.com/services/T0000000/B0000000/C0000000'
end

Incoming Hook Example

Custom Notifications (Handlers)

You can write your own handler for slow queries. Send data to any source(for e.g. to logs storage) or make notification for another source(Email, Messengers, etc.)

QueryTrack::Settings.configure do |config|
  config.duration = 0.5
  config.notifications.custom_handler = -> (sql, duration, trace) {
    # data processing...
  }
end

Production Usage Notes

When QueryTrack send slack hooks, request is executed in separate thread. So there should be no synchronous delays.

Subscription to SQL events and checking duration time actually take insignificant time in milliseconds.

If your project is horizontally scaled, you can install query_track for one of the node to avoid performance degrade for whole application.

Contributing

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

License

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

FAQs

Package last updated on 16 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc