wd_newrelic_rpm 3.5.6 → 3.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/CHANGELOG +43 -3
  2. data/Gemfile +6 -2
  3. data/LICENSE +23 -0
  4. data/lib/new_relic/agent.rb +50 -3
  5. data/lib/new_relic/agent/agent.rb +40 -60
  6. data/lib/new_relic/agent/configuration/defaults.rb +9 -3
  7. data/lib/new_relic/agent/configuration/server_source.rb +4 -0
  8. data/lib/new_relic/agent/cross_app_monitor.rb +239 -0
  9. data/lib/new_relic/agent/cross_app_tracing.rb +281 -0
  10. data/lib/new_relic/agent/database.rb +28 -10
  11. data/lib/new_relic/agent/error_collector.rb +5 -0
  12. data/lib/new_relic/agent/event_listener.rb +4 -0
  13. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +58 -39
  14. data/lib/new_relic/agent/instrumentation/metric_frame.rb +16 -3
  15. data/lib/new_relic/agent/instrumentation/net.rb +13 -11
  16. data/lib/new_relic/agent/instrumentation/queue_time.rb +50 -192
  17. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +145 -0
  18. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +45 -0
  19. data/lib/new_relic/agent/instrumentation/resque.rb +10 -10
  20. data/lib/new_relic/agent/instrumentation/sinatra.rb +19 -9
  21. data/lib/new_relic/agent/new_relic_service.rb +63 -9
  22. data/lib/new_relic/agent/pipe_service.rb +8 -12
  23. data/lib/new_relic/agent/rules_engine.rb +72 -0
  24. data/lib/new_relic/agent/shim_agent.rb +0 -1
  25. data/lib/new_relic/agent/sql_sampler.rb +3 -2
  26. data/lib/new_relic/agent/stats.rb +149 -0
  27. data/lib/new_relic/agent/stats_engine.rb +9 -0
  28. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -24
  29. data/lib/new_relic/agent/stats_engine/metric_stats.rb +84 -185
  30. data/lib/new_relic/agent/stats_engine/stats_hash.rb +58 -0
  31. data/lib/new_relic/agent/stats_engine/transactions.rb +10 -2
  32. data/lib/new_relic/agent/transaction_info.rb +31 -6
  33. data/lib/new_relic/agent/transaction_sample_builder.rb +19 -8
  34. data/lib/new_relic/agent/transaction_sampler.rb +17 -10
  35. data/lib/new_relic/helper.rb +32 -0
  36. data/lib/new_relic/local_environment.rb +24 -32
  37. data/lib/new_relic/okjson.rb +599 -0
  38. data/lib/new_relic/transaction_sample.rb +2 -1
  39. data/lib/new_relic/transaction_sample/segment.rb +2 -1
  40. data/lib/new_relic/version.rb +1 -1
  41. data/newrelic.yml +27 -41
  42. data/test/multiverse/suites/agent_only/Envfile +5 -1
  43. data/test/multiverse/suites/agent_only/audit_log_test.rb +2 -4
  44. data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -2
  45. data/test/multiverse/suites/agent_only/{cross_process_test.rb → cross_application_tracing_test.rb} +3 -3
  46. data/test/multiverse/suites/agent_only/key_transactions_test.rb +66 -0
  47. data/test/multiverse/suites/agent_only/marshaling_test.rb +9 -22
  48. data/test/multiverse/suites/agent_only/rename_rule_test.rb +57 -0
  49. data/test/multiverse/suites/agent_only/start_up_test.rb +1 -1
  50. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +17 -6
  51. data/test/multiverse/suites/rails/error_tracing_test.rb +20 -8
  52. data/test/multiverse/suites/rails/queue_time_test.rb +2 -2
  53. data/test/multiverse/suites/resque/instrumentation_test.rb +4 -3
  54. data/test/multiverse/suites/sinatra/Envfile +2 -0
  55. data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -0
  56. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +5 -5
  57. data/test/multiverse/suites/sinatra/sinatra_test.rb +77 -10
  58. data/test/new_relic/agent/agent/connect_test.rb +45 -1
  59. data/test/new_relic/agent/agent/start_worker_thread_test.rb +0 -3
  60. data/test/new_relic/agent/agent_test.rb +20 -40
  61. data/test/new_relic/agent/agent_test_controller_test.rb +27 -60
  62. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  63. data/test/new_relic/agent/configuration/server_source_test.rb +8 -3
  64. data/test/new_relic/agent/cross_app_monitor_test.rb +237 -0
  65. data/test/new_relic/agent/database_test.rb +60 -16
  66. data/test/new_relic/agent/error_collector_test.rb +28 -4
  67. data/test/new_relic/agent/event_listener_test.rb +23 -2
  68. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
  69. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +85 -12
  70. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +95 -0
  71. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +436 -59
  72. data/test/new_relic/agent/instrumentation/queue_time_test.rb +58 -357
  73. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -5
  74. data/test/new_relic/agent/method_tracer_test.rb +4 -2
  75. data/test/new_relic/agent/new_relic_service_test.rb +108 -6
  76. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  77. data/test/new_relic/agent/pipe_service_test.rb +9 -9
  78. data/test/new_relic/agent/rpm_agent_test.rb +0 -11
  79. data/test/new_relic/agent/rules_engine_test.rb +82 -0
  80. data/test/new_relic/agent/shim_agent_test.rb +0 -4
  81. data/test/new_relic/agent/sql_sampler_test.rb +7 -0
  82. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +85 -0
  83. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +110 -23
  84. data/test/new_relic/agent/stats_engine_test.rb +1 -46
  85. data/test/new_relic/agent/stats_hash_test.rb +93 -0
  86. data/test/new_relic/agent/stats_test.rb +197 -0
  87. data/test/new_relic/agent/transaction_info_test.rb +63 -11
  88. data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -3
  89. data/test/new_relic/agent/transaction_sampler_test.rb +92 -80
  90. data/test/new_relic/agent/worker_loop_test.rb +1 -1
  91. data/test/new_relic/agent_test.rb +35 -5
  92. data/test/new_relic/control_test.rb +1 -1
  93. data/test/new_relic/fake_collector.rb +87 -9
  94. data/test/new_relic/helper_test.rb +24 -0
  95. data/test/new_relic/metric_data_test.rb +11 -11
  96. data/test/new_relic/metric_spec_test.rb +1 -1
  97. data/test/script/ci.sh +1 -1
  98. data/test/test_contexts.rb +0 -1
  99. data/test/test_helper.rb +21 -3
  100. metadata +34 -41
  101. data/lib/new_relic/agent/cross_process_monitoring.rb +0 -187
  102. data/lib/new_relic/stats.rb +0 -337
  103. data/test/new_relic/agent/cross_process_monitoring_test.rb +0 -190
  104. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +0 -133
  105. data/test/new_relic/fakes_sending_data.rb +0 -30
  106. data/test/new_relic/stats_test.rb +0 -421
@@ -0,0 +1,58 @@
1
+ # A Hash-descended class for storing metric data in the NewRelic Agent.
2
+ #
3
+ # Keys are NewRelic::MetricSpec objects.
4
+ # Values are NewRelic::Agent::Stats objects.
5
+ #
6
+ # Missing keys will be automatically created as empty NewRelic::Agent::Stats
7
+ # instances, so use has_key? explicitly to check for key existence.
8
+ #
9
+ # This class makes no provisions for safe usage from multiple threads, such
10
+ # measures should be externally provided.
11
+ module NewRelic
12
+ module Agent
13
+ class StatsHash < ::Hash
14
+ def initialize
15
+ super { |hash, key| hash[key] = NewRelic::Agent::Stats.new }
16
+ end
17
+
18
+ def marshal_dump
19
+ Hash[self]
20
+ end
21
+
22
+ def marshal_load(hash)
23
+ self.merge!(hash)
24
+ end
25
+
26
+ def ==(other)
27
+ Hash[self] == Hash[other]
28
+ end
29
+
30
+ def record(metric_specs, value=nil)
31
+ Array(metric_specs).each do |metric_spec|
32
+ stats = self[metric_spec]
33
+ if block_given?
34
+ yield stats
35
+ else
36
+ case value
37
+ when Numeric
38
+ stats.record_data_point(value)
39
+ when NewRelic::Agent::Stats
40
+ stats.merge!(value)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def merge!(other)
47
+ other.each do |key,val|
48
+ if self.has_key?(key)
49
+ self[key].merge!(val)
50
+ else
51
+ self[key] = val
52
+ end
53
+ end
54
+ self
55
+ end
56
+ end
57
+ end
58
+ end
@@ -5,8 +5,8 @@ module Agent
5
5
  # A simple stack element that tracks the current name and length
6
6
  # of the executing stack
7
7
  class ScopeStackElement
8
- attr_reader :name, :deduct_call_time_from_parent
9
- attr_accessor :children_time
8
+ attr_reader :deduct_call_time_from_parent
9
+ attr_accessor :name, :children_time
10
10
  def initialize(name, deduct_call_time)
11
11
  @name = name
12
12
  @deduct_call_time_from_parent = deduct_call_time
@@ -30,6 +30,8 @@ module Agent
30
30
  def pop_scope(*args); end
31
31
  end
32
32
 
33
+ attr_reader :transaction_sampler
34
+
33
35
  # add a new transaction sampler, unless we're currently in a
34
36
  # transaction (then we fail)
35
37
  def transaction_sampler= sampler
@@ -74,6 +76,12 @@ module Agent
74
76
  @transaction_sampler && Agent.config[:'transaction_tracer.enabled']
75
77
  end
76
78
 
79
+ # Rename the segment associated with the last pushed scope to +new_name+.
80
+ def rename_scope_segment( new_name )
81
+ self.peek_scope.name = new_name
82
+ @transaction_sampler.rename_scope_segment( new_name )
83
+ end
84
+
77
85
  # Returns the latest ScopeStackElement
78
86
  def peek_scope
79
87
  scope_stack.last
@@ -3,17 +3,27 @@ require 'erb'
3
3
  module NewRelic
4
4
  module Agent
5
5
  class TransactionInfo
6
+ DEFAULT_TRANSACTION_NAME = '(unknown)'
6
7
 
7
- attr_accessor :token, :capture_deep_tt, :transaction_name
8
+ attr_accessor :token, :capture_deep_tt
9
+ attr_writer :transaction_name
8
10
  attr_reader :start_time
9
11
 
10
12
  def initialize
11
13
  @guid = ""
12
- @transaction_name = "(unknown)"
14
+ @transaction_name = nil
13
15
  @start_time = Time.now
14
16
  @ignore_end_user = false
15
17
  end
16
18
 
19
+ def transaction_name_set?
20
+ !@transaction_name.nil?
21
+ end
22
+
23
+ def transaction_name
24
+ @transaction_name || DEFAULT_TRANSACTION_NAME
25
+ end
26
+
17
27
  def force_persist_sample?(sample)
18
28
  token && sample.duration > Agent.config[:apdex_t]
19
29
  end
@@ -37,11 +47,26 @@ module NewRelic
37
47
  def ignore_end_user?
38
48
  @ignore_end_user
39
49
  end
40
-
50
+
41
51
  def ignore_end_user=(value)
42
52
  @ignore_end_user = value
43
53
  end
44
54
 
55
+ def apdex_t
56
+ (Agent.config[:web_transactions_apdex] &&
57
+ Agent.config[:web_transactions_apdex][@transaction_name]) ||
58
+ Agent.config[:apdex_t]
59
+ end
60
+
61
+ def transaction_trace_threshold
62
+ key = :'transaction_tracer.transaction_threshold'
63
+ if Agent.config.source(key).class == Configuration::DefaultSource
64
+ apdex_t * 4
65
+ else
66
+ Agent.config[key]
67
+ end
68
+ end
69
+
45
70
  def self.get()
46
71
  Thread.current[:newrelic_transaction_info] ||= TransactionInfo.new
47
72
  end
@@ -64,9 +89,9 @@ module NewRelic
64
89
 
65
90
  def self.get_token(request)
66
91
  return nil unless request
67
-
92
+
68
93
  agent_flag = request.cookies['NRAGENT']
69
- if agent_flag and agent_flag.instance_of? String
94
+ if agent_flag and agent_flag.instance_of? String
70
95
  s = agent_flag.split("=")
71
96
  if s.length == 2
72
97
  if s[0] == "tk" && s[1]
@@ -78,7 +103,7 @@ module NewRelic
78
103
  end
79
104
  end
80
105
 
81
- # Run through a collection of unsafe characters ( in the context of the token )
106
+ # Run through a collection of unsafe characters ( in the context of the token )
82
107
  # and set the token to an empty string if any of them are found in the token so that
83
108
  # potential XSS attacks via the token are avoided
84
109
  def self.sanitize_token(token)
@@ -21,22 +21,25 @@ module NewRelic
21
21
  def sample_id
22
22
  @sample.sample_id
23
23
  end
24
-
24
+
25
25
  def ignored?
26
26
  @ignore || @sample.params[:path].nil?
27
27
  end
28
-
28
+
29
29
  def ignore_transaction
30
30
  @ignore = true
31
31
  end
32
32
 
33
+ def segment_limit
34
+ Agent.config[:'transaction_tracer.limit_segments']
35
+ end
36
+
33
37
  def trace_entry(metric_name, time)
34
- segment_limit = Agent.config[:'transaction_tracer.limit_segments']
35
- if @sample.count_segments < segment_limit
38
+ if @sample.count_segments < segment_limit()
36
39
  segment = @sample.create_segment(time.to_f - @sample_start, metric_name)
37
40
  @current_segment.add_called_segment(segment)
38
41
  @current_segment = segment
39
- if @sample.count_segments == segment_limit
42
+ if @sample.count_segments == segment_limit()
40
43
  ::NewRelic::Agent.logger.debug("Segment limit of #{segment_limit} reached, ceasing collection.")
41
44
  end
42
45
  @current_segment
@@ -44,7 +47,7 @@ module NewRelic
44
47
  end
45
48
 
46
49
  def trace_exit(metric_name, time)
47
- return unless @sample.count_segments < Agent.config[:'transaction_tracer.limit_segments']
50
+ return unless @sample.count_segments < segment_limit()
48
51
  if metric_name != @current_segment.metric_name
49
52
  fail "unbalanced entry/exit: #{metric_name} != #{@current_segment.metric_name}"
50
53
  end
@@ -52,7 +55,7 @@ module NewRelic
52
55
  @current_segment = @current_segment.parent_segment
53
56
  end
54
57
 
55
- def finish_trace(time)
58
+ def finish_trace(time=Time.now.to_f)
56
59
  # This should never get called twice, but in a rare case that we can't reproduce in house it does.
57
60
  # log forensics and return gracefully
58
61
  if @sample.frozen?
@@ -63,7 +66,9 @@ module NewRelic
63
66
  @sample.params[:custom_params] ||= {}
64
67
  @sample.params[:custom_params].merge!(normalize_params(NewRelic::Agent::Instrumentation::MetricFrame.custom_parameters))
65
68
 
66
- @sample.force_persist = NewRelic::Agent::TransactionInfo.get.force_persist_sample?(sample)
69
+ txn_info = NewRelic::Agent::TransactionInfo.get
70
+ @sample.force_persist = txn_info.force_persist_sample?(sample)
71
+ @sample.threshold = txn_info.transaction_trace_threshold
67
72
  @sample.freeze
68
73
  @current_segment = nil
69
74
  end
@@ -106,6 +111,12 @@ module NewRelic
106
111
  @sample.params[:custom_params][:cpu_time] = cpu_time
107
112
  end
108
113
 
114
+ # Set the metric name of the current segment to +new_name+ if
115
+ def rename_current_segment( new_name )
116
+ return unless @sample.count_segments < segment_limit()
117
+ @current_segment.metric_name = new_name
118
+ end
119
+
109
120
  def sample
110
121
  @sample
111
122
  end
@@ -116,6 +116,12 @@ module NewRelic
116
116
  end
117
117
  end
118
118
 
119
+ # Rename the latest scope's segment in the builder to +new_name+.
120
+ def rename_scope_segment( new_name )
121
+ return unless builder
122
+ builder.rename_current_segment( new_name )
123
+ end
124
+
119
125
  # Defaults to zero, otherwise delegated to the transaction
120
126
  # sample builder
121
127
  def scope_depth
@@ -204,7 +210,8 @@ module NewRelic
204
210
  # Sets @slowest_sample to the passed in sample if it is slower
205
211
  # than the current sample in @slowest_sample
206
212
  def store_slowest_sample(sample)
207
- if slowest_sample?(@slowest_sample, sample)
213
+ if slowest_sample?(@slowest_sample, sample) && sample.threshold &&
214
+ sample.duration >= sample.threshold
208
215
  @slowest_sample = sample
209
216
  end
210
217
  end
@@ -256,7 +263,7 @@ module NewRelic
256
263
  return unless builder
257
264
  segment = builder.current_segment
258
265
  if segment
259
- new_message = truncate_message(append_new_message(segment[key],
266
+ new_message = self.class.truncate_message(append_new_message(segment[key],
260
267
  message))
261
268
  if key == :sql && config.respond_to?(:has_key?) && config.has_key?(:adapter)
262
269
  segment[key] = Database::Statement.new(new_message)
@@ -274,7 +281,7 @@ module NewRelic
274
281
  # Truncates the message to `MAX_DATA_LENGTH` if needed, and
275
282
  # appends an ellipsis because it makes the trucation clearer in
276
283
  # the UI
277
- def truncate_message(message)
284
+ def self.truncate_message(message)
278
285
  if message.length > (MAX_DATA_LENGTH - 4)
279
286
  message[0..MAX_DATA_LENGTH - 4] + '...'
280
287
  else
@@ -319,6 +326,12 @@ module NewRelic
319
326
  notice_extra_data(key, duration, :key)
320
327
  end
321
328
 
329
+ # Set parameters on the current segment.
330
+ def add_segment_parameters( params )
331
+ return unless builder
332
+ builder.current_segment.params.merge!( params )
333
+ end
334
+
322
335
  # Every 1/n harvests, adds the most recent sample to the harvest
323
336
  # array if it exists. Makes sure that the random sample is not
324
337
  # also the slowest sample for this harvest by `uniq!`ing the
@@ -352,13 +365,7 @@ module NewRelic
352
365
 
353
366
  force_persist.each {|sample| store_force_persist(sample)}
354
367
 
355
-
356
- # Now get the slowest sample
357
- if @slowest_sample &&
358
- @slowest_sample.duration >=
359
- Agent.config[:'transaction_tracer.transaction_threshold']
360
- result << @slowest_sample
361
- end
368
+ result << @slowest_sample if @slowest_sample
362
369
 
363
370
  result.compact!
364
371
  result = result.sort_by { |x| x.duration }
@@ -1,3 +1,5 @@
1
+ #encoding: utf-8
2
+
1
3
  module NewRelic
2
4
  # A singleton for shared generic helper methods
3
5
  module Helper
@@ -31,4 +33,34 @@ module NewRelic
31
33
  (time.to_f * 1000).round
32
34
  end
33
35
  end
36
+
37
+ # Load the JSON library from the standard library.
38
+ def self::load_stdlib_json
39
+ # Don't even try to use 1.9.1's json.
40
+ return false if RUBY_VERSION == '1.9.1'
41
+
42
+ require 'json'
43
+ define_method( :json_dump, &::JSON.method(:dump) )
44
+ define_method( :json_load, &::JSON.method(:parse) )
45
+
46
+ return true
47
+ rescue LoadError
48
+ NewRelic::Agent.logger.debug "%p while loading JSON library: %s" % [ err, err.message ] if
49
+ defined?( NewRelic::Agent ) && NewRelic::Agent.respond_to?( :logger )
50
+ return false
51
+ end
52
+
53
+
54
+ # Load the fallback JSON library
55
+ def self::load_okjson
56
+ require 'new_relic/okjson'
57
+ define_method( :json_dump, &::NewRelic::OkJson.method(:encode) )
58
+ define_method( :json_load, &::NewRelic::OkJson.method(:decode) )
59
+ end
60
+
61
+
62
+ load_stdlib_json or load_okjson
63
+ module_function :json_dump, :json_load
64
+
34
65
  end
66
+
@@ -49,7 +49,7 @@ module NewRelic
49
49
  rescue => e
50
50
  Agent.logger.error e
51
51
  end
52
-
52
+
53
53
  # yields to the block and appends the returned value to the list
54
54
  # of gems - this catches errors that might be raised in the block
55
55
  def append_gem_list
@@ -57,7 +57,7 @@ module NewRelic
57
57
  rescue => e
58
58
  Agent.logger.error e
59
59
  end
60
-
60
+
61
61
  # yields to the block and appends the returned value to the list
62
62
  # of plugins - this catches errors that might be raised in the block
63
63
  def append_plugin_list
@@ -65,7 +65,7 @@ module NewRelic
65
65
  rescue => e
66
66
  Agent.logger.error e
67
67
  end
68
-
68
+
69
69
  # An instance id pulled from either @dispatcher_instance_id or by
70
70
  # splitting out the first part of the running file
71
71
  def dispatcher_instance_id
@@ -76,7 +76,7 @@ module NewRelic
76
76
  end
77
77
  @dispatcher_instance_id
78
78
  end
79
-
79
+
80
80
  # Interrogates some common ruby constants for useful information
81
81
  # about what kind of ruby environment the agent is running in
82
82
  def gather_ruby_info
@@ -89,7 +89,7 @@ module NewRelic
89
89
  gather_jruby_info
90
90
  end
91
91
  end
92
-
92
+
93
93
  # like gather_ruby_info but for the special case of JRuby
94
94
  def gather_jruby_info
95
95
  append_environment_value('JRuby version') { JRUBY_VERSION }
@@ -122,14 +122,14 @@ module NewRelic
122
122
  processors
123
123
  end
124
124
  end
125
-
125
+
126
126
  # Grabs the architecture string from either `uname -p` or the env
127
127
  # variable PROCESSOR_ARCHITECTURE
128
128
  def gather_architecture_info
129
129
  append_environment_value('Arch') { `uname -p` } ||
130
130
  append_environment_value('Arch') { ENV['PROCESSOR_ARCHITECTURE'] }
131
131
  end
132
-
132
+
133
133
  # gathers OS info from either `uname -v`, `uname -s`, or the OS
134
134
  # env variable
135
135
  def gather_os_info
@@ -137,13 +137,13 @@ module NewRelic
137
137
  append_environment_value('OS') { `uname -s` } ||
138
138
  append_environment_value('OS') { ENV['OS'] }
139
139
  end
140
-
140
+
141
141
  # Gathers the architecture and cpu info
142
142
  def gather_system_info
143
143
  gather_architecture_info
144
144
  gather_cpu_info
145
145
  end
146
-
146
+
147
147
  # Looks for a capistrano file indicating the current revision
148
148
  def gather_revision_info
149
149
  rev_file = File.join(NewRelic::Control.instance.root, "REVISION")
@@ -153,11 +153,10 @@ module NewRelic
153
153
  end
154
154
  end
155
155
  end
156
-
156
+
157
157
  # The name of the AR database adapter for the current environment and
158
158
  # the current schema version
159
159
  def gather_ar_adapter_info
160
-
161
160
  append_environment_value 'Database adapter' do
162
161
  if defined?(ActiveRecord) && defined?(ActiveRecord::Base) &&
163
162
  ActiveRecord::Base.respond_to?(:configurations)
@@ -168,7 +167,7 @@ module NewRelic
168
167
  end
169
168
  end
170
169
  end
171
-
170
+
172
171
  # Datamapper version
173
172
  def gather_dm_adapter_info
174
173
  append_environment_value 'DataMapper version' do
@@ -176,7 +175,7 @@ module NewRelic
176
175
  DataMapper::VERSION
177
176
  end
178
177
  end
179
-
178
+
180
179
  # sensing for which adapter is defined, then appends the relevant
181
180
  # config information
182
181
  def gather_db_info
@@ -212,13 +211,13 @@ module NewRelic
212
211
  i << [ 'Gems', @gems.to_a] if not @gems.empty?
213
212
  i
214
213
  end
215
-
214
+
216
215
  # it's a working jruby if it has the runtime method, and object
217
216
  # space is enabled
218
217
  def working_jruby?
219
218
  !(defined?(::JRuby) && JRuby.respond_to?(:runtime) && !JRuby.runtime.is_object_space_enabled)
220
219
  end
221
-
220
+
222
221
  # Runs through all the objects in ObjectSpace to find the first one that
223
222
  # match the provided class
224
223
  def find_class_in_object_space(klass)
@@ -227,7 +226,7 @@ module NewRelic
227
226
  end
228
227
  return nil
229
228
  end
230
-
229
+
231
230
  # Sets the @mongrel instance variable if we can find a Mongrel::HttpServer
232
231
  def mongrel
233
232
  return @mongrel if @mongrel
@@ -236,13 +235,13 @@ module NewRelic
236
235
  end
237
236
  @mongrel
238
237
  end
239
-
238
+
240
239
  private
241
240
 
242
241
  # Although you can override the dispatcher with NEWRELIC_DISPATCHER this
243
242
  # is not advisable since it implies certain api's being available.
244
243
  def discover_dispatcher
245
- dispatchers = %w[passenger torquebox trinidad glassfish thin mongrel litespeed webrick fastcgi unicorn sinatra]
244
+ dispatchers = %w[passenger torquebox trinidad glassfish resque thin mongrel litespeed webrick fastcgi unicorn]
246
245
  while dispatchers.any? && @discovered_dispatcher.nil?
247
246
  send 'check_for_'+(dispatchers.shift)
248
247
  end
@@ -316,20 +315,13 @@ module NewRelic
316
315
  end
317
316
  end
318
317
 
319
- def check_for_sinatra
320
- return unless defined?(::Sinatra) && defined?(::Sinatra::Base)
321
-
322
- begin
323
- version = ::Sinatra::VERSION
324
- rescue
325
- $stderr.puts("Error determining Sinatra version")
326
- end
327
-
328
- if ::NewRelic::VersionNumber.new('0.9.2') > version
329
- $stderr.puts("Your Sinatra version is #{version}, we highly recommend upgrading to >=0.9.2")
330
- end
331
-
332
- @discovered_dispatcher = :sinatra
318
+ def check_for_resque
319
+ using_resque = (
320
+ defined?(::Resque) &&
321
+ (ENV['QUEUE'] || ENV['QUEUES']) &&
322
+ (File.basename($0) == 'rake' && ARGV.include?('resque:work'))
323
+ )
324
+ @discovered_dispatcher = :resque if using_resque
333
325
  end
334
326
 
335
327
  def check_for_thin