Last active
January 14, 2016 08:04
-
-
Save hey-jude/a70d48b44446e1aa146d to your computer and use it in GitHub Desktop.
instrumenting rabl rendering on newrelic rpm : config/initializers/rpm_instrumentation.rb
This file contains 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
require 'new_relic/agent/method_tracer' | |
require 'grape-rabl/formatter' | |
# 0.3.1: Grape::Formatter::Rabl.call, master: Grape::Rabl::Formatter#render | |
Grape::Formatter::Rabl.class_eval do # class_eval creates instance methods | |
class << self | |
include ::NewRelic::Agent::MethodTracer | |
# https://github.com/ruby-grape/grape-rabl/blob/v0.3.1/lib/grape-rabl/formatter.rb | |
def call_with_newrelic(object, env) | |
rabl_path = env['api.tilt.rabl'] || env['api.endpoint'].options[:route_options][:rabl] | |
path = rabl_path ? "RABL #{rabl_path}" : 'JSON' | |
::NewRelic::Agent::MethodTracer.trace_execution_scoped("View/#{path}") do | |
call_without_newrelic(object, env) | |
end | |
end | |
alias_method :call_without_newrelic, :call | |
alias_method :call, :call_with_newrelic | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment