Skip to content

Instantly share code, notes, and snippets.

@idyll
Created November 24, 2011 08:54
Show Gist options
  • Save idyll/1390925 to your computer and use it in GitHub Desktop.
Save idyll/1390925 to your computer and use it in GitHub Desktop.
NewRelic changeless needed to work with Grape on Heroku
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
@idyll
Copy link
Author

idyll commented Nov 24, 2011

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