newrelic_rpm 2.13.6.beta2 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (33) hide show
  1. data/cert/cacert.pem +149 -53
  2. data/cert/oldsite.pem +28 -0
  3. data/cert/site.pem +27 -0
  4. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +26 -5
  5. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +65 -41
  6. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +30 -21
  7. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +6 -0
  8. data/lib/new_relic/agent/instrumentation/rails/errors.rb +30 -18
  9. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +14 -4
  10. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +9 -3
  11. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +13 -3
  12. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +1 -0
  13. data/lib/new_relic/control.rb +12 -176
  14. data/lib/new_relic/control/class_methods.rb +39 -0
  15. data/lib/new_relic/control/configuration.rb +1 -0
  16. data/lib/new_relic/control/frameworks/external.rb +9 -6
  17. data/lib/new_relic/control/frameworks/merb.rb +24 -18
  18. data/lib/new_relic/control/frameworks/rails.rb +126 -112
  19. data/lib/new_relic/control/frameworks/rails3.rb +54 -49
  20. data/lib/new_relic/control/frameworks/ruby.rb +33 -27
  21. data/lib/new_relic/control/frameworks/sinatra.rb +16 -11
  22. data/lib/new_relic/control/instance_methods.rb +150 -0
  23. data/lib/new_relic/control/instrumentation.rb +1 -0
  24. data/lib/new_relic/control/logging_methods.rb +1 -0
  25. data/lib/new_relic/control/profiling.rb +1 -0
  26. data/lib/new_relic/control/server_methods.rb +7 -1
  27. data/lib/new_relic/delayed_job_injection.rb +2 -1
  28. data/lib/new_relic/version.rb +3 -3
  29. data/lib/newrelic_rpm.rb +3 -7
  30. data/newrelic_rpm.gemspec +9 -4
  31. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +6 -0
  32. data/test/new_relic/control_test.rb +16 -1
  33. metadata +25 -52
@@ -0,0 +1,150 @@
1
+ module NewRelic
2
+ class Control
3
+ module InstanceMethods
4
+ # The env is the setting used to identify which section of the newrelic.yml
5
+ # to load. This defaults to a framework specific value, such as ENV['RAILS_ENV']
6
+ # but can be overridden as long as you set it before calling #init_plugin
7
+ attr_writer :env
8
+
9
+ attr_reader :local_env
10
+
11
+
12
+ # Initialize the plugin/gem and start the agent. This does the
13
+ # necessary configuration based on the framework environment and
14
+ # determines whether or not to start the agent. If the agent is
15
+ # not going to be started then it loads the agent shim which has
16
+ # stubs for all the external api.
17
+ #
18
+ # This may be invoked multiple times, as long as you don't attempt
19
+ # to uninstall the agent after it has been started.
20
+ #
21
+ # If the plugin is initialized and it determines that the agent is
22
+ # not enabled, it will skip starting it and install the shim. But
23
+ # if you later call this with <tt>:agent_enabled => true</tt>,
24
+ # then it will install the real agent and start it.
25
+ #
26
+ # What determines whether the agent is launched is the result of
27
+ # calling agent_enabled? This will indicate whether the
28
+ # instrumentation should/will be installed. If we're in a mode
29
+ # where tracers are not installed then we should not start the
30
+ # agent.
31
+ #
32
+ # Subclasses are not allowed to override, but must implement
33
+ # init_config({}) which is called one or more times.
34
+ #
35
+ def init_plugin(options={})
36
+ options['app_name'] = ENV['NEWRELIC_APP_NAME'] if ENV['NEWRELIC_APP_NAME']
37
+
38
+ # Merge the stringified options into the config as overrides:
39
+ logger_override = options.delete(:log)
40
+ environment_name = options.delete(:env) and self.env = environment_name
41
+ dispatcher = options.delete(:dispatcher) and @local_env.dispatcher = dispatcher
42
+ dispatcher_instance_id = options.delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id
43
+
44
+
45
+ # Clear out the settings, if they've already been loaded. It may be that
46
+ # between calling init_plugin the first time and the second time, the env
47
+ # has been overridden
48
+ @settings = nil
49
+ settings
50
+ merge_options(options)
51
+ if logger_override
52
+ @log = logger_override
53
+ # Try to grab the log filename
54
+ @log_file = @log.instance_eval { @logdev.filename rescue nil }
55
+ end
56
+ # An artifact of earlier implementation, we put both #add_method_tracer and #trace_execution
57
+ # methods in the module methods.
58
+ Module.send :include, NewRelic::Agent::MethodTracer::ClassMethods
59
+ Module.send :include, NewRelic::Agent::MethodTracer::InstanceMethods
60
+ init_config(options)
61
+ NewRelic::Agent.agent = NewRelic::Agent::Agent.instance
62
+ if agent_enabled? && !NewRelic::Agent.instance.started?
63
+ setup_log unless logger_override
64
+ start_agent
65
+ install_instrumentation
66
+ load_samplers unless self['disable_samplers']
67
+ local_env.gather_environment_info
68
+ append_environment_info
69
+ elsif !agent_enabled?
70
+ install_shim
71
+ end
72
+ end
73
+
74
+ # Install the real agent into the Agent module, and issue the start command.
75
+ def start_agent
76
+ NewRelic::Agent.agent.start
77
+ end
78
+
79
+ # True if dev mode or monitor mode are enabled, and we are running
80
+ # inside a valid dispatcher like mongrel or passenger. Can be overridden
81
+ # by NEWRELIC_ENABLE env variable, monitor_daemons config option when true, or
82
+ # agent_enabled config option when true or false.
83
+ def agent_enabled?
84
+ return false if !developer_mode? && !monitor_mode?
85
+ return self['agent_enabled'].to_s =~ /true|on|yes/i if !self['agent_enabled'].nil? && self['agent_enabled'] != 'auto'
86
+ return false if ENV['NEWRELIC_ENABLE'].to_s =~ /false|off|no/i
87
+ return true if self['monitor_daemons'].to_s =~ /true|on|yes/i
88
+ return true if ENV['NEWRELIC_ENABLE'].to_s =~ /true|on|yes/i
89
+ # When in 'auto' mode the agent is enabled if there is a known
90
+ # dispatcher running
91
+ return true if @local_env.dispatcher != nil
92
+ end
93
+
94
+ def app
95
+ @local_env.framework
96
+ end
97
+ alias framework app
98
+
99
+ def to_s
100
+ "Control[#{self.app}]"
101
+ end
102
+
103
+ protected
104
+
105
+ # Append framework specific environment information for uploading to
106
+ # the server for change detection. Override in subclasses
107
+ def append_environment_info; end
108
+
109
+ def bundler_gem_list
110
+ if defined?(Bundler) && Bundler.instance_eval do @load end
111
+ Bundler.load.specs.map do | spec |
112
+ version = (spec.respond_to?(:version) && spec.version)
113
+ spec.name + (version ? "(#{version})" : "")
114
+ end
115
+ else
116
+ []
117
+ end
118
+ end
119
+
120
+ def config_file
121
+ File.expand_path(File.join(root,"config","newrelic.yml"))
122
+ end
123
+
124
+ def initialize local_env, config_file_override=nil
125
+ @local_env = local_env
126
+ @instrumentation_files = []
127
+ newrelic_file = config_file_override || config_file
128
+ # Next two are for populating the newrelic.yml via erb binding, necessary
129
+ # when using the default newrelic.yml file
130
+ generated_for_user = ''
131
+ license_key=''
132
+ if !File.exists?(newrelic_file)
133
+ log! "Cannot find read #{newrelic_file}."
134
+ @yaml = {}
135
+ else
136
+ @yaml = YAML.load(ERB.new(File.read(newrelic_file)).result(binding))
137
+ end
138
+ rescue ScriptError, StandardError => e
139
+ puts e
140
+ puts e.backtrace.join("\n")
141
+ raise "Error reading newrelic.yml file: #{e}"
142
+ end
143
+
144
+ def newrelic_root
145
+ self.class.newrelic_root
146
+ end
147
+ end
148
+ include InstanceMethods
149
+ end
150
+ end
@@ -76,5 +76,6 @@ module NewRelic
76
76
  log.debug "Finished instrumentation"
77
77
  end
78
78
  end
79
+ include Instrumentation
79
80
  end
80
81
  end
@@ -70,5 +70,6 @@ module NewRelic
70
70
  fetch('log_file_name', 'newrelic_agent.log')
71
71
  end
72
72
  end
73
+ include LoggingMethods
73
74
  end
74
75
  end
@@ -20,5 +20,6 @@ module NewRelic
20
20
  @profiling = profiling_available? && val && defined?(RubyProf)
21
21
  end
22
22
  end
23
+ include Profiling
23
24
  end
24
25
  end
@@ -67,6 +67,10 @@ module NewRelic
67
67
  end
68
68
  end
69
69
 
70
+ def cert_file_path
71
+ File.expand_path(File.join(newrelic_root, 'cert', 'cacert.pem'))
72
+ end
73
+
70
74
  # Return the Net::HTTP with proxy configuration given the NewRelic::Control::Server object.
71
75
  # Default is the collector but for api calls you need to pass api_server
72
76
  #
@@ -85,7 +89,7 @@ module NewRelic
85
89
  http.use_ssl = true
86
90
  if verify_certificate?
87
91
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
88
- http.ca_file = File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')
92
+ http.ca_file = cert_file_path
89
93
  else
90
94
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
91
95
  end
@@ -93,6 +97,8 @@ module NewRelic
93
97
  http
94
98
  end
95
99
  end
100
+
101
+ include ServerMethods
96
102
  end
97
103
  end
98
104
 
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  DependencyDetection.defer do
14
14
  depends_on do
15
- defined?(::Delayed) && defined?(::Delayed::Worker) and !NewRelic::Control.instance['disable_dj']
15
+ defined?(::Delayed) && defined?(::Delayed::Worker)
16
16
  end
17
17
 
18
18
  executes do
@@ -34,3 +34,4 @@ DependencyDetection.defer do
34
34
  end
35
35
  end
36
36
  end
37
+ DependencyDetection.detect!
@@ -2,9 +2,9 @@
2
2
  module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 2
5
- MINOR = 13
6
- TINY = 6
7
- BUILD = 'beta2' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
5
+ MINOR = 14
6
+ TINY = 0
7
+ BUILD = nil #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
data/lib/newrelic_rpm.rb CHANGED
@@ -18,7 +18,6 @@
18
18
  # directly.
19
19
  #
20
20
  require 'new_relic/control'
21
-
22
21
  if defined? Merb
23
22
  module NewRelic
24
23
  class MerbBootLoader < Merb::BootLoader
@@ -39,14 +38,11 @@ elsif defined? Rails
39
38
  end
40
39
  end
41
40
  else
42
- if Rails.respond_to?(:configuration)
43
41
  # After verison 2.0 of Rails we can access the configuration directly.
44
42
  # We need it to add dev mode routes after initialization finished.
45
- config = Rails.configuration
46
- NewRelic::Control.instance.init_plugin :config => config
47
- else
48
- NewRelic::Control.instance.init_plugin
49
- end
43
+ config = nil
44
+ config = Rails.configuration if Rails.respond_to?(:configuration)
45
+ NewRelic::Control.instance.init_plugin :config => config
50
46
  end
51
47
  else
52
48
  NewRelic::Control.instance.init_plugin
data/newrelic_rpm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{newrelic_rpm}
8
- s.version = "2.13.6.beta2"
8
+ s.version = "2.14.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bill Kayser", "Justin George"]
12
- s.date = %q{2011-03-22}
12
+ s.date = %q{2011-03-29}
13
13
  s.description = %q{New Relic RPM is a Ruby performance management system, developed by
14
14
  New Relic, Inc (http://www.newrelic.com). RPM provides you with deep
15
15
  information about the performance of your Ruby on Rails or Merb
@@ -33,6 +33,8 @@ http://github.com/newrelic/rpm/tree/master.
33
33
  "bin/newrelic",
34
34
  "bin/newrelic_cmd",
35
35
  "cert/cacert.pem",
36
+ "cert/oldsite.pem",
37
+ "cert/site.pem",
36
38
  "install.rb",
37
39
  "lib/conditional_vendored_dependency_detection.rb",
38
40
  "lib/conditional_vendored_metric_parser.rb",
@@ -84,6 +86,7 @@ http://github.com/newrelic/rpm/tree/master.
84
86
  "lib/new_relic/commands/deployments.rb",
85
87
  "lib/new_relic/commands/install.rb",
86
88
  "lib/new_relic/control.rb",
89
+ "lib/new_relic/control/class_methods.rb",
87
90
  "lib/new_relic/control/configuration.rb",
88
91
  "lib/new_relic/control/frameworks/external.rb",
89
92
  "lib/new_relic/control/frameworks/merb.rb",
@@ -91,6 +94,7 @@ http://github.com/newrelic/rpm/tree/master.
91
94
  "lib/new_relic/control/frameworks/rails3.rb",
92
95
  "lib/new_relic/control/frameworks/ruby.rb",
93
96
  "lib/new_relic/control/frameworks/sinatra.rb",
97
+ "lib/new_relic/control/instance_methods.rb",
94
98
  "lib/new_relic/control/instrumentation.rb",
95
99
  "lib/new_relic/control/logging_methods.rb",
96
100
  "lib/new_relic/control/profiling.rb",
@@ -264,7 +268,7 @@ Refer to the README.md file for more information.
264
268
 
265
269
  Please see http://support.newrelic.com/faqs/docs/ruby-agent-release-notes
266
270
  for a complete description of the features and enhancements available
267
- in version 2.13 of the Ruby Agent.
271
+ in version 2.14 of the Ruby Agent.
268
272
 
269
273
  For details on this specific release, refer to the CHANGELOG file.
270
274
 
@@ -274,10 +278,11 @@ for instructions for previous versions
274
278
  }
275
279
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "New Relic Ruby Performance Monitoring Agent"]
276
280
  s.require_paths = ["lib"]
277
- s.rubygems_version = %q{1.5.2}
281
+ s.rubygems_version = %q{1.3.7}
278
282
  s.summary = %q{New Relic Ruby Performance Monitoring Agent}
279
283
 
280
284
  if s.respond_to? :specification_version then
285
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
281
286
  s.specification_version = 3
282
287
 
283
288
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -18,6 +18,12 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
18
18
  ActiveRecordFixtures.teardown
19
19
  NewRelic::Agent.shutdown
20
20
  end
21
+
22
+ #####################################################################
23
+ # Note: If these tests are failing, most likely the problem is that #
24
+ # the active record instrumentation is not loading for whichever #
25
+ # version of rails you're testing at the moment. #
26
+ #####################################################################
21
27
 
22
28
  def test_agent_setup
23
29
  assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
@@ -13,6 +13,21 @@ class NewRelic::ControlTest < Test::Unit::TestCase
13
13
  NewRelic::Agent.shutdown
14
14
  end
15
15
 
16
+ def test_cert_file_path
17
+ assert @c.cert_file_path
18
+ assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @c.cert_file_path
19
+ end
20
+
21
+ def test_cert_file
22
+ result = `openssl verify -CAfile #{@c.cert_file_path} #{@c.send(:newrelic_root)}/cert/site.pem`
23
+ assert (result =~ /OK/), 'Should verify certificate: ' + result
24
+ end
25
+
26
+ def test_old_cert_file
27
+ result = `openssl verify -CAfile #{@c.cert_file_path} #{@c.send(:newrelic_root)}/cert/oldsite.pem`
28
+ assert (result =~ /OK/), 'Should verify the old certificate: ' + result
29
+ end
30
+
16
31
  def test_monitor_mode
17
32
  assert ! @c.monitor_mode?
18
33
  @c.settings.delete 'enabled'
@@ -34,7 +49,7 @@ class NewRelic::ControlTest < Test::Unit::TestCase
34
49
  end
35
50
 
36
51
  def test_test_config
37
- if defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i > 2
52
+ if defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
38
53
  assert_equal :rails3, c.app
39
54
  elsif defined?(Rails)
40
55
  assert_equal :rails, c.app
metadata CHANGED
@@ -1,15 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_rpm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196231
5
- prerelease: 7
6
- segments:
7
- - 2
8
- - 13
9
- - 6
10
- - beta
11
- - 2
12
- version: 2.13.6.beta2
4
+ prerelease:
5
+ version: 2.14.0
13
6
  platform: ruby
14
7
  authors:
15
8
  - Bill Kayser
@@ -18,7 +11,7 @@ autorequire:
18
11
  bindir: bin
19
12
  cert_chain: []
20
13
 
21
- date: 2011-03-22 00:00:00 -07:00
14
+ date: 2011-03-29 00:00:00 -07:00
22
15
  default_executable:
23
16
  dependencies:
24
17
  - !ruby/object:Gem::Dependency
@@ -29,9 +22,6 @@ dependencies:
29
22
  requirements:
30
23
  - - ">="
31
24
  - !ruby/object:Gem::Version
32
- hash: 3
33
- segments:
34
- - 0
35
25
  version: "0"
36
26
  type: :development
37
27
  version_requirements: *id001
@@ -43,9 +33,6 @@ dependencies:
43
33
  requirements:
44
34
  - - ">="
45
35
  - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
36
  version: "0"
50
37
  type: :development
51
38
  version_requirements: *id002
@@ -57,9 +44,6 @@ dependencies:
57
44
  requirements:
58
45
  - - ">="
59
46
  - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
47
  version: "0"
64
48
  type: :development
65
49
  version_requirements: *id003
@@ -91,6 +75,8 @@ files:
91
75
  - bin/newrelic
92
76
  - bin/newrelic_cmd
93
77
  - cert/cacert.pem
78
+ - cert/oldsite.pem
79
+ - cert/site.pem
94
80
  - install.rb
95
81
  - lib/conditional_vendored_dependency_detection.rb
96
82
  - lib/conditional_vendored_metric_parser.rb
@@ -142,6 +128,7 @@ files:
142
128
  - lib/new_relic/commands/deployments.rb
143
129
  - lib/new_relic/commands/install.rb
144
130
  - lib/new_relic/control.rb
131
+ - lib/new_relic/control/class_methods.rb
145
132
  - lib/new_relic/control/configuration.rb
146
133
  - lib/new_relic/control/frameworks/external.rb
147
134
  - lib/new_relic/control/frameworks/merb.rb
@@ -149,6 +136,7 @@ files:
149
136
  - lib/new_relic/control/frameworks/rails3.rb
150
137
  - lib/new_relic/control/frameworks/ruby.rb
151
138
  - lib/new_relic/control/frameworks/sinatra.rb
139
+ - lib/new_relic/control/instance_methods.rb
152
140
  - lib/new_relic/control/instrumentation.rb
153
141
  - lib/new_relic/control/logging_methods.rb
154
142
  - lib/new_relic/control/profiling.rb
@@ -306,32 +294,23 @@ has_rdoc: true
306
294
  homepage: http://www.github.com/newrelic/rpm
307
295
  licenses: []
308
296
 
309
- post_install_message: |+
310
-
311
- PLEASE NOTE:
312
-
313
- Developer Mode is now a Rack middleware.
314
-
315
- RPM Developer Mode is no longer available in Rails 2.1 and earlier.
316
- However, starting in version 2.12 you can use Developer Mode in any
317
- Rack based framework, in addition to Rails. To install developer mode
318
- in a non-Rails application, just add NewRelic::Rack::DeveloperMode to
319
- your middleware stack.
320
-
321
- If you are using JRuby, we recommend using at least version 1.4 or
322
- later because of issues with the implementation of the timeout library.
323
-
324
- Refer to the README.md file for more information.
325
-
326
- Please see http://support.newrelic.com/faqs/docs/ruby-agent-release-notes
327
- for a complete description of the features and enhancements available
328
- in version 2.13 of the Ruby Agent.
329
-
330
- For details on this specific release, refer to the CHANGELOG file.
331
-
332
- Notice: Developer Mode now supports only Rails 2.3+ - refer to README
333
- for instructions for previous versions
334
-
297
+ post_install_message: "\n\
298
+ PLEASE NOTE:\n\n\
299
+ Developer Mode is now a Rack middleware.\n\n\
300
+ RPM Developer Mode is no longer available in Rails 2.1 and earlier.\n\
301
+ However, starting in version 2.12 you can use Developer Mode in any\n\
302
+ Rack based framework, in addition to Rails. To install developer mode\n\
303
+ in a non-Rails application, just add NewRelic::Rack::DeveloperMode to\n\
304
+ your middleware stack.\n\n\
305
+ If you are using JRuby, we recommend using at least version 1.4 or \n\
306
+ later because of issues with the implementation of the timeout library.\n\n\
307
+ Refer to the README.md file for more information.\n\n\
308
+ Please see http://support.newrelic.com/faqs/docs/ruby-agent-release-notes\n\
309
+ for a complete description of the features and enhancements available\n\
310
+ in version 2.14 of the Ruby Agent.\n\n\
311
+ For details on this specific release, refer to the CHANGELOG file.\n\n\
312
+ Notice: Developer Mode now supports only Rails 2.3+ - refer to README\n\
313
+ for instructions for previous versions\n\n"
335
314
  rdoc_options:
336
315
  - --line-numbers
337
316
  - --inline-source
@@ -344,23 +323,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
323
  requirements:
345
324
  - - ">="
346
325
  - !ruby/object:Gem::Version
347
- hash: 3
348
- segments:
349
- - 0
350
326
  version: "0"
351
327
  required_rubygems_version: !ruby/object:Gem::Requirement
352
328
  none: false
353
329
  requirements:
354
330
  - - ">="
355
331
  - !ruby/object:Gem::Version
356
- hash: 3
357
- segments:
358
- - 0
359
332
  version: "0"
360
333
  requirements: []
361
334
 
362
335
  rubyforge_project:
363
- rubygems_version: 1.5.2
336
+ rubygems_version: 1.5.0
364
337
  signing_key:
365
338
  specification_version: 3
366
339
  summary: New Relic Ruby Performance Monitoring Agent