newrelic_rpm 3.10.0.279 → 3.11.0.283
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +61 -0
- data/lib/new_relic/agent.rb +14 -8
- data/lib/new_relic/agent/agent.rb +43 -28
- data/lib/new_relic/agent/agent_logger.rb +21 -20
- data/lib/new_relic/agent/configuration/default_source.rb +31 -1
- data/lib/new_relic/agent/database.rb +2 -1
- data/lib/new_relic/agent/datastores.rb +177 -0
- data/lib/new_relic/agent/datastores/metric_helper.rb +85 -0
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +11 -20
- data/lib/new_relic/agent/deprecator.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +20 -35
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +116 -57
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -20
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +104 -172
- data/lib/new_relic/agent/instrumentation/memcache.rb +104 -52
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +9 -0
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +15 -2
- data/lib/new_relic/agent/instrumentation/mongo.rb +5 -18
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +36 -0
- data/lib/new_relic/agent/new_relic_service.rb +4 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -17
- data/lib/new_relic/agent/threading/backtrace_service.rb +28 -5
- data/lib/new_relic/agent/transaction.rb +63 -34
- data/lib/new_relic/agent/transaction_event_aggregator.rb +0 -4
- data/lib/new_relic/agent/transaction_sampler.rb +11 -5
- data/lib/new_relic/rack/error_collector.rb +0 -1
- data/lib/new_relic/version.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +28 -56
- data/lib/sequel/plugins/newrelic_instrumentation.rb +28 -45
- data/newrelic_rpm.gemspec +0 -7
- data/test/agent_helper.rb +35 -16
- data/test/environments/rails31/Gemfile +1 -0
- data/test/environments/rails32/Gemfile +1 -0
- data/test/helpers/mongo_metric_builder.rb +2 -3
- data/test/multiverse/lib/multiverse/output_collector.rb +24 -9
- data/test/multiverse/lib/multiverse/suite.rb +5 -0
- data/test/multiverse/suites/active_record/Envfile +6 -4
- data/test/multiverse/suites/active_record/active_record_test.rb +32 -73
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +0 -1
- data/test/multiverse/suites/activemerchant/activemerchant_test.rb +0 -3
- data/test/multiverse/suites/agent_only/agent_run_id_handling_test.rb +0 -1
- data/test/multiverse/suites/agent_only/audit_log_test.rb +0 -1
- data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +0 -2
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -1
- data/test/multiverse/suites/agent_only/custom_analytics_events_test.rb +0 -2
- data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +0 -1
- data/test/multiverse/suites/agent_only/encoding_handling_test.rb +0 -2
- data/test/multiverse/suites/agent_only/exclusive_time_test.rb +0 -2
- data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +0 -1
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +0 -1
- data/test/multiverse/suites/agent_only/keepalive_test.rb +0 -1
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +54 -9
- data/test/multiverse/suites/agent_only/labels_test.rb +0 -2
- data/test/multiverse/suites/agent_only/logging_test.rb +0 -1
- data/test/multiverse/suites/agent_only/marshaling_test.rb +0 -1
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +0 -2
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +5 -7
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +0 -1
- data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +0 -2
- data/test/multiverse/suites/agent_only/ssl_test.rb +0 -2
- data/test/multiverse/suites/agent_only/synthetics_test.rb +0 -1
- data/test/multiverse/suites/agent_only/testing_app.rb +21 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +1 -2
- data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +0 -2
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +0 -1
- data/test/multiverse/suites/agent_only/xray_sessions_test.rb +69 -34
- data/test/multiverse/suites/capistrano/deployment_test.rb +0 -1
- data/test/multiverse/suites/capistrano2/deployment_test.rb +0 -1
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +0 -2
- data/test/multiverse/suites/curb/curb_test.rb +0 -2
- data/test/multiverse/suites/datamapper/Envfile +26 -3
- data/test/multiverse/suites/datamapper/config/newrelic.yml +1 -0
- data/test/multiverse/suites/datamapper/datamapper_test.rb +271 -37
- data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +0 -1
- data/test/multiverse/suites/delayed_job/Envfile +31 -8
- data/test/multiverse/suites/delayed_job/delayed_job_sampler_test.rb +0 -3
- data/test/multiverse/suites/delayed_job/unsupported_backend_test.rb +0 -3
- data/test/multiverse/suites/excon/excon_test.rb +0 -2
- data/test/multiverse/suites/grape/grape_test.rb +0 -3
- data/test/multiverse/suites/grape/grape_versioning_test.rb +0 -3
- data/test/multiverse/suites/grape/unsupported_version_test.rb +0 -3
- data/test/multiverse/suites/high_security/high_security_test.rb +0 -1
- data/test/multiverse/suites/httpclient/httpclient_test.rb +0 -2
- data/test/multiverse/suites/json/json_test.rb +0 -1
- data/test/multiverse/suites/marshalling/marshalling_test.rb +0 -1
- data/test/multiverse/suites/memcached/Envfile +52 -0
- data/test/multiverse/suites/memcached/dalli_test.rb +89 -0
- data/test/multiverse/suites/memcached/memcache_client_test.rb +25 -0
- data/test/multiverse/suites/memcached/memcache_test_cases.rb +302 -0
- data/test/multiverse/suites/memcached/memcached_test.rb +159 -0
- data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +26 -17
- data/test/multiverse/suites/mongo/mongo_connection_test.rb +0 -1
- data/test/multiverse/suites/mongo/mongo_instrumentation_test.rb +0 -1
- data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +0 -1
- data/test/multiverse/suites/net_http/net_http_test.rb +0 -2
- data/test/multiverse/suites/padrino/padrino_test.rb +0 -3
- data/test/multiverse/suites/rack/http_response_code_test.rb +0 -1
- data/test/multiverse/suites/rack/nested_non_rack_app_test.rb +1 -1
- data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +12 -12
- data/test/multiverse/suites/rack/rack_cascade_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_env_mutation_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_parameter_filtering_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_unsupported_version_test.rb +0 -2
- data/test/multiverse/suites/rack/url_map_test.rb +3 -2
- data/test/multiverse/suites/rails/Envfile +3 -0
- data/test/multiverse/suites/rails/activejob_test.rb +0 -1
- data/test/multiverse/suites/rails/app.rb +0 -1
- data/test/multiverse/suites/rails/parameter_capture_test.rb +13 -0
- data/test/multiverse/suites/rails/rails3_app/app_rails3_plus.rb +5 -0
- data/test/multiverse/suites/rails/transaction_ignoring_test.rb +0 -2
- data/test/multiverse/suites/resque/instrumentation_test.rb +0 -2
- data/test/multiverse/suites/resque/resque_marshalling_test.rb +0 -1
- data/test/multiverse/suites/sequel/sequel_extension_test.rb +135 -0
- data/test/multiverse/suites/sequel/sequel_helpers.rb +62 -0
- data/test/multiverse/suites/sequel/sequel_plugin_test.rb +230 -0
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +0 -2
- data/test/multiverse/suites/sinatra/ignoring_test.rb +0 -2
- data/test/multiverse/suites/sinatra/nested_middleware_test.rb +0 -2
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +0 -1
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +0 -2
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +14 -12
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +0 -1
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +0 -2
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +0 -2
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +0 -2
- data/test/multiverse/suites/yajl/yajl_test.rb +0 -1
- data/test/new_relic/agent/agent/start_test.rb +2 -2
- data/test/new_relic/agent/agent_logger_test.rb +6 -3
- data/test/new_relic/agent/datastores/metric_helper_test.rb +61 -0
- data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +20 -21
- data/test/new_relic/agent/datastores_test.rb +195 -0
- data/test/new_relic/agent/deprecator_test.rb +52 -0
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +20 -26
- data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +58 -53
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +7 -20
- data/test/new_relic/agent/instrumentation/middleware_proxy_test.rb +19 -0
- data/test/new_relic/agent/instrumentation/sequel_helper_test.rb +36 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +1 -0
- data/test/new_relic/agent/method_tracer_test.rb +3 -4
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
- data/test/new_relic/agent/threading/backtrace_service_test.rb +29 -4
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +0 -4
- data/test/new_relic/agent/transaction_test.rb +100 -2
- data/test/new_relic/agent_test.rb +3 -3
- data/test/new_relic/http_client_test_cases.rb +0 -1
- data/test/new_relic/multiverse_helpers.rb +7 -0
- data/test/new_relic/transaction_ignoring_test_cases.rb +0 -2
- data/test/new_relic/transaction_sample_test.rb +11 -2
- data/test/performance/README.md +37 -17
- data/test/performance/lib/performance.rb +1 -0
- data/test/performance/lib/performance/baseline_compare_reporter.rb +11 -7
- data/test/performance/lib/performance/console_reporter.rb +29 -5
- data/test/performance/lib/performance/formatting_helpers.rb +22 -0
- data/test/performance/lib/performance/instrumentation/stackprof.rb +11 -1
- data/test/performance/lib/performance/result.rb +17 -6
- data/test/performance/lib/performance/runner.rb +7 -3
- data/test/performance/lib/performance/test_case.rb +89 -21
- data/test/performance/script/runner +13 -1
- data/test/performance/suites/active_record.rb +47 -0
- data/test/performance/suites/config.rb +4 -48
- data/test/performance/suites/marshalling.rb +20 -30
- data/test/performance/suites/queue_time.rb +1 -1
- data/test/performance/suites/rack_middleware.rb +1 -1
- data/test/performance/suites/rum_autoinsertion.rb +1 -1
- data/test/performance/suites/sql_obfuscation.rb +2 -2
- data/test/performance/suites/startup.rb +1 -1
- data/test/performance/suites/stats_hash.rb +7 -11
- data/test/performance/suites/thread_profiling.rb +20 -25
- data/test/performance/suites/trace_execution_scoped.rb +2 -2
- data/test/performance/suites/transaction_tracing.rb +4 -2
- data/test/test_helper.rb +5 -1
- metadata +53 -100
- data.tar.gz.sig +0 -0
- data/gem-public_cert.pem +0 -20
- data/lib/new_relic/agent/datastores/mongo/metric_generator.rb +0 -33
- data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +0 -289
- data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +0 -69
- data/test/new_relic/agent/memcache_instrumentation_test.rb +0 -155
- metadata.gz.sig +0 -2
@@ -2,186 +2,147 @@
|
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
|
-
## NewRelic instrumentation for DataMapper
|
6
|
-
#
|
7
|
-
# Instrumenting DM has different key challenges versus AR:
|
8
|
-
#
|
9
|
-
# 1. The hooking of SQL logging in DM is decoupled from any knowledge of the
|
10
|
-
# Model#method that invoked it. But on the positive side, the duration is
|
11
|
-
# already calculated for you (and it happens inside the C-based DO code, so
|
12
|
-
# it's faster than a Ruby equivalent).
|
13
|
-
#
|
14
|
-
# 2. There are a lot more entry points that need to be hooked in order to
|
15
|
-
# understand call flow: DM::Model (model class) vs. DM::Resource (model
|
16
|
-
# instance) vs. DM::Collection (collection of model instances). And
|
17
|
-
# others.
|
18
|
-
#
|
19
|
-
# 3. Strategic Eager Loading (SEL) combined with separately-grouped
|
20
|
-
# lazy-loaded attributes presents a unique problem for tying resulting
|
21
|
-
# SEL-invoked SQL calls to their proper scope.
|
22
|
-
#
|
23
|
-
# NOTE: On using "Database" versus "ActiveRecord" as base metric name
|
24
|
-
#
|
25
|
-
# Using "Database" as the metric name base seems to properly identify methods
|
26
|
-
# as being DB-related in call graphs, but certain New Relic views that show
|
27
|
-
# aggregations of DB CPM, etc still seem to rely solely on "ActiveRecord"
|
28
|
-
# being the base name, thus AFAICT "Database" calls to this are lost. (Though
|
29
|
-
# I haven't yet tested "Database/SQL/{find/save/destroy/all}" yet, as it seems
|
30
|
-
# like an intuitively good name to use.)
|
31
|
-
#
|
32
|
-
# So far I think these are the rules:
|
33
|
-
#
|
34
|
-
# - ActiveRecord/{find/save/destroy} populates "Database Throughput" and
|
35
|
-
# "Database Response Time" in the Database tab. [non-scoped]
|
36
|
-
#
|
37
|
-
# - ActiveRecord/all populates the main Overview tab of DB time. (still
|
38
|
-
# unsure about this one). [non-scoped]
|
39
|
-
#
|
40
|
-
# These metrics are represented as :push_scope => false or included as the
|
41
|
-
# non-first metric in trace_execution_scoped() (docs say only first counts
|
42
|
-
# towards scope) so they don't show up ine normal call graph/trace.
|
43
|
-
|
44
5
|
DependencyDetection.defer do
|
45
|
-
|
46
|
-
|
47
|
-
depends_on do
|
48
|
-
defined?(::DataMapper)
|
49
|
-
end
|
6
|
+
named :data_mapper
|
50
7
|
|
51
8
|
depends_on do
|
52
|
-
defined?(DataMapper
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
defined?(DataMapper::Resource)
|
57
|
-
end
|
58
|
-
|
59
|
-
depends_on do
|
60
|
-
defined?(DataMapper::Collection)
|
9
|
+
defined?(::DataMapper) &&
|
10
|
+
defined?(::DataMapper::Model) &&
|
11
|
+
defined?(::DataMapper::Resource) &&
|
12
|
+
defined?(::DataMapper::Collection)
|
61
13
|
end
|
62
14
|
|
63
15
|
executes do
|
64
16
|
::NewRelic::Agent.logger.info 'Installing DataMapper instrumentation'
|
17
|
+
require 'new_relic/agent/datastores/metric_helper'
|
65
18
|
end
|
66
19
|
|
67
20
|
executes do
|
68
|
-
DataMapper::Model
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
|
73
|
-
|
74
|
-
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
75
|
-
add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
|
76
|
-
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
77
|
-
add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
|
78
|
-
add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
|
79
|
-
add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
|
80
|
-
|
81
|
-
# For dm-aggregates and partial dm-ar-finders support:
|
82
|
-
for method in [ :aggregate, :find, :find_by_sql ] do
|
83
|
-
next unless method_defined? method
|
84
|
-
add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
|
85
|
-
end
|
21
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :get
|
22
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :first
|
23
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :last
|
24
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :all
|
86
25
|
|
87
|
-
|
26
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :create
|
27
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :create!
|
28
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :update
|
29
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :update!
|
30
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :destroy
|
31
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :destroy!
|
32
|
+
|
33
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :aggregate
|
34
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :find
|
35
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Model, :find_by_sql
|
88
36
|
end
|
89
37
|
|
90
38
|
executes do
|
91
|
-
DataMapper::Resource
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
add_method_tracer :destroy!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
|
98
|
-
|
99
|
-
end
|
39
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Resource, :update
|
40
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Resource, :update!
|
41
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Resource, :save
|
42
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Resource, :save!
|
43
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Resource, :destroy
|
44
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Resource, :destroy!
|
100
45
|
end
|
101
46
|
|
102
47
|
executes do
|
103
|
-
DataMapper::Collection
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
|
108
|
-
add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
|
109
|
-
|
110
|
-
add_method_tracer :lazy_load, 'ActiveRecord/#{self.name}/lazy_load'
|
111
|
-
|
112
|
-
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
113
|
-
add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
|
114
|
-
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
115
|
-
add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
|
116
|
-
add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
|
117
|
-
add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
|
118
|
-
|
119
|
-
# For dm-aggregates support:
|
120
|
-
for method in [ :aggregate ] do
|
121
|
-
next unless method_defined? method
|
122
|
-
add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
|
123
|
-
end
|
48
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :get
|
49
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :first
|
50
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :last
|
51
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :all
|
124
52
|
|
125
|
-
|
126
|
-
end
|
127
|
-
end
|
53
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :lazy_load
|
128
54
|
|
129
|
-
|
55
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :create
|
56
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :create!
|
57
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :update
|
58
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :update!
|
59
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :destroy
|
60
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :destroy!
|
130
61
|
|
131
|
-
|
132
|
-
defined?(DataMapper) && defined?(DataMapper::Adapters) && defined?(DataMapper::Adapters::DataObjectsAdapter)
|
62
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Collection, :aggregate
|
133
63
|
end
|
134
64
|
|
135
65
|
executes do
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
add_method_tracer :select, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/select'
|
142
|
-
add_method_tracer :execute, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/execute'
|
143
|
-
|
66
|
+
# Catch direct SQL calls that bypass CRUD
|
67
|
+
if defined?(::DataMapper::Adapters::DataObjectsAdapter)
|
68
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Adapters::DataObjectsAdapter, :select, true
|
69
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Adapters::DataObjectsAdapter, :execute, true
|
144
70
|
end
|
145
71
|
end
|
146
|
-
end
|
147
72
|
|
148
|
-
DependencyDetection.defer do
|
149
|
-
|
150
|
-
depends_on do
|
151
|
-
defined?(DataMapper) && defined?(DataMapper::Validations) && defined?(DataMapper::Validations::ClassMethods)
|
152
|
-
end
|
153
|
-
|
154
|
-
# DM::Validations overrides Model#create, but currently in a way that makes it
|
155
|
-
# impossible to instrument from one place. I've got a patch pending inclusion
|
156
|
-
# to make it instrumentable by putting the create method inside ClassMethods.
|
157
|
-
# This will pick it up if/when that patch is accepted.
|
158
73
|
executes do
|
159
|
-
|
160
|
-
|
161
|
-
|
74
|
+
# DM::Validations overrides Model#create, so we patch it here as well
|
75
|
+
if defined?(::DataMapper::Validations::ClassMethods)
|
76
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Validations::ClassMethods, :create
|
162
77
|
end
|
163
78
|
end
|
164
|
-
end
|
165
|
-
|
166
|
-
DependencyDetection.defer do
|
167
79
|
|
168
|
-
|
169
|
-
|
80
|
+
executes do
|
81
|
+
# DM::Transaction calls commit() twice, so potentially shows up twice.
|
82
|
+
if defined?(::DataMapper::Transaction)
|
83
|
+
NewRelic::Agent::DataMapperTracing.add_tracer ::DataMapper::Transaction, :commit, true
|
84
|
+
end
|
170
85
|
end
|
171
86
|
|
172
|
-
# NOTE: DM::Transaction basically calls commit() twice, so as-is it will show
|
173
|
-
# up in traces twice -- second time subordinate to the first's scope. Works
|
174
|
-
# well enough.
|
175
87
|
executes do
|
176
|
-
|
177
|
-
|
88
|
+
if defined?(::DataObjects::Connection)
|
89
|
+
::DataObjects::Connection.class_eval do
|
90
|
+
include ::NewRelic::Agent::Instrumentation::DataMapperInstrumentation
|
91
|
+
end
|
178
92
|
end
|
179
93
|
end
|
180
94
|
end
|
181
95
|
|
182
|
-
|
183
96
|
module NewRelic
|
184
97
|
module Agent
|
98
|
+
module DataMapperTracing
|
99
|
+
def self.add_tracer(clazz, method_name, operation_only = false)
|
100
|
+
clazz.class_eval do
|
101
|
+
if method_defined?(method_name) || private_method_defined?(method_name)
|
102
|
+
define_method("#{method_name}_with_newrelic",
|
103
|
+
NewRelic::Agent::DataMapperTracing.method_body(clazz, method_name, operation_only))
|
104
|
+
|
105
|
+
alias_method "#{method_name}_without_newrelic", method_name
|
106
|
+
alias_method method_name, "#{method_name}_with_newrelic"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
DATA_MAPPER = "DataMapper".freeze
|
112
|
+
|
113
|
+
def self.method_body(clazz, method_name, operation_only)
|
114
|
+
use_model_name = NewRelic::Helper.instance_methods_include?(clazz, :model)
|
115
|
+
metric_operation = method_name.to_s.gsub(/[!?]/, "")
|
116
|
+
|
117
|
+
Proc.new do |*args, &blk|
|
118
|
+
begin
|
119
|
+
if operation_only
|
120
|
+
# Used by direct SQL, like ::DataMapper::Adapters::DataObjectsAdapter#select
|
121
|
+
name = nil
|
122
|
+
elsif use_model_name
|
123
|
+
# Used by ::DataMapper::Collection to get contained model name
|
124
|
+
name = self.model.name
|
125
|
+
elsif self.is_a?(Class)
|
126
|
+
# Used by class-style access, like Model.first()
|
127
|
+
name = self.name
|
128
|
+
else
|
129
|
+
# Used by instance-style access, like model.update(attr: "new")
|
130
|
+
name = self.class.name
|
131
|
+
end
|
132
|
+
|
133
|
+
metrics = NewRelic::Agent::Datastores::MetricHelper.metrics_for(
|
134
|
+
DATA_MAPPER,
|
135
|
+
metric_operation,
|
136
|
+
name)
|
137
|
+
|
138
|
+
NewRelic::Agent::MethodTracer.trace_execution_scoped(metrics) do
|
139
|
+
self.send("#{method_name}_without_newrelic", *args, &blk)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
185
146
|
module Instrumentation
|
186
147
|
module DataMapperInstrumentation
|
187
148
|
# Unlike in AR, log is called in DM after the query actually ran,
|
@@ -194,42 +155,13 @@ module NewRelic
|
|
194
155
|
def log(msg) #THREAD_LOCAL_ACCESS
|
195
156
|
state = NewRelic::Agent::TransactionState.tl_get
|
196
157
|
return unless state.is_execution_traced?
|
197
|
-
return unless operation = case NewRelic::Helper.correctly_encoded(msg.query)
|
198
|
-
when /^\s*select/i then 'find'
|
199
|
-
when /^\s*(update|insert)/i then 'save'
|
200
|
-
when /^\s*delete/i then 'destroy'
|
201
|
-
else nil
|
202
|
-
end
|
203
|
-
|
204
|
-
# FYI: self.to_s will yield connection URI string.
|
205
|
-
duration = msg.duration / 1000000.0
|
206
158
|
|
207
|
-
|
159
|
+
duration = msg.duration / 1000000.0
|
208
160
|
NewRelic::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration, state)
|
209
|
-
|
210
|
-
# Record query duration associated with each of the desired metrics.
|
211
|
-
metric = "ActiveRecord/#{operation}"
|
212
|
-
rollup_metrics = ActiveRecordHelper.rollup_metrics_for(metric)
|
213
|
-
metrics = [metric] + rollup_metrics
|
214
|
-
NewRelic::Agent.instance.stats_engine.tl_record_unscoped_metrics(metrics, duration)
|
215
161
|
ensure
|
216
162
|
super
|
217
163
|
end
|
218
|
-
|
219
|
-
end # DataMapperInstrumentation
|
220
|
-
end # Instrumentation
|
221
|
-
end # Agent
|
222
|
-
end # NewRelic
|
223
|
-
|
224
|
-
DependencyDetection.defer do
|
225
|
-
|
226
|
-
depends_on do
|
227
|
-
defined?(DataObjects) && defined?(DataObjects::Connection)
|
228
|
-
end
|
229
|
-
|
230
|
-
executes do
|
231
|
-
DataObjects::Connection.class_eval do
|
232
|
-
include ::NewRelic::Agent::Instrumentation::DataMapperInstrumentation
|
164
|
+
end
|
233
165
|
end
|
234
166
|
end
|
235
167
|
end
|
@@ -9,83 +9,135 @@
|
|
9
9
|
# http://seattlerb.rubyforge.org/memcache-client/ (Gem: memcache-client)
|
10
10
|
# http://github.com/mperham/dalli (Gem: dalli)
|
11
11
|
|
12
|
+
require 'new_relic/agent/datastores/metric_helper'
|
13
|
+
|
12
14
|
module NewRelic
|
13
15
|
module Agent
|
14
16
|
module Instrumentation
|
15
17
|
module Memcache
|
16
18
|
module_function
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
|
20
|
+
def enabled?
|
21
|
+
!::NewRelic::Agent.config[:disable_memcache_instrumentation]
|
22
|
+
end
|
23
|
+
|
24
|
+
METHODS = [:get, :get_multi, :set, :add, :incr, :decr, :delete, :replace, :append,
|
25
|
+
:prepend, :cas, :single_get, :multi_get, :single_cas, :multi_cas]
|
26
|
+
|
27
|
+
def supported_methods_for(client_class, methods)
|
28
|
+
methods.select do |method_name|
|
29
|
+
client_class.method_defined?(method_name) || client_class.private_method_defined?(method_name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def instrument_methods(client_class, requested_methods = METHODS)
|
34
|
+
supported_methods_for(client_class, requested_methods).each do |method_name|
|
35
|
+
|
36
|
+
visibility = NewRelic::Helper.instance_method_visibility client_class, method_name
|
37
|
+
method_name_without = :"#{method_name}_without_newrelic_trace"
|
38
|
+
|
39
|
+
client_class.class_eval do
|
40
|
+
alias_method method_name_without, method_name
|
41
|
+
|
42
|
+
define_method method_name do |*args, &block|
|
43
|
+
metrics = Datastores::MetricHelper.metrics_for("Memcached", method_name)
|
44
|
+
|
45
|
+
NewRelic::Agent::MethodTracer.trace_execution_scoped(metrics) do
|
27
46
|
t0 = Time.now
|
28
47
|
begin
|
29
|
-
|
48
|
+
send method_name_without, *args, &block
|
30
49
|
ensure
|
31
|
-
|
50
|
+
if NewRelic::Agent.config[:capture_memcache_keys]
|
51
|
+
NewRelic::Agent.instance.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil
|
52
|
+
end
|
32
53
|
end
|
33
54
|
end
|
34
55
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def memcache_key_snippet(method_name)
|
41
|
-
return "" unless NewRelic::Agent.config[:capture_memcache_keys]
|
42
|
-
"NewRelic::Agent.instance.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil"
|
56
|
+
|
57
|
+
send visibility, method_name
|
58
|
+
send visibility, method_name_without
|
59
|
+
end
|
60
|
+
end
|
43
61
|
end
|
62
|
+
|
44
63
|
end
|
45
64
|
end
|
46
65
|
end
|
47
66
|
end
|
48
67
|
|
49
68
|
DependencyDetection.defer do
|
50
|
-
|
69
|
+
named :memcache_client
|
51
70
|
|
52
71
|
depends_on do
|
53
|
-
|
72
|
+
NewRelic::Agent::Instrumentation::Memcache.enabled?
|
54
73
|
end
|
55
74
|
|
56
75
|
depends_on do
|
57
|
-
defined?(::MemCache)
|
58
|
-
defined?(::Dalli::Client) || defined?(::Spymemcached)
|
76
|
+
defined?(::MemCache)
|
59
77
|
end
|
60
78
|
|
61
79
|
executes do
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
::NewRelic::Agent.logger.info 'Installing Memcached instrumentation for memcache-client gem'
|
81
|
+
NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::MemCache)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
DependencyDetection.defer do
|
86
|
+
named :memcached
|
87
|
+
|
88
|
+
depends_on do
|
89
|
+
NewRelic::Agent::Instrumentation::Memcache.enabled?
|
90
|
+
end
|
91
|
+
|
92
|
+
depends_on do
|
93
|
+
defined?(::Memcached)
|
94
|
+
end
|
95
|
+
|
96
|
+
executes do
|
97
|
+
::NewRelic::Agent.logger.info 'Installing Memcached instrumentation for memcached gem'
|
98
|
+
::NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::Memcached)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
DependencyDetection.defer do
|
103
|
+
named :dalli
|
104
|
+
|
105
|
+
depends_on do
|
106
|
+
NewRelic::Agent::Instrumentation::Memcache.enabled?
|
107
|
+
end
|
108
|
+
|
109
|
+
depends_on do
|
110
|
+
defined?(::Dalli::Client)
|
111
|
+
end
|
112
|
+
|
113
|
+
executes do
|
114
|
+
::NewRelic::Agent.logger.info 'Installing Memcache instrumentation for dalli gem'
|
115
|
+
::NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::Dalli::Client)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
DependencyDetection.defer do
|
120
|
+
named :dalli_cas_client
|
121
|
+
|
122
|
+
depends_on do
|
123
|
+
NewRelic::Agent::Instrumentation::Memcache.enabled?
|
124
|
+
end
|
125
|
+
|
126
|
+
depends_on do
|
127
|
+
# These CAS client methods are only optionally defined if users require
|
128
|
+
# dalli/cas/client. Use a separate dependency block so it can potentially
|
129
|
+
# re-evaluate after they've done that require.
|
130
|
+
defined?(::Dalli::Client) &&
|
131
|
+
::NewRelic::Agent::Instrumentation::Memcache.supported_methods_for(::Dalli::Client,
|
132
|
+
CAS_CLIENT_METHODS).any?
|
133
|
+
end
|
134
|
+
|
135
|
+
CAS_CLIENT_METHODS = [:get_cas, :get_multi_cas, :set_cas, :replace_cas,
|
136
|
+
:delete_cas]
|
137
|
+
|
138
|
+
executes do
|
139
|
+
::NewRelic::Agent.logger.info 'Installing Dalli CAS Client Memcache instrumentation'
|
140
|
+
::NewRelic::Agent::Instrumentation::Memcache.instrument_methods(::Dalli::Client,
|
141
|
+
CAS_CLIENT_METHODS)
|
90
142
|
end
|
91
143
|
end
|