Skip to content

Log db query count from rails #19

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/chitragupta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def configure_app(app)
require "chitragupta/request_log_formatter"
config.lograge.enabled = true
config.lograge.formatter = RequestLogFormatter::FORMAT
config.lograge.custom_options = lambda do |event|
{:query_count => event.payload[:query_count]}
end
end

# setting the log_tags to empty array to ensure that the message being generated does not contain the unwanted tags
Expand Down
1 change: 1 addition & 0 deletions lib/chitragupta/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def populate_rails_server_data(data, message)

data[:data][:response][:view_rendering_duration] = message[:view] rescue nil
data[:data][:response][:db_query_duration] = message[:db] rescue nil
data[:data][:response][:db_query_count] = message[:query_count] rescue nil
end

def populate_ruby_server_data(data, message)
Expand Down
2 changes: 1 addition & 1 deletion lib/chitragupta/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Chitragupta
VERSION = "0.4.1"
VERSION = "0.4.2"
end
9 changes: 6 additions & 3 deletions spec/chitragupta/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Console
status: nil,
duration: nil,
view_rendering_duration: nil,
db_query_duration: nil
db_query_duration: nil,
db_query_count: nil
}
},
meta: {
Expand Down Expand Up @@ -124,7 +125,8 @@ class Console
status: 200,
duration: 10.01,
view_rendering_duration: 12.34,
db_query_duration: 0.09
db_query_duration: 0.09,
db_query_count: 10
}
},
meta: {
Expand All @@ -137,7 +139,8 @@ class Console
status: 200,
duration: 10.01,
view: 12.34,
db: 0.09
db: 0.09,
query_count: 10
}
Chitragupta::Util.send(:populate_rails_server_data, data, message)
expect(data).to eq(expected_output)
Expand Down