Skip to content
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

Add support to Mongoid #185

Open
wants to merge 1 commit 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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meta_request/lib/meta_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module MetaRequest
autoload :AppRequest, 'meta_request/app_request'
autoload :Storage, 'meta_request/storage'
autoload :Middlewares, 'meta_request/middlewares'
autoload :Subscribers, 'meta_request/subscribers'
autoload :LogInterceptor, 'meta_request/log_interceptor'
autoload :AppNotifications, 'meta_request/app_notifications'
autoload :Utils, 'meta_request/utils'
Expand Down
4 changes: 4 additions & 0 deletions meta_request/lib/meta_request/app_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class AppNotifications
# Subscribe to all events relevant to RailsPanel
#
def self.subscribe
if Mongo and Mongo::Monitoring and Mongo::Monitoring::Global
Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::COMMAND, MetaRequest::Subscribers::MongoCommandSubscriber.new)
end

new
.subscribe('meta_request.log')
.subscribe('sql.active_record', &SQL_BLOCK)
Expand Down
7 changes: 7 additions & 0 deletions meta_request/lib/meta_request/subscribers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module MetaRequest
module Subscribers
autoload :MongoCommandSubscriber, 'meta_request/subscribers/mongo_command_subscriber'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module MetaRequest
module Subscribers
class MongoCommandSubscriber
def started(event)
# puts "Started #{event.command_name}: #{event.command}"
end

def failed(event)
# puts "Failed #{event.command_name}: #{event.message}"
end

def succeeded(event)
start_time = Time.now - event.duration
end_time = Time.now
transaction_id = event.request_id
command = event.started_event.command.to_json
payload = { name: event.command_name, sql: command }
ActiveSupport::Notifications.publish('sql.active_record', start_time, end_time, transaction_id, payload)
end
end
end
end