newrelic_rpm 3.6.6.147 → 3.6.7.152
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +0 -1
- data/CHANGELOG +55 -17
- data/Guardfile +7 -0
- data/Rakefile +6 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/bin/nrdebug +273 -0
- data/install.rb +3 -3
- data/lib/new_relic/agent.rb +4 -6
- data/lib/new_relic/agent/agent.rb +76 -72
- data/lib/new_relic/agent/autostart.rb +18 -5
- data/lib/new_relic/agent/browser_monitoring.rb +41 -35
- data/lib/new_relic/agent/browser_token.rb +38 -0
- data/lib/new_relic/agent/busy_calculator.rb +7 -5
- data/lib/new_relic/agent/commands/agent_command.rb +19 -0
- data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
- data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
- data/lib/new_relic/agent/configuration/default_source.rb +700 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
- data/lib/new_relic/agent/configuration/manager.rb +8 -8
- data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
- data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
- data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
- data/lib/new_relic/agent/error_collector.rb +7 -10
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
- data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
- data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
- data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
- data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
- data/lib/new_relic/agent/method_tracer.rb +181 -191
- data/lib/new_relic/agent/new_relic_service.rb +16 -14
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/request_sampler.rb +32 -165
- data/lib/new_relic/agent/sampled_buffer.rb +79 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
- data/lib/new_relic/agent/sql_sampler.rb +3 -3
- data/lib/new_relic/agent/stats_engine.rb +1 -1
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
- data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
- data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
- data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
- data/lib/new_relic/agent/transaction.rb +16 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
- data/lib/new_relic/agent/transaction_sampler.rb +5 -8
- data/lib/new_relic/agent/transaction_state.rb +166 -0
- data/lib/new_relic/agent/transaction_timings.rb +53 -0
- data/lib/new_relic/cli/command.rb +91 -0
- data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
- data/lib/new_relic/{commands → cli}/install.rb +2 -2
- data/lib/new_relic/control/frameworks/rails.rb +1 -8
- data/lib/new_relic/control/instance_methods.rb +1 -2
- data/lib/new_relic/helper.rb +9 -0
- data/lib/new_relic/local_environment.rb +16 -63
- data/lib/new_relic/rack/browser_monitoring.rb +8 -5
- data/lib/new_relic/recipes.rb +44 -31
- data/lib/new_relic/transaction_sample.rb +6 -2
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/install.rake +21 -1
- data/newrelic_rpm.gemspec +5 -1
- data/test/agent_helper.rb +4 -9
- data/test/environments/.gitignore +16 -0
- data/test/environments/lib/environments/runner.rb +104 -0
- data/test/environments/norails/Gemfile +11 -0
- data/test/environments/norails/Rakefile +9 -0
- data/test/environments/rails21/Gemfile +24 -0
- data/test/environments/rails21/Rakefile +12 -0
- data/test/environments/rails21/app/controllers/application.rb +20 -0
- data/test/environments/rails21/config/boot.rb +113 -0
- data/test/environments/rails21/config/database.yml +31 -0
- data/test/environments/rails21/config/environment.rb +28 -0
- data/test/environments/rails21/config/environments/development.rb +16 -0
- data/test/environments/rails21/config/environments/production.rb +8 -0
- data/test/environments/rails21/config/environments/test.rb +10 -0
- data/test/environments/rails21/config/routes.rb +5 -0
- data/test/environments/rails21/db/schema.rb +5 -0
- data/test/environments/rails22/Gemfile +29 -0
- data/test/environments/rails22/Rakefile +12 -0
- data/test/environments/rails22/app/controllers/application.rb +20 -0
- data/test/environments/rails22/config/boot.rb +113 -0
- data/test/environments/rails22/config/database.yml +31 -0
- data/test/environments/rails22/config/environment.rb +27 -0
- data/test/environments/rails22/config/environments/development.rb +16 -0
- data/test/environments/rails22/config/environments/production.rb +8 -0
- data/test/environments/rails22/config/environments/test.rb +10 -0
- data/test/environments/rails22/config/routes.rb +5 -0
- data/test/environments/rails22/db/schema.rb +5 -0
- data/test/environments/rails23/Gemfile +22 -0
- data/test/environments/rails23/Rakefile +12 -0
- data/test/environments/rails23/app/controllers/application.rb +20 -0
- data/test/environments/rails23/config/boot.rb +127 -0
- data/test/environments/rails23/config/database.yml +31 -0
- data/test/environments/rails23/config/environment.rb +25 -0
- data/test/environments/rails23/config/environments/development.rb +16 -0
- data/test/environments/rails23/config/environments/production.rb +8 -0
- data/test/environments/rails23/config/environments/test.rb +10 -0
- data/test/environments/rails23/config/preinitializer.rb +25 -0
- data/test/environments/rails23/config/routes.rb +5 -0
- data/test/environments/rails23/db/schema.rb +5 -0
- data/test/environments/rails30/Gemfile +19 -0
- data/test/environments/rails30/Rakefile +9 -0
- data/test/environments/rails30/config/application.rb +17 -0
- data/test/environments/rails30/config/boot.rb +10 -0
- data/test/environments/rails30/config/database.yml +31 -0
- data/test/environments/rails30/config/environment.rb +6 -0
- data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
- data/test/environments/rails30/db/schema.rb +5 -0
- data/test/environments/rails31/Gemfile +19 -0
- data/test/environments/rails31/Rakefile +9 -0
- data/test/environments/rails31/config/application.rb +18 -0
- data/test/environments/rails31/config/boot.rb +10 -0
- data/test/environments/rails31/config/database.yml +31 -0
- data/test/environments/rails31/config/environment.rb +6 -0
- data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
- data/test/environments/rails31/db/schema.rb +5 -0
- data/test/environments/rails32/Gemfile +25 -0
- data/test/environments/rails32/Rakefile +9 -0
- data/test/environments/rails32/config/application.rb +19 -0
- data/test/environments/rails32/config/boot.rb +10 -0
- data/test/environments/rails32/config/database.yml +31 -0
- data/test/environments/rails32/config/environment.rb +6 -0
- data/test/environments/rails32/db/schema.rb +5 -0
- data/test/environments/rails40/Gemfile +25 -0
- data/test/environments/rails40/Rakefile +9 -0
- data/test/environments/rails40/config/application.rb +18 -0
- data/test/environments/rails40/config/boot.rb +10 -0
- data/test/environments/rails40/config/database.yml +31 -0
- data/test/environments/rails40/config/environment.rb +6 -0
- data/test/environments/rails40/db/schema.rb +5 -0
- data/test/multiverse/lib/multiverse/suite.rb +24 -12
- data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
- data/test/multiverse/suites/curb/curb_test.rb +17 -3
- data/test/multiverse/suites/excon/Envfile +1 -1
- data/test/multiverse/suites/excon/excon_test.rb +18 -2
- data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
- data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
- data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
- data/test/multiverse/suites/rails/ignore_test.rb +48 -0
- data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
- data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
- data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
- data/test/multiverse/suites/typhoeus/Envfile +9 -2
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
- data/test/new_relic/agent/agent/start_test.rb +3 -22
- data/test/new_relic/agent/agent_test.rb +6 -5
- data/test/new_relic/agent/autostart_test.rb +39 -1
- data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
- data/test/new_relic/agent/browser_token_test.rb +52 -0
- data/test/new_relic/agent/busy_calculator_test.rb +1 -1
- data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
- data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
- data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
- data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
- data/test/new_relic/agent/configuration/manager_test.rb +16 -1
- data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
- data/test/new_relic/agent/error_collector_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
- data/test/new_relic/agent/method_tracer_test.rb +2 -2
- data/test/new_relic/agent/new_relic_service_test.rb +5 -49
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
- data/test/new_relic/agent/request_sampler_test.rb +32 -95
- data/test/new_relic/agent/rpm_agent_test.rb +7 -5
- data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
- data/test/new_relic/agent/stats_engine_test.rb +10 -17
- data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
- data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
- data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
- data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
- data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
- data/test/new_relic/agent/transaction/pop_test.rb +0 -16
- data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
- data/test/new_relic/agent/transaction_state_test.rb +75 -0
- data/test/new_relic/agent/transaction_test.rb +15 -0
- data/test/new_relic/agent/transaction_timings_test.rb +81 -0
- data/test/new_relic/agent_test.rb +12 -14
- data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
- data/test/new_relic/control/frameworks/rails_test.rb +1 -2
- data/test/new_relic/control_test.rb +1 -2
- data/test/new_relic/dependency_detection_test.rb +14 -0
- data/test/new_relic/fake_collector.rb +1 -0
- data/test/new_relic/helper_test.rb +7 -2
- data/test/new_relic/http_client_test_cases.rb +33 -1
- data/test/new_relic/local_environment_test.rb +0 -23
- data/test/new_relic/metric_data_test.rb +4 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
- data/test/performance/lib/performance/result.rb +15 -4
- data/test/performance/lib/performance/timer.rb +7 -1
- data/test/performance/script/baselines +102 -0
- data/test/performance/suites/rum_autoinsertion.rb +57 -0
- data/test/rum/basic.result.html +10 -0
- data/test/rum/basic.source.html +10 -0
- data/test/rum/comments1.result.html +24 -0
- data/test/rum/comments1.source.html +24 -0
- data/test/rum/comments2.result.html +24 -0
- data/test/rum/comments2.source.html +24 -0
- data/test/rum/gt_in_quotes1.result.html +27 -0
- data/test/rum/gt_in_quotes1.source.html +27 -0
- data/test/rum/gt_in_quotes2.result.html +24 -0
- data/test/rum/gt_in_quotes2.source.html +24 -0
- data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
- data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
- data/test/rum/gt_in_single_quotes1.result.html +25 -0
- data/test/rum/gt_in_single_quotes1.source.html +25 -0
- data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
- data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
- data/test/rum/incomplete_non_meta_tags.result.html +10 -0
- data/test/rum/incomplete_non_meta_tags.source.html +10 -0
- data/test/rum/no_body.result.html +21 -0
- data/test/rum/no_body.source.html +21 -0
- data/test/rum/no_header.result.html +7 -0
- data/test/rum/no_header.source.html +7 -0
- data/test/rum/no_start_header.result.html +9 -0
- data/test/rum/no_start_header.source.html +9 -0
- data/test/rum/script1.result.html +19 -0
- data/test/rum/script1.source.html +19 -0
- data/test/rum/script2.result.html +17 -0
- data/test/rum/script2.source.html +17 -0
- data/test/rum/x_ua_meta_tag.result.html +10 -0
- data/test/rum/x_ua_meta_tag.source.html +10 -0
- data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
- data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
- data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
- data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
- data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
- data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
- data/test/script/ci.sh +1 -12
- data/test/test_helper.rb +1 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
- metadata +225 -32
- metadata.gz.sig +0 -0
- data/lib/new_relic/agent/configuration/defaults.rb +0 -157
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
- data/lib/new_relic/agent/thread.rb +0 -37
- data/lib/new_relic/agent/thread_profiler.rb +0 -323
- data/lib/new_relic/agent/transaction_info.rb +0 -114
- data/lib/new_relic/command.rb +0 -89
- data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
- data/test/new_relic/agent/thread_profiler_test.rb +0 -586
- data/test/new_relic/agent/thread_test.rb +0 -93
- data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -22,8 +22,6 @@ module NewRelic
|
|
22
22
|
def notice_scope_empty(*args); end
|
23
23
|
end
|
24
24
|
|
25
|
-
BUILDER_KEY = :transaction_sample_builder
|
26
|
-
|
27
25
|
attr_accessor :random_sampling, :sampling_rate
|
28
26
|
attr_accessor :slow_capture_threshold
|
29
27
|
attr_reader :samples, :last_sample, :disabled
|
@@ -178,7 +176,7 @@ module NewRelic
|
|
178
176
|
|
179
177
|
sampler_methods.each{|sym| send(sym, sample) }
|
180
178
|
|
181
|
-
if
|
179
|
+
if sample.force_persist_sample?
|
182
180
|
store_force_persist(sample)
|
183
181
|
end
|
184
182
|
end
|
@@ -301,8 +299,7 @@ module NewRelic
|
|
301
299
|
# Appends a backtrace to a segment if that segment took longer
|
302
300
|
# than the specified duration
|
303
301
|
def append_backtrace(segment, duration)
|
304
|
-
if
|
305
|
-
Thread.current[:capture_deep_tt])
|
302
|
+
if duration >= Agent.config[:'transaction_tracer.stack_trace_threshold']
|
306
303
|
segment[:backtrace] = caller.join("\n")
|
307
304
|
end
|
308
305
|
end
|
@@ -448,19 +445,19 @@ module NewRelic
|
|
448
445
|
if !enabled? || !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
|
449
446
|
clear_builder
|
450
447
|
else
|
451
|
-
|
448
|
+
TransactionState.get.transaction_sample_builder ||= TransactionSampleBuilder.new(time)
|
452
449
|
end
|
453
450
|
end
|
454
451
|
|
455
452
|
# The current thread-local transaction sample builder
|
456
453
|
def builder
|
457
|
-
|
454
|
+
TransactionState.get.transaction_sample_builder
|
458
455
|
end
|
459
456
|
|
460
457
|
# Sets the thread local variable storing the transaction sample
|
461
458
|
# builder to nil to clear it
|
462
459
|
def clear_builder
|
463
|
-
|
460
|
+
TransactionState.get.transaction_sample_builder = nil
|
464
461
|
end
|
465
462
|
|
466
463
|
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'new_relic/agent/browser_token'
|
6
|
+
|
7
|
+
module NewRelic
|
8
|
+
module Agent
|
9
|
+
|
10
|
+
# This is THE location to store thread local information during a transaction
|
11
|
+
# Need a new piece of data? Add a method here, NOT a new thread local variable.
|
12
|
+
class TransactionState
|
13
|
+
|
14
|
+
def self.get
|
15
|
+
state_for(Thread.current)
|
16
|
+
end
|
17
|
+
|
18
|
+
# This method should only be used by TransactionState for access to the
|
19
|
+
# current thread's state or to provide read-only accessors for other threads
|
20
|
+
#
|
21
|
+
# If ever exposed, this requires additional synchronization
|
22
|
+
def self.state_for(thread)
|
23
|
+
thread[:newrelic_transaction_state] ||= TransactionState.new
|
24
|
+
end
|
25
|
+
private_class_method :state_for
|
26
|
+
|
27
|
+
def self.clear
|
28
|
+
Thread.current[:newrelic_transaction_state] = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# This starts the timer for the transaction.
|
32
|
+
def self.reset(request=nil)
|
33
|
+
self.get.reset(request)
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@stats_scope_stack = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def reset(request)
|
41
|
+
# We almost always want to use the transaction time, but in case it's
|
42
|
+
# not available, we track the last reset. No accessor, as only the
|
43
|
+
# TransactionState class should use it.
|
44
|
+
@last_reset_time = Time.now
|
45
|
+
|
46
|
+
@transaction = Transaction.current
|
47
|
+
@timings = nil
|
48
|
+
|
49
|
+
@request = request
|
50
|
+
@request_token = BrowserToken.get_token(request)
|
51
|
+
@request_guid = ""
|
52
|
+
@request_ignore_enduser = false
|
53
|
+
end
|
54
|
+
|
55
|
+
def timings
|
56
|
+
@timings ||= TransactionTimings.new(transaction_queue_time, transaction_start_time, transaction_name)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Cross app tracing
|
60
|
+
# Because we need values from headers before the transaction actually starts
|
61
|
+
attr_accessor :client_cross_app_id, :referring_transaction_info
|
62
|
+
|
63
|
+
# Request data
|
64
|
+
attr_accessor :request, :request_token, :request_guid, :request_ignore_enduser
|
65
|
+
|
66
|
+
# Current transaction stack and sample building
|
67
|
+
attr_accessor :transaction, :transaction_sample_builder
|
68
|
+
attr_writer :current_transaction_stack
|
69
|
+
|
70
|
+
# Returns and initializes the transaction stack if necessary
|
71
|
+
#
|
72
|
+
# We don't default in the initializer so non-transaction threads retain
|
73
|
+
# a nil stack, and methods in this class use has_current_transction?
|
74
|
+
# instead of this accessor to see if we're a transaction thread or not
|
75
|
+
def current_transaction_stack
|
76
|
+
@current_transaction_stack ||= []
|
77
|
+
end
|
78
|
+
|
79
|
+
def transaction_start_time
|
80
|
+
if transaction.nil?
|
81
|
+
@last_reset_time
|
82
|
+
else
|
83
|
+
transaction.start_time
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def transaction_queue_time
|
88
|
+
transaction.nil? ? 0.0 : transaction.queue_time
|
89
|
+
end
|
90
|
+
|
91
|
+
def transaction_name
|
92
|
+
transaction.nil? ? nil : transaction.name
|
93
|
+
end
|
94
|
+
|
95
|
+
def transaction_noticed_error_ids
|
96
|
+
transaction.nil? ? [] : transaction.noticed_error_ids
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.in_background_transaction?(thread)
|
100
|
+
state_for(thread).in_background_transaction?
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.in_request_transaction?(thread)
|
104
|
+
state_for(thread).in_request_transaction?
|
105
|
+
end
|
106
|
+
|
107
|
+
def in_background_transaction?
|
108
|
+
!current_transaction.nil? && current_transaction.request.nil?
|
109
|
+
end
|
110
|
+
|
111
|
+
def in_request_transaction?
|
112
|
+
!current_transaction.nil? && !current_transaction.request.nil?
|
113
|
+
end
|
114
|
+
|
115
|
+
def current_transaction
|
116
|
+
current_transaction_stack.last if has_current_transaction?
|
117
|
+
end
|
118
|
+
|
119
|
+
def has_current_transaction?
|
120
|
+
!@current_transaction_stack.nil?
|
121
|
+
end
|
122
|
+
|
123
|
+
# Execution tracing on current thread
|
124
|
+
attr_accessor :untraced
|
125
|
+
|
126
|
+
def push_traced(should_trace)
|
127
|
+
@untraced ||= []
|
128
|
+
@untraced << should_trace
|
129
|
+
end
|
130
|
+
|
131
|
+
def pop_traced
|
132
|
+
@untraced.pop if @untraced
|
133
|
+
end
|
134
|
+
|
135
|
+
def is_traced?
|
136
|
+
@untraced.nil? || @untraced.last != false
|
137
|
+
end
|
138
|
+
|
139
|
+
# TT's and SQL
|
140
|
+
attr_accessor :record_tt, :record_sql
|
141
|
+
|
142
|
+
def is_transaction_traced?
|
143
|
+
@record_tt != false
|
144
|
+
end
|
145
|
+
|
146
|
+
def is_sql_recorded?
|
147
|
+
@record_sql != false
|
148
|
+
end
|
149
|
+
|
150
|
+
# Busy calculator
|
151
|
+
attr_accessor :busy_entries
|
152
|
+
|
153
|
+
# Sql Sampler Transaction Data
|
154
|
+
attr_accessor :sql_sampler_transaction_data
|
155
|
+
|
156
|
+
# Scope stack tracking from NewRelic::StatsEngine::Transactions
|
157
|
+
# Should not be nil--this class manages its initialization and resetting
|
158
|
+
attr_accessor :stats_scope_stack
|
159
|
+
|
160
|
+
def clear_stats_scope_stack
|
161
|
+
@stats_scope_stack = []
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
module NewRelic
|
6
|
+
module Agent
|
7
|
+
class TransactionTimings
|
8
|
+
|
9
|
+
def initialize(queue_time_in_seconds, start_time_in_seconds, transaction_name)
|
10
|
+
@now = Time.now.to_f
|
11
|
+
@queue_time_in_seconds = clamp_to_positive(queue_time_in_seconds.to_f)
|
12
|
+
@start_time_in_seconds = clamp_to_positive(start_time_in_seconds.to_f)
|
13
|
+
|
14
|
+
@transaction_name = transaction_name
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :transaction_name,
|
18
|
+
:start_time_in_seconds, :queue_time_in_seconds
|
19
|
+
|
20
|
+
def start_time_as_time
|
21
|
+
Time.at(@start_time_in_seconds)
|
22
|
+
end
|
23
|
+
|
24
|
+
def start_time_in_millis
|
25
|
+
convert_to_milliseconds(@start_time_in_seconds)
|
26
|
+
end
|
27
|
+
|
28
|
+
def queue_time_in_millis
|
29
|
+
convert_to_milliseconds(queue_time_in_seconds)
|
30
|
+
end
|
31
|
+
|
32
|
+
def app_time_in_millis
|
33
|
+
convert_to_milliseconds(app_time_in_seconds)
|
34
|
+
end
|
35
|
+
|
36
|
+
def app_time_in_seconds
|
37
|
+
@now - @start_time_in_seconds
|
38
|
+
end
|
39
|
+
|
40
|
+
# Helpers
|
41
|
+
|
42
|
+
def convert_to_milliseconds(value_in_seconds)
|
43
|
+
clamp_to_positive((value_in_seconds.to_f * 1000.0).round)
|
44
|
+
end
|
45
|
+
|
46
|
+
def clamp_to_positive(value)
|
47
|
+
return 0.0 if value < 0.0
|
48
|
+
value
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
# Run the command given by the first argument. Right
|
8
|
+
# now all we have is deployments. We hope to have other
|
9
|
+
# kinds of events here later.
|
10
|
+
$LOAD_PATH << "#{File.dirname(__FILE__)}/.."
|
11
|
+
module NewRelic
|
12
|
+
module Cli
|
13
|
+
class Command
|
14
|
+
attr_accessor :leftover
|
15
|
+
# Capture a failure to execute the command.
|
16
|
+
class CommandFailure < StandardError
|
17
|
+
attr_reader :options
|
18
|
+
def initialize message, opt_parser=nil
|
19
|
+
super message
|
20
|
+
@options = opt_parser
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def info(message)
|
25
|
+
STDOUT.puts message
|
26
|
+
end
|
27
|
+
|
28
|
+
def err(message)
|
29
|
+
STDERR.puts message
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(command_line_args)
|
33
|
+
if Hash === command_line_args
|
34
|
+
# command line args is an options hash
|
35
|
+
command_line_args.each do | key, value |
|
36
|
+
instance_variable_set "@#{key}", value.to_s if value
|
37
|
+
end
|
38
|
+
else
|
39
|
+
# parse command line args. Throw an exception on a bad arg.
|
40
|
+
@options = options do | opts |
|
41
|
+
opts.on("-h", "Show this help") { raise CommandFailure, opts.to_s }
|
42
|
+
end
|
43
|
+
@leftover = @options.parse(command_line_args)
|
44
|
+
end
|
45
|
+
rescue OptionParser::ParseError => e
|
46
|
+
raise CommandFailure.new(e.message, @options)
|
47
|
+
end
|
48
|
+
|
49
|
+
@commands = []
|
50
|
+
def self.inherited(subclass)
|
51
|
+
@commands << subclass
|
52
|
+
end
|
53
|
+
|
54
|
+
cmds = File.expand_path(File.join(File.dirname(__FILE__), '*.rb'))
|
55
|
+
Dir[cmds].each{|command| require command }
|
56
|
+
|
57
|
+
def self.run
|
58
|
+
|
59
|
+
@command_names = @commands.map{ |c| c.command }
|
60
|
+
|
61
|
+
extra = []
|
62
|
+
options = ARGV.options do |opts|
|
63
|
+
script_name = File.basename($0)
|
64
|
+
if script_name =~ /newrelic_cmd$/
|
65
|
+
$stdout.puts "warning: the 'newrelic_cmd' script has been renamed 'newrelic'"
|
66
|
+
script_name = 'newrelic'
|
67
|
+
end
|
68
|
+
opts.banner = "Usage: #{script_name} [ #{ @command_names.join(" | ")} ] [options]"
|
69
|
+
opts.separator "use '#{script_name} <command> -h' to see detailed command options"
|
70
|
+
opts
|
71
|
+
end
|
72
|
+
extra = options.order!
|
73
|
+
command = extra.shift
|
74
|
+
# just make it a little easier on them
|
75
|
+
command = 'deployments' if command =~ /deploy/
|
76
|
+
if command.nil?
|
77
|
+
STDERR.puts options
|
78
|
+
elsif !@command_names.include?(command)
|
79
|
+
STDERR.puts "Unrecognized command: #{command}"
|
80
|
+
STDERR.puts options
|
81
|
+
else
|
82
|
+
command_class = @commands.find{ |c| c.command == command}
|
83
|
+
command_class.new(extra).run
|
84
|
+
end
|
85
|
+
rescue OptionParser::InvalidOption => e
|
86
|
+
raise NewRelic::Cli::Command::CommandFailure, e.message
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -14,7 +14,7 @@ require 'rexml/document'
|
|
14
14
|
# it won't load it twice, something it does when run inside a test
|
15
15
|
require 'new_relic/control' unless defined? NewRelic::Control
|
16
16
|
|
17
|
-
class NewRelic::
|
17
|
+
class NewRelic::Cli::Deployments < NewRelic::Cli::Command
|
18
18
|
attr_reader :control
|
19
19
|
def self.command; "deployments"; end
|
20
20
|
|
@@ -23,7 +23,7 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
23
23
|
# When command_line_args is a hash, we are invoking directly and
|
24
24
|
# it's treated as an options with optional string values for
|
25
25
|
# :user, :description, :appname, :revision, :environment,
|
26
|
-
# and :changes.
|
26
|
+
# :license_key, and :changes.
|
27
27
|
#
|
28
28
|
# Will throw CommandFailed exception if there's any error.
|
29
29
|
#
|
@@ -33,8 +33,11 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
33
33
|
@description ||= @leftover && @leftover.join(" ")
|
34
34
|
@user ||= ENV['USER']
|
35
35
|
control.env = @environment if @environment
|
36
|
+
|
36
37
|
load_yaml_from_env(control.env)
|
37
38
|
@appname ||= NewRelic::Agent.config.app_names[0] || control.env || 'development'
|
39
|
+
@license_key ||= NewRelic::Agent.config[:license_key]
|
40
|
+
|
38
41
|
setup_logging(control.env)
|
39
42
|
end
|
40
43
|
|
@@ -68,11 +71,10 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
68
71
|
|
69
72
|
uri = "/deployments.xml"
|
70
73
|
|
71
|
-
if
|
72
|
-
NewRelic::Agent.config[:license_key].empty?
|
74
|
+
if @license_key.nil? || @license_key.empty?
|
73
75
|
raise "license_key was not set in newrelic.yml for #{control.env}"
|
74
76
|
end
|
75
|
-
request = Net::HTTP::Post.new(uri, {'x-license-key' =>
|
77
|
+
request = Net::HTTP::Post.new(uri, {'x-license-key' => @license_key})
|
76
78
|
request.content_type = "application/octet-stream"
|
77
79
|
|
78
80
|
request.set_form_data(create_params)
|
@@ -83,18 +85,18 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
83
85
|
info "Recorded deployment to '#{@appname}' (#{@description || Time.now })"
|
84
86
|
else
|
85
87
|
err_string = REXML::Document.new(response.body).elements['errors/error'].map(&:to_s).join("; ") rescue response.message
|
86
|
-
raise NewRelic::Command::CommandFailure, "Deployment not recorded: #{err_string}"
|
88
|
+
raise NewRelic::Cli::Command::CommandFailure, "Deployment not recorded: #{err_string}"
|
87
89
|
end
|
88
90
|
rescue SystemCallError, SocketError => e
|
89
91
|
# These include Errno connection errors
|
90
92
|
err_string = "Transient error attempting to connect to #{control.api_server} (#{e})"
|
91
|
-
raise NewRelic::Command::CommandFailure.new(err_string)
|
92
|
-
rescue NewRelic::Command::CommandFailure
|
93
|
+
raise NewRelic::Cli::Command::CommandFailure.new(err_string)
|
94
|
+
rescue NewRelic::Cli::Command::CommandFailure
|
93
95
|
raise
|
94
96
|
rescue => e
|
95
97
|
err "Unexpected error attempting to connect to #{control.api_server}"
|
96
98
|
info "#{e}: #{e.backtrace.join("\n ")}"
|
97
|
-
raise NewRelic::Command::CommandFailure.new(e.to_s)
|
99
|
+
raise NewRelic::Cli::Command::CommandFailure.new(e.to_s)
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
@@ -114,6 +116,8 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
114
116
|
"Default: #{@user || '<none>'}") { | u | @user = u }
|
115
117
|
o.on("-r", "--revision=REV", String,
|
116
118
|
"Specify the revision being deployed") { | r | @revision = r }
|
119
|
+
o.on("-l", "--license-key=KEY", String,
|
120
|
+
"Specify the license key of the account for the app being deployed") { | l | @license_key = l }
|
117
121
|
o.on("-c", "--changes",
|
118
122
|
"Read in a change log from the standard input") { @changelog = STDIN.read }
|
119
123
|
yield o if block_given?
|
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
require 'new_relic/version'
|
7
7
|
require 'erb'
|
8
8
|
|
9
|
-
class NewRelic::
|
9
|
+
class NewRelic::Cli::Install < NewRelic::Cli::Command
|
10
10
|
|
11
11
|
NO_LICENSE_KEY = "<PASTE LICENSE KEY HERE>"
|
12
12
|
|
@@ -40,7 +40,7 @@ class NewRelic::Command::Install < NewRelic::Command
|
|
40
40
|
def run
|
41
41
|
dest_file = File.expand_path(@dest_dir + "/newrelic.yml")
|
42
42
|
if File.exist?(dest_file)
|
43
|
-
raise NewRelic::Command::CommandFailure, "newrelic.yml file already exists. Move it out of the way."
|
43
|
+
raise NewRelic::Cli::Command::CommandFailure, "newrelic.yml file already exists. Move it out of the way."
|
44
44
|
end
|
45
45
|
File.open(dest_file, 'w') { | out | out.puts(content) }
|
46
46
|
|