Created
December 5, 2014 21:11
-
-
Save ashanbrown/f6d9ea48d897e77a8b27 to your computer and use it in GitHub Desktop.
initializer monkey patch to get new_relic explains to show up when using octopus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if defined?(NewRelic::Agent::Instrumentation::ActiveRecordSubscriber) | |
module NewRelic | |
module Agent | |
module Instrumentation | |
class ActiveRecordSubscriber | |
def active_record_config_for_event_with_octopus(event) | |
return unless event.payload[:connection_id] | |
config = active_record_config_for_event_without_octopus(event) | |
config || begin | |
connections = (::ActiveRecord::Base.connection.instance_variable_get(:@shards) || {}).values.map(&:connections).flatten | |
connection = connections.detect { |cnxn| cnxn.object_id == event.payload[:connection_id] } | |
connection.instance_variable_get(:@config) if connection | |
end | |
end | |
alias_method_chain :active_record_config_for_event, :octopus | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment