Skip to content

Instantly share code, notes, and snippets.

@hey-jude
Last active January 14, 2016 08:04
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 hey-jude/a70d48b44446e1aa146d to your computer and use it in GitHub Desktop.
Save hey-jude/a70d48b44446e1aa146d to your computer and use it in GitHub Desktop.
instrumenting rabl rendering on newrelic rpm : config/initializers/rpm_instrumentation.rb
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