Skip to content

Instantly share code, notes, and snippets.

@mgreen
Created March 21, 2012 00:43
Show Gist options
  • Save mgreen/2143106 to your computer and use it in GitHub Desktop.
Save mgreen/2143106 to your computer and use it in GitHub Desktop.
newrelic for em-http-request with em-synchrony
if defined?(::EM::HTTPMethods) and defined?(::EM::Synchrony)
module EM::HTTPMethods
def request_with_newrelic_trace(type, *args, &block)
uri = @uri.kind_of?(Addressable::URI) ? @uri : Addressable::URI::parse(@uri.to_s)
metrics = ["External/#{uri.host}/EM::HTTPMethods/#{type.to_s.upcase}","External/#{uri.host}/a
ll"]
if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
metrics << "External/allWeb"
else
metrics << "External/allOther"
end
self.class.trace_execution_scoped metrics do
self.send("#{type}_without_newrelic_trace", *args, &block)
end
end
end
%w[get head post delete put].each do |type|
EM::HTTPMethods.class_eval %[
def #{type}_with_newrelic_trace(*args, &block)
request_with_newrelic_trace(:#{type}, *args, &block)
end
alias #{type}_without_newrelic_trace #{type}
alias #{type} #{type}_with_newrelic_trace
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment