Skip to content

Instantly share code, notes, and snippets.

@johnnyshields
Created February 23, 2016 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnnyshields/0e53430c3998cba5c789 to your computer and use it in GitHub Desktop.
Save johnnyshields/0e53430c3998cba5c789 to your computer and use it in GitHub Desktop.
Monkey patch to instrument Moped 1.x same as 2.x.
# Monkey patch to instrument Moped 1.x same as 2.x.
# Can be removed after upgrading to Mongoid 4.
module Moped
module Instrumentable
class Noop
class << self
# Do not instrument anything.
def instrument(name, payload = {})
yield payload if block_given?
end
end
end
end
end
module Moped
module Instrumentable
TOPIC = "query.moped"
def instrumenter
@instrumenter ||= Moped::Instrumentable::Noop
end
def instrument(name, payload = {}, &block)
instrumenter.instrument(name, payload, &block)
end
end
end
module Moped
class Node
include Moped::Instrumentable
def logging_with_instrument(operations, &block)
instrument(TOPIC, prefix: " MOPED: #{resolved_address}", ops: operations) do
logging_without_instrument(operations, &block)
end
end
alias_method_chain :logging, :instrument
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment