Skip to content

Instantly share code, notes, and snippets.

@dblock
Created September 21, 2011 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dblock/1233422 to your computer and use it in GitHub Desktop.
Save dblock/1233422 to your computer and use it in GitHub Desktop.
New Relic API Rackup
if Rails.env.production?
require 'new_relic/agent/instrumentation/controller_instrumentation'
module NewRelic
module Agent
module Instrumentation
module API
def newrelic_request_headers
@newrelic_request.env
end
def call_with_newrelic(*args)
@newrelic_request = ::Rack::Request.new(args.first)
path = @newrelic_request.path.split('/').delete_if { |p| p.blank? }.join('_')
method = @newrelic_request.request_method.downcase
perform_action_with_newrelic_trace(
:category => :rack,
:path => "#{path}\##{method}",
:request => @newrelic_request) do
result = call_without_newrelic(*args)
# Ignore cascaded calls
MetricFrame.abort_transaction! if result.first == 404
result
end
end
def self.included middleware #:nodoc:
middleware.class_eval do
alias call_without_newrelic call
alias call call_with_newrelic
end
end
include ControllerInstrumentation
def self.extended middleware #:nodoc:
middleware.class_eval do
class << self
alias call_without_newrelic call
alias call call_with_newrelic
end
end
end
end
end
end
end
end
@gugl
Copy link

gugl commented Apr 23, 2012

Thanks for the snippet.

I get a stack level too deep, though.
The only additional information i get is: actionpack (3.2.2) lib/action_dispatch/middleware/reloader.rb:70

I followed your instructions and tried it with newrelic_rpm 3.3.4 and 3.1.2....both end up with stack level too deep.

I use ruby 1.9.3p125 and rails 3.2.2
Any ideas?

@dblock
Copy link
Author

dblock commented Apr 23, 2012

I have this in production with "rpm_contrib", "2.1.8" and "newrelic_rpm", "3.3.3". What's on the stack?

@gugl
Copy link

gugl commented Apr 23, 2012

Sorry, was my fault.
i used both:
extend NewRelic::Agent::Instrumentation::Rack
AND
extend NewRelic::Agent::Instrumentation::API

Now i only use extend NewRelic::Agent::Instrumentation::API and it works fine.

@dblock
Copy link
Author

dblock commented Nov 29, 2012

We no longer use this instrumentation and have reworked it. Check out [this blog post](http://artsy.github.com/blog/2012/11/29/measuring-performance-in-grape-apis-with-new-relic] for details.

@dblock
Copy link
Author

dblock commented Nov 29, 2012

We no longer use this instrumentation and have reworked it. Check out this blog post for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment