-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary rails 3 support; no dev mode, limited bundler support
- Loading branch information
Bill Kayser
committed
Mar 13, 2010
1 parent
9c98000
commit c2e9b86
Showing
5 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
lib/new_relic/agent/instrumentation/rails3/action_controller.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
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
class ActionController::Base | ||
include NewRelic::Agent::Instrumentation::ControllerInstrumentation | ||
include NewRelic::Agent::Instrumentation::Rails3::ActionController | ||
end | ||
end | ||
|
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
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 |
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
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 |
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
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
Can you please remove this? It shows up in our test suites and rake tasks, etc.