Created
February 23, 2016 19:29
-
-
Save johnnyshields/0e53430c3998cba5c789 to your computer and use it in GitHub Desktop.
Monkey patch to instrument Moped 1.x same as 2.x.
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
# 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