forked from newrelic/rpm_contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup initialization process to better support Rails 3
- Loading branch information
Showing
1 changed file
with
30 additions
and
21 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,34 +1,43 @@ | ||
|
||
RPM_CONTRIB_LIB = File.dirname(__FILE__) | ||
|
||
module RPMContrib | ||
VERSION = File.read(RPM_CONTRIB_LIB+"/../CHANGELOG")[/Version ([\d\.]+)$/, 1] | ||
end | ||
|
||
# Perform any framework/dispatcher detection before loading the rpm | ||
# gem. | ||
def self.init_sequence | ||
Proc.new do | ||
# Tell the agent to load all the files in the | ||
# rpm_contrib/instrumentation directory. | ||
NewRelic::Agent.add_instrumentation(RPM_CONTRIB_LIB+"/rpm_contrib/instrumentation/**/*.rb") | ||
|
||
# Load all the Sampler class definitions. These will register | ||
# automatically with the agent. | ||
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/samplers/**/*.rb") { |file| require file } | ||
end | ||
end | ||
|
||
end | ||
|
||
# Perform any framework/dispatcher detection before loading the rpm gem. | ||
raise "The rpm_contrib gem must be loaded before the newrelic_rpm gem." if defined?(::NewRelic) | ||
|
||
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/detection/**/*.rb") { |file| require file } | ||
|
||
require 'newrelic_rpm' | ||
|
||
init_sequence = Proc.new do | ||
|
||
# Tell the agent to load all the files in the | ||
# rpm_contrib/instrumentation directory. | ||
NewRelic::Agent.add_instrumentation(RPM_CONTRIB_LIB+"/rpm_contrib/instrumentation/**/*.rb") | ||
|
||
# Load all the Sampler class definitions. These will register | ||
# automatically with the agent. | ||
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/samplers/**/*.rb") { |file| require file } | ||
end | ||
|
||
if defined?(Rails.configuration) | ||
Rails.configuration.after_initialize &init_sequence | ||
if defined? Rails | ||
# Rails 3.x+ | ||
if Rails.respond_to?(:version) && Rails.version =~ /^3/ | ||
module NewRelic | ||
class Railtie < Rails::Railtie | ||
initializer("rpm_contrib.start_plugin", &RPMContrib.init_sequence) | ||
end | ||
end | ||
# Rails 2.x | ||
elsif defined?(Rails) && Rails.respond_to?(:configuration) | ||
Rails.configuration.after_initialize &RPMContrib.init_sequence | ||
else | ||
raise "The rpm_contrib gem supports Rails 2.2+ only." | ||
end | ||
else | ||
init_sequence.call | ||
end | ||
|
||
|
||
RPMContrib.init_sequence.call | ||
end |