Skip to content

Instantly share code, notes, and snippets.

@ashanbrown
Created December 5, 2014 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashanbrown/f6d9ea48d897e77a8b27 to your computer and use it in GitHub Desktop.
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
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