newrelic_rpm 3.2.0.1 → 3.3.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +7 -3
- data/LICENSE +2 -29
- data/README.rdoc +2 -2
- data/lib/new_relic/agent.rb +14 -0
- data/lib/new_relic/agent/agent.rb +19 -9
- data/lib/new_relic/agent/beacon_configuration.rb +11 -0
- data/lib/new_relic/agent/browser_monitoring.rb +53 -13
- data/lib/new_relic/agent/database.rb +11 -1
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +3 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +23 -2
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +15 -12
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +11 -8
- data/lib/new_relic/agent/sql_sampler.rb +19 -7
- data/lib/new_relic/agent/stats_engine.rb +1 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +120 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -85
- data/lib/new_relic/agent/transaction_info.rb +49 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +2 -0
- data/lib/new_relic/agent/transaction_sampler.rb +65 -7
- data/lib/new_relic/rack/browser_monitoring.rb +38 -8
- data/lib/new_relic/transaction_sample.rb +8 -6
- data/lib/new_relic/version.rb +2 -2
- data/newrelic.yml +1 -1
- data/newrelic_rpm.gemspec +6 -3
- data/test/new_relic/agent/agent/connect_test.rb +4 -11
- data/test/new_relic/agent/beacon_configuration_test.rb +10 -7
- data/test/new_relic/agent/browser_monitoring_test.rb +69 -44
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +12 -8
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -1
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +3 -3
- data/test/new_relic/agent/sql_sampler_test.rb +25 -10
- data/test/new_relic/agent/stats_engine_test.rb +41 -6
- data/test/new_relic/agent/transaction_sampler_test.rb +22 -12
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +7 -1
- metadata +321 -337
data/CHANGELOG
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
v3.
|
2
|
-
*
|
3
|
-
*
|
1
|
+
v3.3.0
|
2
|
+
* fix for GC instrumentation when using Ruby 1.9
|
3
|
+
* new feature to correlate browser and server transaction traces
|
4
|
+
* new feature to trace slow sql statements
|
5
|
+
* fix to help cope with malformed rack responses
|
6
|
+
* do not try to instrument versions of ActiveMerchant that are too old
|
7
|
+
|
4
8
|
v3.2.0
|
5
9
|
* Fix over-detection of mongrel and unicorn and only start the agent when
|
6
10
|
actual server is running
|
data/LICENSE
CHANGED
@@ -1,31 +1,4 @@
|
|
1
|
-
|
2
|
-
and distributed under an MIT license.
|
3
|
-
See https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt
|
4
|
-
|
5
|
-
Copyright (c) 2011 John Resig, http://jquery.com/
|
6
|
-
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
-
a copy of this software and associated documentation files (the
|
9
|
-
"Software"), to deal in the Software without restriction, including
|
10
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
-
permit persons to whom the Software is furnished to do so, subject to
|
13
|
-
the following conditions:
|
14
|
-
|
15
|
-
The above copyright notice and this permission notice shall be
|
16
|
-
included in all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
-
|
26
|
-
|
27
|
-
All other components of this product are
|
28
|
-
Copyright (c) 2008-2011 New Relic, Inc. All rights reserved.
|
1
|
+
Copyright (c) 2008-2010 New Relic, Inc. All rights reserved.
|
29
2
|
|
30
3
|
Certain inventions disclosed in this file may be claimed within
|
31
4
|
patents owned or patent applications filed by New Relic, Inc. or third
|
@@ -61,4 +34,4 @@ FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
|
|
61
34
|
condition to your use of these files, you are solely responsible for
|
62
35
|
such use. New Relic will have no liability to you for direct,
|
63
36
|
indirect, consequential, incidental, special, or punitive damages or
|
64
|
-
for lost profits or data.
|
37
|
+
for lost profits or data.
|
data/README.rdoc
CHANGED
@@ -163,7 +163,7 @@ online. Refer to instructions in *Getting Started*, below.
|
|
163
163
|
= Support
|
164
164
|
|
165
165
|
Reach out to us--and to fellow users--at
|
166
|
-
support.newrelic.com[http://support.newrelic.com/].
|
166
|
+
support.newrelic.com[http://support.newrelic.com/discussions/support].
|
167
167
|
There you'll find documentation, FAQs, and forums where you can submit
|
168
168
|
suggestions and discuss New Relic with staff and other users.
|
169
169
|
|
@@ -171,7 +171,7 @@ Also available is community support on IRC: we generally use #newrelic
|
|
171
171
|
on irc.freenode.net
|
172
172
|
|
173
173
|
Find a bug? E-mail support@newrelic.com, or post it to
|
174
|
-
support.newrelic.com[http://support.newrelic.com/].
|
174
|
+
support.newrelic.com[http://support.newrelic.com/discussions/support].
|
175
175
|
|
176
176
|
Thank you, and may your application scale to infinity plus one.
|
177
177
|
|
data/lib/new_relic/agent.rb
CHANGED
@@ -86,6 +86,7 @@ module NewRelic
|
|
86
86
|
require 'new_relic/agent/busy_calculator'
|
87
87
|
require 'new_relic/agent/sampler'
|
88
88
|
require 'new_relic/agent/database'
|
89
|
+
require 'new_relic/agent/transaction_info'
|
89
90
|
|
90
91
|
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
91
92
|
|
@@ -387,6 +388,19 @@ module NewRelic
|
|
387
388
|
def add_custom_parameters(params)
|
388
389
|
NewRelic::Agent::Instrumentation::MetricFrame.add_custom_parameters(params)
|
389
390
|
end
|
391
|
+
|
392
|
+
# Set attributes about the user making this request. These attributes will be automatically
|
393
|
+
# appended to any Transaction Trace or Error that is collected. These attributes
|
394
|
+
# will also be collected for RUM requests.
|
395
|
+
#
|
396
|
+
# Attributes (hash)
|
397
|
+
# * <tt>:user</tt> => user name or ID
|
398
|
+
# * <tt>:account</tt> => account name or ID
|
399
|
+
# * <tt>:product</tt> => product name or level
|
400
|
+
#
|
401
|
+
def set_user_attributes(attributes)
|
402
|
+
NewRelic::Agent::Instrumentation::MetricFrame.set_user_attributes(attributes)
|
403
|
+
end
|
390
404
|
|
391
405
|
# The #add_request_parameters method is aliased to #add_custom_parameters
|
392
406
|
# and is now deprecated.
|
@@ -37,7 +37,6 @@ module NewRelic
|
|
37
37
|
@transaction_sampler = NewRelic::Agent::TransactionSampler.new
|
38
38
|
@sql_sampler = NewRelic::Agent::SqlSampler.new
|
39
39
|
@stats_engine.transaction_sampler = @transaction_sampler
|
40
|
-
@stats_engine.sql_sampler = @sql_sampler
|
41
40
|
@error_collector = NewRelic::Agent::ErrorCollector.new
|
42
41
|
@connect_attempts = 0
|
43
42
|
|
@@ -775,13 +774,15 @@ module NewRelic
|
|
775
774
|
# Ask the server for permission to send transaction samples.
|
776
775
|
# determined by subscription license.
|
777
776
|
@transaction_sampler.config['enabled'] = server_enabled
|
778
|
-
@sql_sampler.
|
779
|
-
|
777
|
+
@sql_sampler.configure!
|
780
778
|
@should_send_samples = @config_should_send_samples && server_enabled
|
781
|
-
|
779
|
+
|
782
780
|
if @should_send_samples
|
783
781
|
# I don't think this is ever true, but...
|
784
782
|
enable_random_samples!(sample_rate) if @should_send_random_samples
|
783
|
+
|
784
|
+
@transaction_sampler.slow_capture_threshold = @slowest_transaction_threshold
|
785
|
+
|
785
786
|
log.debug "Transaction tracing threshold is #{@slowest_transaction_threshold} seconds."
|
786
787
|
else
|
787
788
|
log.debug "Transaction traces will not be sent to the New Relic service."
|
@@ -862,6 +863,11 @@ module NewRelic
|
|
862
863
|
@beacon_configuration = BeaconConfiguration.new(config_data)
|
863
864
|
@server_side_config_enabled = config_data['listen_to_server_config']
|
864
865
|
|
866
|
+
if @server_side_config_enabled
|
867
|
+
log.info "Using config from server"
|
868
|
+
log.debug "Server provided config: #{config_data.inspect}"
|
869
|
+
end
|
870
|
+
|
865
871
|
control.merge_server_side_config(config_data) if @server_side_config_enabled
|
866
872
|
config_transaction_tracer
|
867
873
|
log_connection!(config_data)
|
@@ -1063,6 +1069,10 @@ module NewRelic
|
|
1063
1069
|
unless @traces.empty?
|
1064
1070
|
now = Time.now
|
1065
1071
|
log.debug "Sending (#{@traces.length}) transaction traces"
|
1072
|
+
|
1073
|
+
# REMOVE THIS BEFORE SHIPPING
|
1074
|
+
log.info "Sending tts with GUIDS #{@traces.collect{|t| t.guid}.join(",")}"
|
1075
|
+
|
1066
1076
|
begin
|
1067
1077
|
options = { :keep_backtraces => true }
|
1068
1078
|
options[:record_sql] = @record_sql unless @record_sql == :off
|
@@ -1134,16 +1144,16 @@ module NewRelic
|
|
1134
1144
|
def compress_data(object)
|
1135
1145
|
dump = Marshal.dump(object)
|
1136
1146
|
|
1137
|
-
# this checks to make sure mongrel won't choke on big uploads
|
1138
|
-
check_post_size(dump)
|
1139
|
-
|
1140
1147
|
dump_size = dump.size
|
1141
1148
|
|
1142
1149
|
return [dump, 'identity'] if dump_size < (64*1024)
|
1143
1150
|
|
1144
|
-
|
1151
|
+
compressed_dump = Zlib::Deflate.deflate(dump, Zlib::DEFAULT_COMPRESSION)
|
1152
|
+
|
1153
|
+
# this checks to make sure mongrel won't choke on big uploads
|
1154
|
+
check_post_size(compressed_dump)
|
1145
1155
|
|
1146
|
-
[
|
1156
|
+
[compressed_dump, 'deflate']
|
1147
1157
|
end
|
1148
1158
|
|
1149
1159
|
# Raises a PostTooBigException if the post_string is longer
|
@@ -28,6 +28,13 @@ module NewRelic
|
|
28
28
|
# local config
|
29
29
|
attr_reader :rum_enabled
|
30
30
|
|
31
|
+
# whether JSONP is used to communicate with the Beacon or not
|
32
|
+
attr_reader :rum_jsonp
|
33
|
+
|
34
|
+
# RUM footer command used for 'finish' - based on whether JSONP is
|
35
|
+
# being used. 'nrfj' for JSONP, otherwise 'nrf2'
|
36
|
+
attr_reader :finish_command
|
37
|
+
|
31
38
|
# A static javascript header that is identical for every account
|
32
39
|
# and application
|
33
40
|
JS_HEADER = "<script type=\"text/javascript\">var NREUMQ=NREUMQ||[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
|
@@ -45,6 +52,10 @@ module NewRelic
|
|
45
52
|
NewRelic::Control.instance.log.debug("Browser timing header: #{@browser_timing_header.inspect}")
|
46
53
|
@browser_timing_static_footer = build_load_file_js(connect_data)
|
47
54
|
NewRelic::Control.instance.log.debug("Browser timing static footer: #{@browser_timing_static_footer.inspect}")
|
55
|
+
@rum_jsonp = connect_data['rum.jsonp']
|
56
|
+
@rum_jsonp = true if @rum_jsonp.nil?
|
57
|
+
NewRelic::Control.instance.log.debug("Real User Monitoring is using JSONP protocol") if @rum_jsonp
|
58
|
+
@finish_command = @rum_jsonp ? 'nrfj' : 'nrf2'
|
48
59
|
end
|
49
60
|
|
50
61
|
# returns a memoized version of the bytes in the license key for
|
@@ -6,6 +6,24 @@ module NewRelic
|
|
6
6
|
# javascript generation and configuration
|
7
7
|
module BrowserMonitoring
|
8
8
|
|
9
|
+
|
10
|
+
class DummyMetricFrame
|
11
|
+
def initialize
|
12
|
+
@attributes = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_attributes
|
16
|
+
@attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
def queue_time
|
20
|
+
0.0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@@dummy_metric_frame = DummyMetricFrame.new
|
25
|
+
|
26
|
+
|
9
27
|
# This method returns a string suitable for inclusion in a page
|
10
28
|
# - known as 'manual instrumentation' for Real User
|
11
29
|
# Monitoring. Can return either a script tag with associated
|
@@ -34,32 +52,49 @@ module NewRelic
|
|
34
52
|
config = NewRelic::Agent.instance.beacon_configuration
|
35
53
|
return "" if config.nil? || !config.rum_enabled || config.browser_monitoring_key.nil?
|
36
54
|
return "" if !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
|
37
|
-
generate_footer_js
|
55
|
+
generate_footer_js(config)
|
38
56
|
end
|
39
57
|
|
40
58
|
private
|
41
59
|
|
42
|
-
def generate_footer_js
|
60
|
+
def generate_footer_js(config)
|
43
61
|
if browser_monitoring_start_time
|
44
|
-
config = NewRelic::Agent.instance.beacon_configuration
|
45
62
|
application_id = config.application_id
|
46
63
|
beacon = config.beacon
|
47
64
|
license_key = config.browser_monitoring_key
|
48
65
|
|
49
|
-
footer_js_string(beacon, license_key, application_id)
|
66
|
+
footer_js_string(config, beacon, license_key, application_id)
|
50
67
|
else
|
51
68
|
''
|
52
69
|
end
|
53
70
|
end
|
54
71
|
|
55
72
|
def browser_monitoring_transaction_name
|
56
|
-
|
73
|
+
NewRelic::Agent::TransactionInfo.get.transaction_name
|
57
74
|
end
|
58
75
|
|
59
76
|
def browser_monitoring_start_time
|
60
|
-
|
77
|
+
NewRelic::Agent::TransactionInfo.get.start_time
|
61
78
|
end
|
62
|
-
|
79
|
+
|
80
|
+
def metric_frame_attribute(key)
|
81
|
+
current_metric_frame.user_attributes[key] || ""
|
82
|
+
end
|
83
|
+
|
84
|
+
def current_metric_frame
|
85
|
+
Thread.current[:last_metric_frame] || @@dummy_metric_frame
|
86
|
+
end
|
87
|
+
|
88
|
+
def tt_guid
|
89
|
+
txn = NewRelic::Agent::TransactionInfo.get
|
90
|
+
return txn.guid if txn.include_guid?
|
91
|
+
""
|
92
|
+
end
|
93
|
+
|
94
|
+
def tt_token
|
95
|
+
return NewRelic::Agent::TransactionInfo.get.token
|
96
|
+
end
|
97
|
+
|
63
98
|
def clamp_to_positive(value)
|
64
99
|
return 0.0 if value < 0
|
65
100
|
value
|
@@ -70,12 +105,17 @@ module NewRelic
|
|
70
105
|
end
|
71
106
|
|
72
107
|
def browser_monitoring_queue_time
|
73
|
-
clamp_to_positive((
|
108
|
+
clamp_to_positive((current_metric_frame.queue_time.to_f * 1000.0).round)
|
74
109
|
end
|
75
110
|
|
76
|
-
def footer_js_string(beacon, license_key, application_id)
|
77
|
-
obfuscated_transaction_name = obfuscate(browser_monitoring_transaction_name)
|
78
|
-
|
111
|
+
def footer_js_string(config, beacon, license_key, application_id)
|
112
|
+
obfuscated_transaction_name = obfuscate(config, browser_monitoring_transaction_name)
|
113
|
+
|
114
|
+
user = obfuscate(config, metric_frame_attribute(:user))
|
115
|
+
account = obfuscate(config, metric_frame_attribute(:account))
|
116
|
+
product = obfuscate(config, metric_frame_attribute(:product))
|
117
|
+
|
118
|
+
html_safe_if_needed("<script type=\"text/javascript\">#{config.browser_timing_static_footer}NREUMQ.push([\"#{config.finish_command}\",\"#{beacon}\",\"#{license_key}\",#{application_id},\"#{obfuscated_transaction_name}\",#{browser_monitoring_queue_time},#{browser_monitoring_app_time},new Date().getTime(),\"#{tt_guid}\",\"#{tt_token}\",\"#{user}\",\"#{account}\",\"#{product}\"])</script>")
|
79
119
|
end
|
80
120
|
|
81
121
|
def html_safe_if_needed(string)
|
@@ -86,9 +126,9 @@ module NewRelic
|
|
86
126
|
end
|
87
127
|
end
|
88
128
|
|
89
|
-
def obfuscate(text)
|
129
|
+
def obfuscate(config, text)
|
90
130
|
obfuscated = ""
|
91
|
-
key_bytes =
|
131
|
+
key_bytes = config.license_bytes
|
92
132
|
index = 0
|
93
133
|
text.each_byte{|byte|
|
94
134
|
obfuscated.concat((byte ^ key_bytes[index % 13].to_i))
|
@@ -30,11 +30,19 @@ module NewRelic
|
|
30
30
|
def get_connection(config)
|
31
31
|
ConnectionManager.instance.get_connection(config)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def close_connections
|
35
35
|
ConnectionManager.instance.close_connections
|
36
36
|
end
|
37
37
|
|
38
|
+
def config
|
39
|
+
ConnectionManager.instance.config
|
40
|
+
end
|
41
|
+
|
42
|
+
def config=(other)
|
43
|
+
ConnectionManager.instance.config = other
|
44
|
+
end
|
45
|
+
|
38
46
|
# Perform this in the runtime environment of a managed
|
39
47
|
# application, to explain the sql statement executed within a
|
40
48
|
# segment of a transaction sample. Returns an array of
|
@@ -114,6 +122,8 @@ module NewRelic
|
|
114
122
|
|
115
123
|
class ConnectionManager
|
116
124
|
include Singleton
|
125
|
+
|
126
|
+
attr_accessor :config
|
117
127
|
|
118
128
|
# Returns a cached connection for a given ActiveRecord
|
119
129
|
# configuration - these are stored or reopened as needed, and if
|
@@ -2,7 +2,9 @@ DependencyDetection.defer do
|
|
2
2
|
@name = :active_merchant
|
3
3
|
|
4
4
|
depends_on do
|
5
|
-
defined?(ActiveMerchant) && defined?(ActiveMerchant::Billing)
|
5
|
+
defined?(ActiveMerchant) && defined?(ActiveMerchant::Billing) &&
|
6
|
+
defined?(ActiveMerchant::Billing::Gateway) &&
|
7
|
+
ActiveMerchant::Billing::Gateway.respond_to?(:implementations)
|
6
8
|
end
|
7
9
|
|
8
10
|
executes do
|
@@ -340,7 +340,9 @@ module NewRelic
|
|
340
340
|
available_params = self.respond_to?(:params) ? self.params : {}
|
341
341
|
end
|
342
342
|
frame_data.request ||= self.request if self.respond_to? :request
|
343
|
-
|
343
|
+
transaction_name = category + '/' + path
|
344
|
+
frame_data.push(transaction_name)
|
345
|
+
NewRelic::Agent::TransactionInfo.get.transaction_name = transaction_name
|
344
346
|
frame_data.filtered_params = (respond_to? :filter_parameters) ? filter_parameters(available_params) : available_params
|
345
347
|
frame_data
|
346
348
|
end
|
@@ -403,7 +405,6 @@ module NewRelic
|
|
403
405
|
queue_start = nil
|
404
406
|
if newrelic_request_headers
|
405
407
|
queue_start = parse_frontend_headers(newrelic_request_headers)
|
406
|
-
Thread.current[:newrelic_queue_time] = (now.to_f - queue_start.to_f) if queue_start
|
407
408
|
end
|
408
409
|
queue_start || now
|
409
410
|
rescue Exception => e
|
@@ -74,10 +74,11 @@ module NewRelic
|
|
74
74
|
attr_reader :depth
|
75
75
|
|
76
76
|
def initialize
|
77
|
-
|
77
|
+
@start = Time.now
|
78
78
|
@path_stack = [] # stack of [controller, path] elements
|
79
79
|
@jruby_cpu_start = jruby_cpu_time
|
80
80
|
@process_cpu_start = process_cpu
|
81
|
+
Thread.current[:last_metric_frame] = self
|
81
82
|
end
|
82
83
|
|
83
84
|
def agent
|
@@ -199,11 +200,19 @@ module NewRelic
|
|
199
200
|
def self.add_custom_parameters(p)
|
200
201
|
current.add_custom_parameters(p) if current
|
201
202
|
end
|
202
|
-
|
203
|
+
|
203
204
|
def self.custom_parameters
|
204
205
|
(current && current.custom_parameters) ? current.custom_parameters : {}
|
205
206
|
end
|
206
207
|
|
208
|
+
def self.set_user_attributes(attributes)
|
209
|
+
current.set_user_attributes(attributes) if current
|
210
|
+
end
|
211
|
+
|
212
|
+
def self.user_attributes
|
213
|
+
(current) ? current.user_attributes : {}
|
214
|
+
end
|
215
|
+
|
207
216
|
def record_apdex()
|
208
217
|
return unless recording_web_transaction? && NewRelic::Agent.is_execution_traced?
|
209
218
|
t = Time.now
|
@@ -248,10 +257,22 @@ module NewRelic
|
|
248
257
|
def custom_parameters
|
249
258
|
@custom_parameters ||= {}
|
250
259
|
end
|
260
|
+
|
261
|
+
def user_attributes
|
262
|
+
@user_atrributes ||= {}
|
263
|
+
end
|
264
|
+
|
265
|
+
def queue_time
|
266
|
+
apdex_start - start
|
267
|
+
end
|
251
268
|
|
252
269
|
def add_custom_parameters(p)
|
253
270
|
custom_parameters.merge!(p)
|
254
271
|
end
|
272
|
+
|
273
|
+
def set_user_attributes(attributes)
|
274
|
+
user_attributes.merge!(attributes)
|
275
|
+
end
|
255
276
|
|
256
277
|
def self.recording_web_transaction?
|
257
278
|
c = Thread.current[:newrelic_metric_frame]
|
@@ -8,19 +8,12 @@ module NewRelic
|
|
8
8
|
alias_method :log_without_newrelic_instrumentation, :log
|
9
9
|
alias_method :log, :log_with_newrelic_instrumentation
|
10
10
|
protected :log
|
11
|
-
end
|
11
|
+
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def log_with_newrelic_instrumentation(sql, name, &block)
|
15
|
-
|
16
15
|
return log_without_newrelic_instrumentation(sql, name, &block) unless NewRelic::Agent.is_execution_traced?
|
17
|
-
|
18
|
-
# Capture db config if we are going to try to get the explain plans
|
19
|
-
if (defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)) ||
|
20
|
-
(defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && self.is_a?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)) ||
|
21
|
-
(defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter))
|
22
|
-
supported_config = @config
|
23
|
-
end
|
16
|
+
|
24
17
|
if name && (parts = name.split " ") && parts.size == 2
|
25
18
|
model = parts.first
|
26
19
|
operation = parts.last.downcase
|
@@ -56,13 +49,22 @@ module NewRelic
|
|
56
49
|
else
|
57
50
|
metrics = [metric, "ActiveRecord/all"]
|
58
51
|
metrics << "ActiveRecord/#{metric_name}" if metric_name
|
52
|
+
if NewRelic::Agent::Database.config && NewRelic::Agent::Database.config[:adapter]
|
53
|
+
type = NewRelic::Agent::Database.config[:adapter].sub(/\d*/, '')
|
54
|
+
host = NewRelic::Agent::Database.config[:host] || 'localhost'
|
55
|
+
metrics << "RemoteService/sql/#{type}/#{host}"
|
56
|
+
end
|
57
|
+
|
59
58
|
self.class.trace_execution_scoped(metrics) do
|
60
59
|
t0 = Time.now
|
61
60
|
begin
|
62
61
|
log_without_newrelic_instrumentation(sql, name, &block)
|
63
62
|
ensure
|
64
|
-
|
65
|
-
NewRelic::Agent.instance.
|
63
|
+
elapsed_time = (Time.now - t0).to_f
|
64
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, NewRelic::Agent::Database.config,
|
65
|
+
elapsed_time)
|
66
|
+
NewRelic::Agent.instance.sql_sampler.notice_sql(sql, metric, NewRelic::Agent::Database.config,
|
67
|
+
elapsed_time)
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
@@ -104,6 +106,7 @@ DependencyDetection.defer do
|
|
104
106
|
|
105
107
|
executes do
|
106
108
|
ActiveRecord::Base.class_eval do
|
109
|
+
NewRelic::Agent::Database::ConnectionManager.instance.config = connection.instance_eval{ @config }
|
107
110
|
class << self
|
108
111
|
add_method_tracer :find_by_sql, 'ActiveRecord/#{self.name}/find_by_sql', :metric => false
|
109
112
|
add_method_tracer :transaction, 'ActiveRecord/#{self.name}/transaction', :metric => false
|