Skip to content

Commit

Permalink
Preliminary rails 3 support; no dev mode, limited bundler support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Kayser committed Mar 13, 2010
1 parent 9c98000 commit c2e9b86
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 4 deletions.
45 changes: 45 additions & 0 deletions lib/new_relic/agent/instrumentation/rails3/action_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module NewRelic
module Agent
module Instrumentation
module Rails3
module ActionController
def self.newrelic_write_attr(attr_name, value) # :nodoc:
write_inheritable_attribute(attr_name, value)
end

def self.newrelic_read_attr(attr_name) # :nodoc:
read_inheritable_attribute(attr_name)
end

# determine the path that is used in the metric name for
# the called controller action
def newrelic_metric_path(action_name_override = nil)
action_part = action_name_override || action_name
if action_name_override || self.class.action_methods.include?(action_part)
"#{self.class.controller_path}/#{action_part}"
else
"#{self.class.controller_path}/(other)"
end
end

def process_action(*args)

perform_action_with_newrelic_trace(:category => :controller, :name => self.action_name, :params => request.filtered_parameters, :class_name => self.class.name) do
super
end
end

end
end
end
end
end

if defined?(ActionController) && defined?(ActionController::Base)
puts "ApplicationController is defined"

This comment has been minimized.

Copy link
@cgriego

cgriego Sep 14, 2010

Can you please remove this? It shows up in our test suites and rake tasks, etc.

This comment has been minimized.

Copy link
@jaggederest

jaggederest Sep 21, 2010

Contributor

Feel free to delete it, I'll issue an updated agent shortly.

class ActionController::Base
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
include NewRelic::Agent::Instrumentation::Rails3::ActionController
end
end

21 changes: 21 additions & 0 deletions lib/new_relic/agent/instrumentation/rails3/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module NewRelic
module Agent
module Instrumentation
module Rails3
module Errors
def newrelic_notice_error(exception, custom_params = {})
filtered_params = (respond_to? :filter_parameters) ? filter_parameters(params) : params
filtered_params.merge!(custom_params)
NewRelic::Agent.agent.error_collector.notice_error(exception, request, newrelic_metric_path, filtered_params)
end
end
end
end
end
end

if defined?(ActionController) && defined?(ActionController::Base)
class ActionController::Base
include NewRelic::Agent::Instrumentation::Rails3::Errors
end
end
75 changes: 75 additions & 0 deletions lib/new_relic/control/rails3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Control subclass instantiated when Rails is detected. Contains
# Rails specific configuration, instrumentation, environment values,
# etc.
class NewRelic::Control::Rails3 < NewRelic::Control

def env
@env ||= ::Rails.env.to_s
end

def root
@root ||= Rails.root.to_s
end

def logger
::Rails.logger
end

def base_log_file
logger.instance_eval {
@log.path
}
rescue
File.join(root, 'log')
end
private :base_log_file

def log_path
@log_path ||= File.expand_path(File.dirname(base_log_file))
end

def vendor_root
@vendor_root ||= File.join(root,'vendor','rails')
end

def version
@rails_version ||= NewRelic::VersionNumber.new(::Rails::VERSION::STRING)
end

def init_config(options={})
rails_config=options[:config]
if !agent_enabled?
# Might not be running if it does not think mongrel, thin, passenger, etc
# is running, if it things it's a rake task, or if the agent_enabled is false.
logger.info "New Relic Agent not running."
else
logger.info "Starting the New Relic Agent."
end
end

protected

# Collect the Rails::Info into an associative array as well as the list of plugins
def append_environment_info
local_env.append_environment_value('Rails version'){ version }
local_env.append_environment_value('Rails threadsafe') do
::Rails.configuration.action_controller.allow_concurrency == true
end
local_env.append_environment_value('Rails Env') { env }
local_env.append_gem_list do
::Rails.configuration.gems.map do | gem |
version = (gem.respond_to?(:version) && gem.version) ||
(gem.specification.respond_to?(:version) && gem.specification.version)
gem.name + (version ? "(#{version})" : "")
end
end
local_env.append_plugin_list { ::Rails.configuration.plugins }
end

def install_shim
super
require 'new_relic/agent/instrumentation/controller_instrumentation'
ActionController::Base.send :include, NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
end

end
14 changes: 11 additions & 3 deletions lib/new_relic/local_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module NewRelic
# An instance of LocalEnvironment is responsible for determining
# three things:
#
# * Framework - :rails, :merb, :ruby, :external, :test
# * Framework - :rails, :rails3, :merb, :ruby, :external, :test
# * Dispatcher - A supported dispatcher, or nil (:mongrel, :thin, :passenger, :webrick, etc)
# * Dispatcher Instance ID, which distinguishes agents on a single host from each other
#
Expand All @@ -17,7 +17,7 @@ class LocalEnvironment

attr_accessor :dispatcher # mongrel, thin, webrick, or possibly nil
attr_accessor :dispatcher_instance_id # used to distinguish instances of a dispatcher from each other, may be nil
attr_accessor :framework # rails, merb, external, ruby, test
attr_accessor :framework # rails, rails3, merb, external, ruby, test
attr_reader :mongrel # The mongrel instance, if there is one, captured as a convenience
attr_reader :processors # The number of cpus, if detected, or nil
alias environment dispatcher
Expand Down Expand Up @@ -179,13 +179,21 @@ def discover_framework
when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
when defined?(::NewRelic::TEST) then :test
when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
when defined?(::Rails) then :rails
when defined?(::Rails) then check_rails_version
when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
when defined?(::NewRelic::IA) then :external
else :ruby
end
end

def check_rails_version
if Rails::VERSION::MAJOR < 3
:rails
else
:rails3
end
end

def check_for_torquebox
return unless defined?(::JRuby) &&
( Java::OrgTorqueboxRailsWebDeployers::RailsRackDeployer rescue nil)
Expand Down
3 changes: 2 additions & 1 deletion lib/new_relic/noticed_error.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# This class encapsulates an error that was noticed by RPM in a managed app.
class NewRelic::NoticedError
extend NewRelic::Agent::CollectionHelper
attr_accessor :path, :timestamp, :params, :exception_class, :message

def initialize(path, data, exception, timestamp = Time.now)
self.path = path
self.params = data
self.params = NewRelic::NoticedError.normalize_params(data)

self.exception_class = exception ? exception.class.name : '<no exception>'

Expand Down

0 comments on commit c2e9b86

Please sign in to comment.