oneapm_rpm 1.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.rubocop.yml +725 -0
- data/Gemfile +3 -0
- data/Guardfile +7 -0
- data/LICENSE +1 -0
- data/README.md +3 -0
- data/config/cert/cacert.pem +1177 -0
- data/config/database.yml +5 -0
- data/lib/initializers/goliath.rb +11 -0
- data/lib/initializers/other.rb +1 -0
- data/lib/initializers/rails.rb +15 -0
- data/lib/one_apm/agent.rb +253 -0
- data/lib/one_apm/agent/agent.rb +283 -0
- data/lib/one_apm/agent/agent/connect.rb +175 -0
- data/lib/one_apm/agent/agent/container_data_manager.rb +218 -0
- data/lib/one_apm/agent/agent/forkable_dispatcher_functions.rb +96 -0
- data/lib/one_apm/agent/agent/helpers.rb +45 -0
- data/lib/one_apm/agent/agent/start.rb +226 -0
- data/lib/one_apm/agent/agent/start_worker_thread.rb +148 -0
- data/lib/one_apm/agent/busy_calculator.rb +115 -0
- data/lib/one_apm/agent/cross_app/cross_app_monitor.rb +181 -0
- data/lib/one_apm/agent/cross_app/cross_app_tracing.rb +336 -0
- data/lib/one_apm/agent/database.rb +308 -0
- data/lib/one_apm/agent/database/active_record_helper.rb +80 -0
- data/lib/one_apm/agent/database/obfuscation_helpers.rb +76 -0
- data/lib/one_apm/agent/database/obfuscator.rb +78 -0
- data/lib/one_apm/agent/database/postgres_explain_obfuscator.rb +45 -0
- data/lib/one_apm/agent/datastores.rb +175 -0
- data/lib/one_apm/agent/datastores/metric_helper.rb +83 -0
- data/lib/one_apm/agent/datastores/mongo.rb +27 -0
- data/lib/one_apm/agent/datastores/mongo/metric_translator.rb +189 -0
- data/lib/one_apm/agent/datastores/mongo/obfuscator.rb +37 -0
- data/lib/one_apm/agent/datastores/mongo/statement_formatter.rb +51 -0
- data/lib/one_apm/agent/event/event_listener.rb +40 -0
- data/lib/one_apm/agent/event/event_loop.rb +191 -0
- data/lib/one_apm/agent/event/worker_loop.rb +97 -0
- data/lib/one_apm/agent/harvester.rb +48 -0
- data/lib/one_apm/agent/inbound_request_monitor.rb +30 -0
- data/lib/one_apm/agent/javascript_instrumentor.rb +186 -0
- data/lib/one_apm/agent/pipe/pipe_channel_manager.rb +275 -0
- data/lib/one_apm/agent/pipe/pipe_service.rb +81 -0
- data/lib/one_apm/agent/sampler.rb +55 -0
- data/lib/one_apm/agent/sampler_collection.rb +65 -0
- data/lib/one_apm/agent/samplers/cpu_sampler.rb +49 -0
- data/lib/one_apm/agent/samplers/delayed_job_sampler.rb +109 -0
- data/lib/one_apm/agent/samplers/memory_sampler.rb +144 -0
- data/lib/one_apm/agent/samplers/object_sampler.rb +22 -0
- data/lib/one_apm/agent/samplers/vm_sampler.rb +124 -0
- data/lib/one_apm/agent/synthetics_monitor.rb +48 -0
- data/lib/one_apm/agent/threading/agent_thread.rb +74 -0
- data/lib/one_apm/agent/threading/backtrace_node.rb +133 -0
- data/lib/one_apm/agent/threading/backtrace_service.rb +259 -0
- data/lib/one_apm/agent/threading/thread_profile.rb +155 -0
- data/lib/one_apm/collector/collector/helper.rb +139 -0
- data/lib/one_apm/collector/collector/http_connection.rb +254 -0
- data/lib/one_apm/collector/collector/server_methods.rb +71 -0
- data/lib/one_apm/collector/collector_service.rb +123 -0
- data/lib/one_apm/collector/commands/agent_command.rb +17 -0
- data/lib/one_apm/collector/commands/thread_profiler_session.rb +108 -0
- data/lib/one_apm/collector/commands/xray_session.rb +53 -0
- data/lib/one_apm/collector/commands/xray_session_collection.rb +156 -0
- data/lib/one_apm/collector/containers/agent_command_router.rb +153 -0
- data/lib/one_apm/collector/containers/custom_event_aggregator.rb +94 -0
- data/lib/one_apm/collector/containers/error_collector.rb +349 -0
- data/lib/one_apm/collector/containers/sql_sampler.rb +331 -0
- data/lib/one_apm/collector/containers/stats_engine.rb +34 -0
- data/lib/one_apm/collector/containers/transaction_event_aggregator.rb +249 -0
- data/lib/one_apm/collector/containers/transaction_sampler.rb +352 -0
- data/lib/one_apm/collector/containers/utilization_data.rb +36 -0
- data/lib/one_apm/collector/stats_engine/gc_profiler.rb +106 -0
- data/lib/one_apm/collector/stats_engine/metric_stats.rb +243 -0
- data/lib/one_apm/collector/stats_engine/stats_hash.rb +105 -0
- data/lib/one_apm/configuration.rb +429 -0
- data/lib/one_apm/configuration/autostart.rb +41 -0
- data/lib/one_apm/configuration/default_source.rb +1026 -0
- data/lib/one_apm/configuration/environment_source.rb +113 -0
- data/lib/one_apm/configuration/high_security_source.rb +56 -0
- data/lib/one_apm/configuration/manual_source.rb +13 -0
- data/lib/one_apm/configuration/server_source.rb +60 -0
- data/lib/one_apm/configuration/yaml_source.rb +134 -0
- data/lib/one_apm/errors/agent_errors.rb +26 -0
- data/lib/one_apm/errors/internal_agent_error.rb +16 -0
- data/lib/one_apm/errors/noticed_error.rb +79 -0
- data/lib/one_apm/frameworks/external.rb +15 -0
- data/lib/one_apm/frameworks/rails.rb +103 -0
- data/lib/one_apm/frameworks/rails3.rb +37 -0
- data/lib/one_apm/frameworks/rails4.rb +21 -0
- data/lib/one_apm/frameworks/ruby.rb +21 -0
- data/lib/one_apm/frameworks/sinatra.rb +12 -0
- data/lib/one_apm/inst/3rd/active_merchant.rb +35 -0
- data/lib/one_apm/inst/3rd/acts_as_solr.rb +70 -0
- data/lib/one_apm/inst/3rd/authlogic.rb +23 -0
- data/lib/one_apm/inst/3rd/sunspot.rb +31 -0
- data/lib/one_apm/inst/background_job/active_job.rb +88 -0
- data/lib/one_apm/inst/background_job/delayed_job.rb +52 -0
- data/lib/one_apm/inst/background_job/delayed_job_injection.rb +8 -0
- data/lib/one_apm/inst/background_job/resque.rb +107 -0
- data/lib/one_apm/inst/background_job/sidekiq.rb +64 -0
- data/lib/one_apm/inst/dispatcher/passenger.rb +25 -0
- data/lib/one_apm/inst/dispatcher/rainbows.rb +23 -0
- data/lib/one_apm/inst/framework/grape.rb +94 -0
- data/lib/one_apm/inst/framework/padrino.rb +30 -0
- data/lib/one_apm/inst/framework/sinatra.rb +185 -0
- data/lib/one_apm/inst/framework/sinatra/ignorer.rb +50 -0
- data/lib/one_apm/inst/framework/sinatra/transaction_namer.rb +54 -0
- data/lib/one_apm/inst/http_clients/curb.rb +189 -0
- data/lib/one_apm/inst/http_clients/excon.rb +70 -0
- data/lib/one_apm/inst/http_clients/excon/connection.rb +31 -0
- data/lib/one_apm/inst/http_clients/excon/middleware.rb +55 -0
- data/lib/one_apm/inst/http_clients/httpclient.rb +44 -0
- data/lib/one_apm/inst/http_clients/net.rb +34 -0
- data/lib/one_apm/inst/http_clients/typhoeus.rb +76 -0
- data/lib/one_apm/inst/nosql/memcache.rb +134 -0
- data/lib/one_apm/inst/nosql/mongo.rb +126 -0
- data/lib/one_apm/inst/nosql/mongo_moped.rb +85 -0
- data/lib/one_apm/inst/nosql/redis.rb +83 -0
- data/lib/one_apm/inst/orm/active_record.rb +99 -0
- data/lib/one_apm/inst/orm/active_record_4.rb +28 -0
- data/lib/one_apm/inst/orm/data_mapper.rb +180 -0
- data/lib/one_apm/inst/orm/sequel.rb +47 -0
- data/lib/one_apm/inst/rack.rb +38 -0
- data/lib/one_apm/inst/rack/rack.rb +44 -0
- data/lib/one_apm/inst/rack/rack_builder.rb +51 -0
- data/lib/one_apm/inst/rails/action_controller.rb +118 -0
- data/lib/one_apm/inst/rails/action_web_service.rb +44 -0
- data/lib/one_apm/inst/rails/errors.rb +43 -0
- data/lib/one_apm/inst/rails3/action_controller.rb +172 -0
- data/lib/one_apm/inst/rails3/errors.rb +43 -0
- data/lib/one_apm/inst/rails4/action_controller.rb +27 -0
- data/lib/one_apm/inst/rails4/action_controller_subscriber.rb +121 -0
- data/lib/one_apm/inst/rails4/action_view.rb +23 -0
- data/lib/one_apm/inst/rails4/action_view_subscriber.rb +93 -0
- data/lib/one_apm/inst/rails4/active_record_subscriber.rb +96 -0
- data/lib/one_apm/inst/rails4/errors.rb +42 -0
- data/lib/one_apm/inst/rails_middleware.rb +40 -0
- data/lib/one_apm/inst/support/evented_subscriber.rb +98 -0
- data/lib/one_apm/inst/support/ignore_actions.rb +39 -0
- data/lib/one_apm/inst/support/queue_time.rb +76 -0
- data/lib/one_apm/inst/transaction_base.rb +405 -0
- data/lib/one_apm/logger/agent_logger.rb +206 -0
- data/lib/one_apm/logger/audit_logger.rb +78 -0
- data/lib/one_apm/logger/memory_logger.rb +50 -0
- data/lib/one_apm/logger/null_logger.rb +19 -0
- data/lib/one_apm/metrics/metric_data.rb +72 -0
- data/lib/one_apm/metrics/metric_spec.rb +82 -0
- data/lib/one_apm/metrics/stats.rb +173 -0
- data/lib/one_apm/probe.rb +16 -0
- data/lib/one_apm/probe/framework_loader.rb +53 -0
- data/lib/one_apm/probe/instance_methods.rb +105 -0
- data/lib/one_apm/probe/instrumentation.rb +60 -0
- data/lib/one_apm/rack/browser_monitoring.rb +144 -0
- data/lib/one_apm/rack/middleware_base.rb +27 -0
- data/lib/one_apm/rack/middleware_hooks.rb +17 -0
- data/lib/one_apm/rack/middleware_tracing.rb +81 -0
- data/lib/one_apm/rack/middleware_wrapper.rb +86 -0
- data/lib/one_apm/support/chained_call.rb +15 -0
- data/lib/one_apm/support/coerce.rb +81 -0
- data/lib/one_apm/support/collection_helper.rb +79 -0
- data/lib/one_apm/support/dotted_hash.rb +45 -0
- data/lib/one_apm/support/encoders.rb +34 -0
- data/lib/one_apm/support/environment_report.rb +127 -0
- data/lib/one_apm/support/event_buffer.rb +82 -0
- data/lib/one_apm/support/event_buffer/sampled_buffer.rb +45 -0
- data/lib/one_apm/support/event_buffer/sized_buffer.rb +21 -0
- data/lib/one_apm/support/event_buffer/synthetics_event_buffer.rb +40 -0
- data/lib/one_apm/support/helper.rb +49 -0
- data/lib/one_apm/support/hostname.rb +13 -0
- data/lib/one_apm/support/http_clients/curb_wrappers.rb +65 -0
- data/lib/one_apm/support/http_clients/excon_wrappers.rb +63 -0
- data/lib/one_apm/support/http_clients/httpclient_wrappers.rb +61 -0
- data/lib/one_apm/support/http_clients/net_http_wrappers.rb +48 -0
- data/lib/one_apm/support/http_clients/typhoeus_wrappers.rb +73 -0
- data/lib/one_apm/support/http_clients/uri_util.rb +39 -0
- data/lib/one_apm/support/json_marshaller.rb +68 -0
- data/lib/one_apm/support/json_wrapper.rb +130 -0
- data/lib/one_apm/support/language_support.rb +142 -0
- data/lib/one_apm/support/library_detection.rb +119 -0
- data/lib/one_apm/support/local_environment.rb +196 -0
- data/lib/one_apm/support/marshaller.rb +62 -0
- data/lib/one_apm/support/method_tracer.rb +334 -0
- data/lib/one_apm/support/method_tracer/helpers.rb +92 -0
- data/lib/one_apm/support/method_tracer/traced_method_stack.rb +103 -0
- data/lib/one_apm/support/obfuscator.rb +47 -0
- data/lib/one_apm/support/okjson.rb +601 -0
- data/lib/one_apm/support/parameter_filtering.rb +35 -0
- data/lib/one_apm/support/rules_engine.rb +56 -0
- data/lib/one_apm/support/rules_engine/replacement_rule.rb +80 -0
- data/lib/one_apm/support/rules_engine/segment_terms_rule.rb +46 -0
- data/lib/one_apm/support/server.rb +11 -0
- data/lib/one_apm/support/supported_versions.rb +257 -0
- data/lib/one_apm/support/system_info.rb +211 -0
- data/lib/one_apm/support/timer_lib.rb +29 -0
- data/lib/one_apm/support/version_number.rb +51 -0
- data/lib/one_apm/support/vm.rb +30 -0
- data/lib/one_apm/support/vm/jruby_vm.rb +38 -0
- data/lib/one_apm/support/vm/monotonic_gc_profiler.rb +43 -0
- data/lib/one_apm/support/vm/mri_vm.rb +85 -0
- data/lib/one_apm/support/vm/rubinius_vm.rb +129 -0
- data/lib/one_apm/support/vm/snapshot.rb +18 -0
- data/lib/one_apm/transaction.rb +336 -0
- data/lib/one_apm/transaction/class_methods.rb +132 -0
- data/lib/one_apm/transaction/instance_helpers.rb +82 -0
- data/lib/one_apm/transaction/metric_constants.rb +42 -0
- data/lib/one_apm/transaction/sample_buffer/force_persist_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/slowest_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/synthetics_sample_buffer.rb +21 -0
- data/lib/one_apm/transaction/sample_buffer/transaction_sample_buffer.rb +101 -0
- data/lib/one_apm/transaction/sample_buffer/xray_sample_buffer.rb +60 -0
- data/lib/one_apm/transaction/segment.rb +193 -0
- data/lib/one_apm/transaction/segment_summary.rb +51 -0
- data/lib/one_apm/transaction/thread_local_access.rb +73 -0
- data/lib/one_apm/transaction/transaction_analysis.rb +78 -0
- data/lib/one_apm/transaction/transaction_apdex.rb +20 -0
- data/lib/one_apm/transaction/transaction_cpu.rb +22 -0
- data/lib/one_apm/transaction/transaction_finish_append.rb +67 -0
- data/lib/one_apm/transaction/transaction_ignore.rb +33 -0
- data/lib/one_apm/transaction/transaction_jruby_functions.rb +40 -0
- data/lib/one_apm/transaction/transaction_metrics.rb +53 -0
- data/lib/one_apm/transaction/transaction_name.rb +90 -0
- data/lib/one_apm/transaction/transaction_namer.rb +49 -0
- data/lib/one_apm/transaction/transaction_sample.rb +204 -0
- data/lib/one_apm/transaction/transaction_sample_builder.rb +168 -0
- data/lib/one_apm/transaction/transaction_state.rb +149 -0
- data/lib/one_apm/transaction/transaction_summary.rb +28 -0
- data/lib/one_apm/transaction/transaction_synthetics.rb +40 -0
- data/lib/one_apm/transaction/transaction_timings.rb +54 -0
- data/lib/one_apm/version.rb +13 -0
- data/lib/oneapm_rpm.rb +16 -0
- data/lib/sequel/extensions/oneapm_instrumentation.rb +84 -0
- data/lib/sequel/plugins/oneapm_instrumentation.rb +66 -0
- data/oneapm.yml +135 -0
- data/oneapm_rpm.gemspec +58 -0
- metadata +474 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/support/method_tracer'
|
4
|
+
|
5
|
+
LibraryDetection.defer do
|
6
|
+
@name = :redis
|
7
|
+
|
8
|
+
depends_on do
|
9
|
+
defined?(::Redis) && !OneApm::Agent.config[:disable_redis]
|
10
|
+
end
|
11
|
+
|
12
|
+
executes do
|
13
|
+
OneApm::Agent.logger.info 'Installing Redis Instrumentation'
|
14
|
+
end
|
15
|
+
|
16
|
+
executes do
|
17
|
+
require 'one_apm/agent/datastores'
|
18
|
+
|
19
|
+
::Redis::Client.class_eval do
|
20
|
+
# Support older versions of Redis::Client that used the method
|
21
|
+
# +raw_call_command+.
|
22
|
+
|
23
|
+
call_method = ::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
|
24
|
+
|
25
|
+
def call_with_oneapm_trace(*args, &blk)
|
26
|
+
method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
|
27
|
+
callback = proc do |result, metric, elapsed|
|
28
|
+
_send_to_one_apm(args, elapsed)
|
29
|
+
end
|
30
|
+
|
31
|
+
OneApm::Agent::Datastores.wrap("Redis", method_name, nil, callback) do
|
32
|
+
call_without_oneapm_trace(*args, &blk)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :call_without_oneapm_trace, call_method
|
37
|
+
alias_method call_method, :call_with_oneapm_trace
|
38
|
+
|
39
|
+
# Older versions of Redis handle pipelining completely differently.
|
40
|
+
# Don't bother supporting them for now.
|
41
|
+
#
|
42
|
+
if public_method_defined? :call_pipelined
|
43
|
+
def call_pipelined_with_oneapm_trace(commands, *rest)
|
44
|
+
# Report each command as a metric suffixed with _pipelined, so the
|
45
|
+
# user can at least see what all the commands were.
|
46
|
+
additional = commands.map do |c|
|
47
|
+
name = c.kind_of?(Array) ? c[0] : c
|
48
|
+
"Datastore/operation/Redis/#{name.to_s.downcase}_pipelined"
|
49
|
+
end
|
50
|
+
|
51
|
+
callback = proc do |result, metric, elapsed|
|
52
|
+
_send_to_one_apm(commands, elapsed)
|
53
|
+
additional.each do |additional_metric|
|
54
|
+
OneApm::Support::MethodTracer.trace_execution_scoped(additional_metric) do
|
55
|
+
# No-op, just getting them as placeholders in the trace tree
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
OneApm::Agent::Datastores.wrap("Redis", "pipelined", nil, callback) do
|
61
|
+
call_pipelined_without_oneapm_trace commands, *rest
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
alias_method :call_pipelined_without_oneapm_trace, :call_pipelined
|
66
|
+
alias_method :call_pipelined, :call_pipelined_with_oneapm_trace
|
67
|
+
end
|
68
|
+
|
69
|
+
def _send_to_one_apm(args, elapsed)
|
70
|
+
if OneApm::Agent.config[:"transaction_tracer.record_sql"] == "obfuscated"
|
71
|
+
args.map! do |arg|
|
72
|
+
if arg.empty?
|
73
|
+
arg
|
74
|
+
else
|
75
|
+
[arg.first] + ["?"] * (arg.count - 1)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
OneApm::Agent::Datastores.notice_statement(args.inspect, elapsed)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/agent/database/active_record_helper'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
module Agent
|
7
|
+
module Instrumentation
|
8
|
+
module ActiveRecord
|
9
|
+
|
10
|
+
EXPLAINER = lambda do |config, query|
|
11
|
+
connection = OneApm::Agent::Database.get_connection(config) do
|
12
|
+
::ActiveRecord::Base.send("#{config[:adapter]}_connection", config)
|
13
|
+
end
|
14
|
+
if connection && connection.respond_to?(:execute)
|
15
|
+
connection.execute("EXPLAIN #{query}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.insert_instrumentation
|
20
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
|
21
|
+
include ::OneApm::Agent::Instrumentation::ActiveRecord
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(instrumented_class)
|
26
|
+
instrumented_class.class_eval do
|
27
|
+
unless instrumented_class.method_defined?(:log_without_oneapm_instrumentation)
|
28
|
+
alias_method :log_without_oneapm_instrumentation, :log
|
29
|
+
alias_method :log, :log_with_oneapm_instrumentation
|
30
|
+
protected :log
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def log_with_oneapm_instrumentation(*args, &block) #THREAD_LOCAL_ACCESS
|
36
|
+
state = OneApm::TransactionState.tl_get
|
37
|
+
|
38
|
+
if !state.is_execution_traced?
|
39
|
+
return log_without_oneapm_instrumentation(*args, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
sql, name, _ = args
|
43
|
+
metric = ActiveRecordHelper.metric_for_name(OneApm::Helper.correctly_encoded(name)) ||
|
44
|
+
ActiveRecordHelper.metric_for_sql(OneApm::Helper.correctly_encoded(sql))
|
45
|
+
|
46
|
+
if !metric
|
47
|
+
log_without_oneapm_instrumentation(*args, &block)
|
48
|
+
else
|
49
|
+
metrics = [metric, remote_service_metric].compact
|
50
|
+
metrics += ActiveRecordHelper.rollup_metrics_for(metric)
|
51
|
+
self.class.trace_execution_scoped(metrics) do
|
52
|
+
t0 = Time.now
|
53
|
+
begin
|
54
|
+
log_without_oneapm_instrumentation(*args, &block)
|
55
|
+
ensure
|
56
|
+
elapsed_time = (Time.now - t0).to_f
|
57
|
+
OneApm::Agent.notice_sql(sql, metric, @config, elapsed_time, state, &EXPLAINER)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def remote_service_metric
|
64
|
+
if @config && @config[:adapter]
|
65
|
+
ActiveRecordHelper.remote_service_metric(@config[:adapter], @config[:host])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
LibraryDetection.defer do
|
74
|
+
@name = :active_record
|
75
|
+
|
76
|
+
depends_on do
|
77
|
+
defined?(::ActiveRecord) &&
|
78
|
+
defined?(::ActiveRecord::Base) &&
|
79
|
+
(!defined?(::ActiveRecord::VERSION) || ::ActiveRecord::VERSION::MAJOR.to_i <= 3)
|
80
|
+
end
|
81
|
+
|
82
|
+
depends_on do
|
83
|
+
!OneApm::Agent.config[:disable_activerecord]
|
84
|
+
end
|
85
|
+
|
86
|
+
executes do
|
87
|
+
::OneApm::Agent.logger.info 'Installing ActiveRecord instrumentation'
|
88
|
+
end
|
89
|
+
|
90
|
+
executes do
|
91
|
+
if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3
|
92
|
+
ActiveSupport.on_load(:active_record) do
|
93
|
+
::OneApm::Agent::Instrumentation::ActiveRecord.insert_instrumentation
|
94
|
+
end
|
95
|
+
else
|
96
|
+
::OneApm::Agent::Instrumentation::ActiveRecord.insert_instrumentation
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/inst/rails4/active_record_subscriber'
|
4
|
+
|
5
|
+
LibraryDetection.defer do
|
6
|
+
named :active_record_4
|
7
|
+
|
8
|
+
depends_on do
|
9
|
+
defined?(::ActiveRecord) &&
|
10
|
+
defined?(::ActiveRecord::Base) &&
|
11
|
+
defined?(::ActiveRecord::VERSION) &&
|
12
|
+
::ActiveRecord::VERSION::MAJOR.to_i >= 4
|
13
|
+
end
|
14
|
+
|
15
|
+
depends_on do
|
16
|
+
!OneApm::Agent.config[:disable_activerecord] &&
|
17
|
+
!OneApm::Agent::Instrumentation::ActiveRecordSubscriber.subscribed?
|
18
|
+
end
|
19
|
+
|
20
|
+
executes do
|
21
|
+
::OneApm::Agent.logger.info 'Installing ActiveRecord 4 instrumentation'
|
22
|
+
end
|
23
|
+
|
24
|
+
executes do
|
25
|
+
subscriber = OneApm::Agent::Instrumentation::ActiveRecordSubscriber.new
|
26
|
+
ActiveSupport::Notifications.subscribe('sql.active_record', subscriber)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
LibraryDetection.defer do
|
4
|
+
@name = :data_mapper
|
5
|
+
|
6
|
+
depends_on do
|
7
|
+
defined?(::DataMapper)
|
8
|
+
end
|
9
|
+
|
10
|
+
depends_on do
|
11
|
+
defined?(DataMapper::Model)
|
12
|
+
end
|
13
|
+
|
14
|
+
depends_on do
|
15
|
+
defined?(DataMapper::Resource)
|
16
|
+
end
|
17
|
+
|
18
|
+
depends_on do
|
19
|
+
defined?(DataMapper::Collection)
|
20
|
+
end
|
21
|
+
|
22
|
+
executes do
|
23
|
+
::OneApm::Agent.logger.info 'Installing DataMapper instrumentation'
|
24
|
+
end
|
25
|
+
|
26
|
+
executes do
|
27
|
+
DataMapper::Model.class_eval do
|
28
|
+
add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
|
29
|
+
add_method_tracer :first, 'ActiveRecord/#{self.name}/first'
|
30
|
+
add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
|
31
|
+
add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
|
32
|
+
|
33
|
+
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
34
|
+
add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
|
35
|
+
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
36
|
+
add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
|
37
|
+
add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
|
38
|
+
add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
|
39
|
+
|
40
|
+
# For dm-aggregates and partial dm-ar-finders support:
|
41
|
+
for method in [ :aggregate, :find, :find_by_sql ] do
|
42
|
+
next unless method_defined? method
|
43
|
+
add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
executes do
|
50
|
+
DataMapper::Resource.class_eval do
|
51
|
+
add_method_tracer :update, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
|
52
|
+
add_method_tracer :update!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
|
53
|
+
add_method_tracer :save, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
|
54
|
+
add_method_tracer :save!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/save'
|
55
|
+
add_method_tracer :destroy, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
|
56
|
+
add_method_tracer :destroy!, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
executes do
|
62
|
+
DataMapper::Collection.class_eval do
|
63
|
+
# DM's Collection instance methods
|
64
|
+
add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
|
65
|
+
add_method_tracer :first, 'ActiveRecord/#{self.name}/first'
|
66
|
+
add_method_tracer :last, 'ActiveRecord/#{self.name}/last'
|
67
|
+
add_method_tracer :all, 'ActiveRecord/#{self.name}/all'
|
68
|
+
|
69
|
+
add_method_tracer :lazy_load, 'ActiveRecord/#{self.name}/lazy_load'
|
70
|
+
|
71
|
+
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
72
|
+
add_method_tracer :create!, 'ActiveRecord/#{self.name}/create'
|
73
|
+
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
74
|
+
add_method_tracer :update!, 'ActiveRecord/#{self.name}/update'
|
75
|
+
add_method_tracer :destroy, 'ActiveRecord/#{self.name}/destroy'
|
76
|
+
add_method_tracer :destroy!, 'ActiveRecord/#{self.name}/destroy'
|
77
|
+
|
78
|
+
# For dm-aggregates support:
|
79
|
+
for method in [ :aggregate ] do
|
80
|
+
next unless method_defined? method
|
81
|
+
add_method_tracer(method, 'ActiveRecord/#{self.name}/' + method.to_s)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
LibraryDetection.defer do
|
89
|
+
|
90
|
+
depends_on do
|
91
|
+
defined?(DataMapper) && defined?(DataMapper::Adapters) && defined?(DataMapper::Adapters::DataObjectsAdapter)
|
92
|
+
end
|
93
|
+
|
94
|
+
executes do
|
95
|
+
|
96
|
+
DataMapper::Adapters::DataObjectsAdapter.class_eval do
|
97
|
+
|
98
|
+
add_method_tracer :select, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/select'
|
99
|
+
add_method_tracer :execute, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/execute'
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
LibraryDetection.defer do
|
106
|
+
|
107
|
+
depends_on do
|
108
|
+
defined?(DataMapper) && defined?(DataMapper::Validations) && defined?(DataMapper::Validations::ClassMethods)
|
109
|
+
end
|
110
|
+
|
111
|
+
executes do
|
112
|
+
DataMapper::Validations::ClassMethods.class_eval do
|
113
|
+
next unless method_defined? :create
|
114
|
+
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
LibraryDetection.defer do
|
120
|
+
|
121
|
+
depends_on do
|
122
|
+
defined?(DataMapper) && defined?(DataMapper::Transaction)
|
123
|
+
end
|
124
|
+
|
125
|
+
executes do
|
126
|
+
DataMapper::Transaction.module_eval do
|
127
|
+
add_method_tracer :commit, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/commit'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
module OneApm
|
134
|
+
module Agent
|
135
|
+
module Instrumentation
|
136
|
+
module DataMapperInstrumentation
|
137
|
+
|
138
|
+
def log(msg) #THREAD_LOCAL_ACCESS
|
139
|
+
state = OneApm::TransactionState.tl_get
|
140
|
+
return unless state.is_execution_traced?
|
141
|
+
return unless operation = case OneApm::Helper.correctly_encoded(msg.query)
|
142
|
+
when /^\s*select/i then 'find'
|
143
|
+
when /^\s*(update|insert)/i then 'save'
|
144
|
+
when /^\s*delete/i then 'destroy'
|
145
|
+
else nil
|
146
|
+
end
|
147
|
+
|
148
|
+
# FYI: self.to_s will yield connection URI string.
|
149
|
+
duration = msg.duration / 1000000.0
|
150
|
+
|
151
|
+
# Attach SQL to current segment/scope.
|
152
|
+
OneApm::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration, state)
|
153
|
+
|
154
|
+
# Record query duration associated with each of the desired metrics.
|
155
|
+
metric = "ActiveRecord/#{operation}"
|
156
|
+
rollup_metrics = ActiveRecordHelper.rollup_metrics_for(metric)
|
157
|
+
metrics = [metric] + rollup_metrics
|
158
|
+
OneApm::Agent.instance.stats_engine.tl_record_unscoped_metrics(metrics, duration)
|
159
|
+
ensure
|
160
|
+
super
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
LibraryDetection.defer do
|
169
|
+
|
170
|
+
depends_on do
|
171
|
+
defined?(DataObjects) && defined?(DataObjects::Connection)
|
172
|
+
end
|
173
|
+
|
174
|
+
executes do
|
175
|
+
DataObjects::Connection.class_eval do
|
176
|
+
include ::OneApm::Agent::Instrumentation::DataMapperInstrumentation
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
LibraryDetection.defer do
|
4
|
+
@name = :sequel
|
5
|
+
|
6
|
+
depends_on do
|
7
|
+
defined?(::Sequel)
|
8
|
+
end
|
9
|
+
|
10
|
+
depends_on do
|
11
|
+
!OneApm::Agent.config[:disable_sequel_instrumentation]
|
12
|
+
end
|
13
|
+
|
14
|
+
def supported_sequel_version?
|
15
|
+
Sequel.const_defined?( :MAJOR ) &&
|
16
|
+
( Sequel::MAJOR > 3 ||
|
17
|
+
Sequel::MAJOR == 3 && Sequel::MINOR >= 37 )
|
18
|
+
end
|
19
|
+
|
20
|
+
executes do
|
21
|
+
if supported_sequel_version?
|
22
|
+
|
23
|
+
::OneApm::Agent.logger.info 'Installing Sequel instrumentation'
|
24
|
+
|
25
|
+
if Sequel::Database.respond_to?(:extension)
|
26
|
+
Sequel::Database.extension :oneapm_instrumentation
|
27
|
+
else
|
28
|
+
OneApm::Agent.logger.info "Detected Sequel version %s." % [ Sequel::VERSION ]
|
29
|
+
OneApm::Agent.logger.info "Please see additional documentation: " +
|
30
|
+
"https://oneapm.com/docs/ruby/sequel-instrumentation"
|
31
|
+
end
|
32
|
+
|
33
|
+
Sequel.synchronize{Sequel::DATABASES.dup}.each do |db|
|
34
|
+
db.extension :oneapm_instrumentation
|
35
|
+
end
|
36
|
+
|
37
|
+
Sequel::Model.plugin :oneapm_instrumentation
|
38
|
+
|
39
|
+
else
|
40
|
+
|
41
|
+
OneApm::Agent.logger.info "Sequel instrumentation requires at least version 3.37.0."
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/inst/transaction_base'
|
4
|
+
require 'one_apm/inst/rack/rack'
|
5
|
+
require 'one_apm/inst/rack/rack_builder'
|
6
|
+
|
7
|
+
LibraryDetection.defer do
|
8
|
+
named :rack
|
9
|
+
|
10
|
+
depends_on do
|
11
|
+
defined?(::Rack) && defined?(::Rack::Builder)
|
12
|
+
end
|
13
|
+
|
14
|
+
executes do
|
15
|
+
::OneApm::Agent.logger.info 'Installing deferred Rack instrumentation'
|
16
|
+
|
17
|
+
class ::Rack::Builder
|
18
|
+
class << self
|
19
|
+
attr_accessor :_oa_deferred_detection_ran
|
20
|
+
end
|
21
|
+
self._oa_deferred_detection_ran = false
|
22
|
+
|
23
|
+
include ::OneApm::Agent::Instrumentation::RackBuilder
|
24
|
+
|
25
|
+
alias_method :to_app_without_oneapm, :to_app
|
26
|
+
alias_method :to_app, :to_app_with_oneapm_deferred_library_detection
|
27
|
+
|
28
|
+
unless OneApm::Agent.config[:disable_rack_middleware]
|
29
|
+
::OneApm::Agent.logger.info 'Installing Rack::Builder middleware instrumentation'
|
30
|
+
alias_method :run_without_oneapm, :run
|
31
|
+
alias_method :run, :run_with_oneapm
|
32
|
+
|
33
|
+
alias_method :use_without_oneapm, :use
|
34
|
+
alias_method :use, :use_with_oneapm
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|