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
data/config/database.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
OneApm::Probe.init
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if Rails::VERSION::MAJOR.to_i >= 3
|
2
|
+
module OneApm
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
|
5
|
+
initializer "oneapm_rpm.start_plugin" do |app|
|
6
|
+
OneApm::Probe.init :config => app.config
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
else
|
12
|
+
config = nil
|
13
|
+
config = Rails.configuration if Rails.respond_to?(:configuration)
|
14
|
+
OneApm::Probe.init :config => config
|
15
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/probe'
|
4
|
+
|
5
|
+
require 'one_apm/support/collection_helper'
|
6
|
+
require 'one_apm/support/timer_lib'
|
7
|
+
require 'one_apm/support/json_wrapper'
|
8
|
+
require 'one_apm/support/chained_call'
|
9
|
+
require 'one_apm/support/rules_engine'
|
10
|
+
require 'one_apm/support/http_clients/uri_util'
|
11
|
+
require 'one_apm/support/system_info'
|
12
|
+
|
13
|
+
require 'one_apm/metrics/metric_spec'
|
14
|
+
require 'one_apm/metrics/metric_data'
|
15
|
+
require 'one_apm/metrics/stats'
|
16
|
+
|
17
|
+
require 'one_apm/errors/noticed_error'
|
18
|
+
require 'one_apm/errors/agent_errors'
|
19
|
+
|
20
|
+
require 'one_apm/agent/agent'
|
21
|
+
require 'one_apm/agent/cross_app/cross_app_monitor'
|
22
|
+
require 'one_apm/support/method_tracer'
|
23
|
+
require 'one_apm/agent/event/worker_loop'
|
24
|
+
require 'one_apm/agent/event/event_loop'
|
25
|
+
require 'one_apm/transaction/transaction_sample'
|
26
|
+
|
27
|
+
require 'one_apm/collector/containers/stats_engine'
|
28
|
+
require 'one_apm/collector/containers/transaction_sampler'
|
29
|
+
require 'one_apm/collector/containers/sql_sampler'
|
30
|
+
require 'one_apm/collector/containers/error_collector'
|
31
|
+
|
32
|
+
require 'one_apm/agent/busy_calculator'
|
33
|
+
require 'one_apm/agent/database'
|
34
|
+
require 'one_apm/agent/pipe/pipe_channel_manager'
|
35
|
+
|
36
|
+
require 'one_apm/configuration'
|
37
|
+
|
38
|
+
require 'one_apm/agent/sampler'
|
39
|
+
require 'one_apm/agent/samplers/cpu_sampler'
|
40
|
+
require 'one_apm/agent/samplers/memory_sampler'
|
41
|
+
require 'one_apm/agent/samplers/object_sampler'
|
42
|
+
require 'one_apm/agent/samplers/delayed_job_sampler'
|
43
|
+
require 'one_apm/agent/samplers/vm_sampler'
|
44
|
+
|
45
|
+
module OneApm
|
46
|
+
module Agent
|
47
|
+
extend self
|
48
|
+
|
49
|
+
@agent = nil
|
50
|
+
|
51
|
+
def instance
|
52
|
+
return @agent if @agent
|
53
|
+
OneApm::Agent.logger.warn("Agent unavailable as it hasn't been started.")
|
54
|
+
OneApm::Agent.logger.warn(caller.join("\n"))
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def instance=(new_instance)
|
59
|
+
@agent = new_instance
|
60
|
+
end
|
61
|
+
|
62
|
+
def start(options = {})
|
63
|
+
raise "Options must be a hash" unless Hash === options
|
64
|
+
OneApm::Agent::PipeChannelManager.listener.start if options[:start_channel_listener]
|
65
|
+
OneApm::Probe.init({:agent_enabled => true, :sync_startup => true}.merge(options))
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method :manual_start, :start
|
69
|
+
|
70
|
+
def shutdown(options={})
|
71
|
+
instance.shutdown(options) if instance
|
72
|
+
end
|
73
|
+
|
74
|
+
def restart
|
75
|
+
OneApm::Agent.shutdown
|
76
|
+
OneApm::Agent.instance.harvest_samplers.clear
|
77
|
+
OneApm::Agent.instance.instance_variable_set(:@connect_state, :pending)
|
78
|
+
OneApm::Agent.instance.instance_variable_set(:@worker_thread, nil)
|
79
|
+
OneApm::Agent.instance.harvester.instance_variable_set(:@starting_pid, nil)
|
80
|
+
OneApm::Probe.init({:agent_enabled => true, :sync_startup => true})
|
81
|
+
end
|
82
|
+
|
83
|
+
def logger
|
84
|
+
@logger || StartupLogger.instance
|
85
|
+
end
|
86
|
+
|
87
|
+
def logger=(log)
|
88
|
+
@logger = log
|
89
|
+
end
|
90
|
+
|
91
|
+
def config
|
92
|
+
@config ||= OneApm::Configuration::Manager.new
|
93
|
+
end
|
94
|
+
|
95
|
+
def reset_config
|
96
|
+
@config.reset_to_defaults
|
97
|
+
end
|
98
|
+
|
99
|
+
def revert_to_default_configuration
|
100
|
+
@config.remove_config_type(:manual)
|
101
|
+
@config.remove_config_type(:server)
|
102
|
+
end
|
103
|
+
|
104
|
+
def record_metric(metric_name, value) #THREAD_LOCAL_ACCESS
|
105
|
+
value_to_store = value
|
106
|
+
value_to_store = OneApm::Metrics::Stats.create_from_hash(value) if value.is_a?(Hash)
|
107
|
+
instance.stats_engine.tl_record_unscoped_metrics(metric_name, value_to_store)
|
108
|
+
end
|
109
|
+
|
110
|
+
def increment_metric(metric_name, amount = 1) #THREAD_LOCAL_ACCESS
|
111
|
+
instance.stats_engine.tl_record_unscoped_metrics(metric_name) do |stats|
|
112
|
+
stats.increment_count(amount)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def drop_buffered_data
|
117
|
+
instance.drop_buffered_data
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_instrumentation(file_pattern)
|
121
|
+
OneApm::Probe.instance.add_instrumentation file_pattern
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_sql_obfuscator(type = :replace, &block)
|
125
|
+
OneApm::Agent::Database.set_sql_obfuscator(type, &block)
|
126
|
+
end
|
127
|
+
|
128
|
+
def disable_sql_recording
|
129
|
+
state = instance.set_record_sql(false)
|
130
|
+
begin
|
131
|
+
yield
|
132
|
+
ensure
|
133
|
+
instance.set_record_sql(state)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def disable_transaction_tracing
|
138
|
+
state = instance.set_record_tt(false)
|
139
|
+
begin
|
140
|
+
yield
|
141
|
+
ensure
|
142
|
+
instance.set_record_tt(state)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def ignore_transaction
|
147
|
+
txn = OneApm::Transaction.tl_current
|
148
|
+
txn.ignore! if txn
|
149
|
+
end
|
150
|
+
|
151
|
+
def ignore_apdex
|
152
|
+
txn = OneApm::Transaction.tl_current
|
153
|
+
txn.ignore_apdex! if txn
|
154
|
+
end
|
155
|
+
|
156
|
+
def ignore_enduser
|
157
|
+
txn = OneApm::Transaction.tl_current
|
158
|
+
txn.ignore_enduser! if txn
|
159
|
+
end
|
160
|
+
|
161
|
+
def disable_all_tracing
|
162
|
+
instance.push_trace_execution_flag(false)
|
163
|
+
yield
|
164
|
+
ensure
|
165
|
+
instance.pop_trace_execution_flag
|
166
|
+
end
|
167
|
+
|
168
|
+
def record_custom_event(event_type, event_attrs)
|
169
|
+
if instance && OneApm::Agent.config[:'custom_insights_events.enabled']
|
170
|
+
instance.custom_event_aggregator.record(event_type, event_attrs)
|
171
|
+
end
|
172
|
+
nil
|
173
|
+
end
|
174
|
+
|
175
|
+
def tl_is_execution_traced?
|
176
|
+
OneApm::TransactionState.tl_get.is_execution_traced?
|
177
|
+
end
|
178
|
+
|
179
|
+
def tl_is_transaction_traced?
|
180
|
+
OneApm::TransactionState.tl_get.is_transaction_traced?
|
181
|
+
end
|
182
|
+
|
183
|
+
def tl_is_sql_recorded?
|
184
|
+
OneApm::TransactionState.tl_get.is_sql_recorded?
|
185
|
+
end
|
186
|
+
|
187
|
+
def ignore_error_filter(&block)
|
188
|
+
if block
|
189
|
+
OneApm::Collector::ErrorCollector.ignore_error_filter = block
|
190
|
+
else
|
191
|
+
OneApm::Collector::ErrorCollector.ignore_error_filter
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def notice_error(exception, options = {})
|
196
|
+
Transaction.notice_error(exception, options)
|
197
|
+
nil
|
198
|
+
end
|
199
|
+
|
200
|
+
def notice_sql(sql, metric, config, elapsed_time, state, &explainer)
|
201
|
+
instance.transaction_sampler.notice_sql(sql, config, elapsed_time, state, &explainer)
|
202
|
+
instance.sql_sampler.notice_sql(sql, metric, config, elapsed_time, state, &explainer)
|
203
|
+
end
|
204
|
+
|
205
|
+
def add_custom_parameters(params) #THREAD_LOCAL_ACCESS
|
206
|
+
if params.is_a? Hash
|
207
|
+
txn = Transaction.tl_current
|
208
|
+
txn.add_custom_parameters(params) if txn
|
209
|
+
else
|
210
|
+
::OneApm::Agent.logger.warn("Bad argument passed to #add_custom_parameters. Expected Hash but got #{params.class}")
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def set_transaction_name(name, options={})
|
215
|
+
Transaction.set_overriding_transaction_name(name, options[:category])
|
216
|
+
end
|
217
|
+
|
218
|
+
def get_transaction_name #THREAD_LOCAL_ACCESS
|
219
|
+
txn = Transaction.tl_current
|
220
|
+
if txn
|
221
|
+
txn.best_name.sub(Regexp.new("\\A#{Regexp.escape(OneApm::TransactionNamer.prefix_for_category(txn))}"), '')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def with_database_metric_name(model, method, &block) #THREAD_LOCAL_ACCESS
|
226
|
+
if txn = Transaction.tl_current
|
227
|
+
txn.with_database_metric_name(model, method, &block)
|
228
|
+
else
|
229
|
+
yield
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def subscribe(event_type, &handler)
|
234
|
+
instance.events.subscribe( event_type, &handler )
|
235
|
+
end
|
236
|
+
|
237
|
+
def notify(event_type, *args)
|
238
|
+
instance.events.notify( event_type, *args )
|
239
|
+
rescue
|
240
|
+
OneApm::Agent.logger.debug "Ignoring exception during %p event notification" % [event_type]
|
241
|
+
end
|
242
|
+
|
243
|
+
def browser_timing_header
|
244
|
+
instance.javascript_instrumentor.browser_timing_header
|
245
|
+
end
|
246
|
+
|
247
|
+
def require_test_helper
|
248
|
+
path = File.join(__FILE__, '..', '..', '..', 'test', 'agent_helper')
|
249
|
+
require File.expand_path(path)
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'net/https'
|
5
|
+
require 'net/http'
|
6
|
+
require 'logger'
|
7
|
+
require 'zlib'
|
8
|
+
require 'stringio'
|
9
|
+
|
10
|
+
require 'one_apm/support/event_buffer/sampled_buffer'
|
11
|
+
require 'one_apm/configuration/autostart'
|
12
|
+
require 'one_apm/agent/harvester'
|
13
|
+
|
14
|
+
require 'one_apm/support/hostname'
|
15
|
+
require 'one_apm/support/environment_report'
|
16
|
+
|
17
|
+
require 'one_apm/configuration'
|
18
|
+
|
19
|
+
require 'one_apm/collector/collector_service'
|
20
|
+
require 'one_apm/collector/containers/agent_command_router'
|
21
|
+
require 'one_apm/collector/containers/transaction_event_aggregator'
|
22
|
+
require 'one_apm/collector/containers/custom_event_aggregator'
|
23
|
+
require 'one_apm/collector/containers/utilization_data'
|
24
|
+
|
25
|
+
require 'one_apm/agent/pipe/pipe_service'
|
26
|
+
require 'one_apm/agent/database'
|
27
|
+
require 'one_apm/agent/event/event_listener'
|
28
|
+
require 'one_apm/agent/cross_app/cross_app_monitor'
|
29
|
+
require 'one_apm/agent/synthetics_monitor'
|
30
|
+
require 'one_apm/support/event_buffer/synthetics_event_buffer'
|
31
|
+
require 'one_apm/agent/sampler_collection'
|
32
|
+
require 'one_apm/agent/javascript_instrumentor'
|
33
|
+
require 'one_apm/support/vm/monotonic_gc_profiler'
|
34
|
+
|
35
|
+
require 'one_apm/agent/agent/start'
|
36
|
+
require 'one_apm/agent/agent/start_worker_thread'
|
37
|
+
require 'one_apm/agent/agent/connect'
|
38
|
+
require 'one_apm/agent/agent/helpers'
|
39
|
+
require 'one_apm/agent/agent/container_data_manager'
|
40
|
+
require 'one_apm/agent/agent/forkable_dispatcher_functions'
|
41
|
+
|
42
|
+
module OneApm
|
43
|
+
module Agent
|
44
|
+
class Agent
|
45
|
+
include OneApm::Agent::Agent::Start
|
46
|
+
include OneApm::Agent::Agent::StartWorkerThread
|
47
|
+
include OneApm::Agent::Agent::Connect
|
48
|
+
include OneApm::Agent::Agent::Helpers
|
49
|
+
include OneApm::Agent::Agent::ContainerDataManager
|
50
|
+
include OneApm::Agent::Agent::ForkableDispatcherFunctions
|
51
|
+
|
52
|
+
# whether we should record raw, obfuscated, or no sql
|
53
|
+
attr_reader :record_sql
|
54
|
+
# builder for JS agent scripts to inject
|
55
|
+
attr_reader :javascript_instrumentor
|
56
|
+
# cross application tracing ids and encoding
|
57
|
+
attr_reader :cross_process_id
|
58
|
+
attr_reader :cross_app_encoding_bytes
|
59
|
+
attr_reader :cross_app_monitor
|
60
|
+
# service for communicating with collector
|
61
|
+
attr_accessor :service
|
62
|
+
# Global events dispatcher. This will provides our primary mechanism
|
63
|
+
# for agent-wide events, such as finishing configuration, error notification
|
64
|
+
# and request before/after from Rack.
|
65
|
+
attr_reader :events
|
66
|
+
# Transaction and metric renaming rules as provided by the
|
67
|
+
# collector on connect. The former are applied during txns,
|
68
|
+
# the latter during harvest.
|
69
|
+
attr_reader :transaction_rules
|
70
|
+
# Responsbile for restarting the harvest thread
|
71
|
+
attr_reader :harvester
|
72
|
+
attr_reader :harvest_samplers
|
73
|
+
attr_reader :harvest_lock
|
74
|
+
# GC::Profiler.total_time is not monotonic so we wrap it.
|
75
|
+
attr_reader :monotonic_gc_profiler
|
76
|
+
|
77
|
+
def self.instance
|
78
|
+
@instance ||= self.new
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.config
|
82
|
+
OneApm::Agent.config
|
83
|
+
end
|
84
|
+
|
85
|
+
def initialize
|
86
|
+
# This should be handled with a configuration callback
|
87
|
+
start_service_if_needed
|
88
|
+
|
89
|
+
@events = OneApm::Agent::EventListener.new
|
90
|
+
|
91
|
+
init_containers @events
|
92
|
+
OneApm::Agent::SyntheticsMonitor.new @events
|
93
|
+
|
94
|
+
@cross_app_monitor = OneApm::Agent::CrossAppMonitor.new(@events)
|
95
|
+
@transaction_rules = OneApm::Support::RulesEngine.new
|
96
|
+
@harvest_samplers = OneApm::Agent::SamplerCollection.new(@events)
|
97
|
+
@monotonic_gc_profiler = OneApm::Support::VM::MonotonicGCProfiler.new
|
98
|
+
@javascript_instrumentor = OneApm::Agent::JavascriptInstrumentor.new(@events)
|
99
|
+
|
100
|
+
@harvester = OneApm::Agent::Harvester.new(@events)
|
101
|
+
@after_fork_lock = Mutex.new
|
102
|
+
|
103
|
+
@connect_state = :pending
|
104
|
+
@connect_attempts = 0
|
105
|
+
@environment_report = nil
|
106
|
+
|
107
|
+
@harvest_lock = Mutex.new
|
108
|
+
end
|
109
|
+
|
110
|
+
def probe
|
111
|
+
OneApm::Probe.instance
|
112
|
+
end
|
113
|
+
|
114
|
+
def start_service_if_needed
|
115
|
+
if Agent.config[:monitor_mode] && !@service
|
116
|
+
@service = OneApm::Collector::CollectorService.new
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def start
|
121
|
+
return unless agent_should_start?
|
122
|
+
|
123
|
+
log_startup
|
124
|
+
check_config_and_start_agent
|
125
|
+
log_version_and_pid
|
126
|
+
|
127
|
+
events.subscribe(:finished_configuring) do
|
128
|
+
log_ignore_url_regexes
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Attempt a graceful shutdown of the agent, running the worker
|
133
|
+
# loop if it exists and is running.
|
134
|
+
#
|
135
|
+
# Options:
|
136
|
+
# :force_send => (true/false) # force the agent to send data
|
137
|
+
def shutdown(options={})
|
138
|
+
return if not started?
|
139
|
+
::OneApm::Agent.logger.info "Starting Agent shutdown"
|
140
|
+
|
141
|
+
stop_event_loop
|
142
|
+
untraced_graceful_disconnect
|
143
|
+
OneApm::Agent.revert_to_default_configuration
|
144
|
+
|
145
|
+
@started = nil
|
146
|
+
OneApm::Probe.reset
|
147
|
+
end
|
148
|
+
|
149
|
+
# Check to see if the agent should start, returning +true+ if it should.
|
150
|
+
def agent_should_start?
|
151
|
+
return false if already_started? || disabled? || defer_for_background_jobs?
|
152
|
+
|
153
|
+
unless app_name_configured?
|
154
|
+
OneApm::Agent.logger.error "No application name configured.",
|
155
|
+
"The Agent cannot start without at least one. Please check your ",
|
156
|
+
"oneapm.yml and ensure that it is valid and has at least one ",
|
157
|
+
"value set for app_name in the #{probe.env} ",
|
158
|
+
"environment."
|
159
|
+
return false
|
160
|
+
end
|
161
|
+
|
162
|
+
true
|
163
|
+
end
|
164
|
+
|
165
|
+
# Connect to the server and validate the license. If successful,
|
166
|
+
# connected? returns true when finished. If not successful, you can
|
167
|
+
# keep calling this. Return false if we could not establish a
|
168
|
+
# connection with the server and we should not retry, such as if
|
169
|
+
# there's a bad license key.
|
170
|
+
#
|
171
|
+
# Set keep_retrying=false to disable retrying and return asap, such as when
|
172
|
+
# invoked in the foreground. Otherwise this runs until a successful
|
173
|
+
# connection is made, or the server rejects us.
|
174
|
+
#
|
175
|
+
# * <tt>:keep_retrying => false</tt> to only try to connect once, and
|
176
|
+
# return with the connection set to nil. This ensures we may try again
|
177
|
+
# later (default true).
|
178
|
+
# * <tt>force_reconnect => true</tt> if you want to establish a new connection
|
179
|
+
# to the server before running the worker loop. This means you get a separate
|
180
|
+
# agent run and OneApm sees it as a separate instance (default is false).
|
181
|
+
def connect(options={})
|
182
|
+
begin
|
183
|
+
defaults = {
|
184
|
+
:keep_retrying => Agent.config[:keep_retrying],
|
185
|
+
:force_reconnect => Agent.config[:force_reconnect]
|
186
|
+
}
|
187
|
+
opts = defaults.merge(options)
|
188
|
+
|
189
|
+
return unless should_connect?(opts[:force_reconnect])
|
190
|
+
|
191
|
+
::OneApm::Agent.logger.debug "Connecting Process to OneApm: #$0"
|
192
|
+
query_server_for_configuration
|
193
|
+
@connected_pid = Process.pid
|
194
|
+
@connect_state = :connected
|
195
|
+
rescue OneApm::ForceDisconnectException => e
|
196
|
+
handle_force_disconnect(e)
|
197
|
+
rescue OneApm::LicenseException => e
|
198
|
+
handle_license_error(e)
|
199
|
+
rescue OneApm::UnrecoverableAgentException => e
|
200
|
+
handle_unrecoverable_agent_error(e)
|
201
|
+
rescue StandardError, Timeout::Error, OneApm::ServerConnectionException => e
|
202
|
+
log_error(e)
|
203
|
+
if opts[:keep_retrying]
|
204
|
+
note_connect_failure
|
205
|
+
::OneApm::Agent.logger.info "Will re-attempt in #{connect_retry_period} seconds"
|
206
|
+
sleep connect_retry_period
|
207
|
+
retry
|
208
|
+
else
|
209
|
+
disconnect
|
210
|
+
end
|
211
|
+
rescue Exception => e
|
212
|
+
::OneApm::Agent.logger.error "Exception of unexpected type during Agent#connect():", e
|
213
|
+
|
214
|
+
raise
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# This method contacts the server to send remaining data and
|
219
|
+
# let the server know that the agent is shutting down - this
|
220
|
+
# allows us to do things like accurately set the end of the
|
221
|
+
# lifetime of the process
|
222
|
+
#
|
223
|
+
# If this process comes from a parent process, it will not
|
224
|
+
# disconnect, so that the parent process can continue to send data
|
225
|
+
def graceful_disconnect
|
226
|
+
if connected?
|
227
|
+
begin
|
228
|
+
@service.request_timeout = 10
|
229
|
+
|
230
|
+
@events.notify(:before_shutdown)
|
231
|
+
transmit_data
|
232
|
+
transmit_event_data
|
233
|
+
transmit_utilization_data if OneApm::Agent.config[:collect_utilization]
|
234
|
+
|
235
|
+
if @connected_pid == $$ && !@service.kind_of?(OneApm::Collector::CollectorService)
|
236
|
+
::OneApm::Agent.logger.debug "Sending OneApm service agent run shutdown message"
|
237
|
+
@service.shutdown(Time.now.to_f)
|
238
|
+
else
|
239
|
+
::OneApm::Agent.logger.debug "This agent connected from parent process #{@connected_pid}--not sending shutdown"
|
240
|
+
end
|
241
|
+
::OneApm::Agent.logger.debug "Graceful disconnect complete"
|
242
|
+
rescue Timeout::Error, StandardError => e
|
243
|
+
::OneApm::Agent.logger.debug "Error when disconnecting #{e.class.name}: #{e.message}"
|
244
|
+
end
|
245
|
+
else
|
246
|
+
::OneApm::Agent.logger.debug "Bypassing graceful disconnect - agent not connected"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def untraced_graceful_disconnect
|
251
|
+
begin
|
252
|
+
OneApm::Agent.disable_all_tracing do
|
253
|
+
graceful_disconnect
|
254
|
+
end
|
255
|
+
rescue => e
|
256
|
+
::OneApm::Agent.logger.error e
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
class ShimAgent < OneApm::Agent::Agent
|
262
|
+
def self.instance
|
263
|
+
@instance ||= self.new
|
264
|
+
end
|
265
|
+
|
266
|
+
def initialize
|
267
|
+
super
|
268
|
+
@stats_engine.extend OneApm::Collector::StatsEngine::Shim
|
269
|
+
@transaction_sampler.extend OneApm::Collector::TransactionSampler::Shim
|
270
|
+
@sql_sampler.extend OneApm::Collector::SqlSampler::Shim
|
271
|
+
@error_collector.extend OneApm::Collector::ErrorCollector::Shim
|
272
|
+
end
|
273
|
+
|
274
|
+
def after_fork *args; end
|
275
|
+
def start *args; end
|
276
|
+
def shutdown *args; end
|
277
|
+
def merge_data_for_endpoint *args; end
|
278
|
+
def push_trace_execution_flag *args; end
|
279
|
+
def pop_trace_execution_flag *args; end
|
280
|
+
def browser_timing_header; "" end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|