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,132 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
class Transaction
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def start_new_transaction(state, category, options)
|
9
|
+
txn = Transaction.new(category, options)
|
10
|
+
state.reset(txn)
|
11
|
+
txn.start(state)
|
12
|
+
txn
|
13
|
+
end
|
14
|
+
|
15
|
+
def start(state, category, options)
|
16
|
+
category ||= :controller
|
17
|
+
txn = state.current_transaction
|
18
|
+
|
19
|
+
if txn
|
20
|
+
txn.create_nested_frame(state, category, options)
|
21
|
+
else
|
22
|
+
txn = start_new_transaction(state, category, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
txn
|
26
|
+
rescue => e
|
27
|
+
OneApm::Agent.logger.error("Exception during Transaction.start", e)
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def stop(state, end_time=Time.now)
|
32
|
+
txn = state.current_transaction
|
33
|
+
|
34
|
+
if txn.nil?
|
35
|
+
OneApm::Agent.logger.error(Transaction::FAILED_TO_STOP_MESSAGE)
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
nested_frame = txn.frame_stack.pop
|
40
|
+
|
41
|
+
if txn.frame_stack.empty?
|
42
|
+
txn.stop(state, end_time, nested_frame)
|
43
|
+
state.reset
|
44
|
+
else
|
45
|
+
nested_name = nested_transaction_name(nested_frame.name)
|
46
|
+
|
47
|
+
if nested_name.start_with?(Transaction::MIDDLEWARE_PREFIX)
|
48
|
+
summary_metrics = Transaction::MIDDLEWARE_SUMMARY_METRICS
|
49
|
+
else
|
50
|
+
summary_metrics = Transaction::EMPTY_SUMMARY_METRICS
|
51
|
+
end
|
52
|
+
|
53
|
+
OneApm::Support::MethodTracer::Helpers.trace_execution_scoped_footer(
|
54
|
+
state,
|
55
|
+
nested_frame.start_time.to_f,
|
56
|
+
nested_name,
|
57
|
+
summary_metrics,
|
58
|
+
nested_frame,
|
59
|
+
Transaction::NESTED_TRACE_STOP_OPTIONS,
|
60
|
+
end_time.to_f)
|
61
|
+
end
|
62
|
+
|
63
|
+
:transaction_stopped
|
64
|
+
rescue => e
|
65
|
+
state.reset
|
66
|
+
OneApm::Agent.logger.error("Exception during Transaction.stop", e)
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def wrap(state, name, category, options = {})
|
71
|
+
Transaction.start(state, category, options.merge(:transaction_name => name))
|
72
|
+
begin
|
73
|
+
yield
|
74
|
+
rescue => e
|
75
|
+
Transaction.notice_error(e)
|
76
|
+
raise e
|
77
|
+
ensure
|
78
|
+
Transaction.stop(state)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def nested_transaction_name(name)
|
83
|
+
if name.start_with?(Transaction::CONTROLLER_PREFIX) || name.start_with?(Transaction::OTHER_TRANSACTION_PREFIX)
|
84
|
+
"#{Transaction::SUBTRANSACTION_PREFIX}#{name}"
|
85
|
+
else
|
86
|
+
name
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# * duration: response time
|
92
|
+
# * failed: the request is failed or not
|
93
|
+
# * apdex_s: satisfy
|
94
|
+
# * apdex_t: tolerate
|
95
|
+
# * apdex_f: frustrate
|
96
|
+
#
|
97
|
+
def apdex_bucket(duration, failed, apdex_t)
|
98
|
+
case
|
99
|
+
when failed
|
100
|
+
:apdex_f # frustrate if request failed
|
101
|
+
when duration <= apdex_t
|
102
|
+
:apdex_s # satisfy if duration < tolerate
|
103
|
+
when duration <= 4 * apdex_t
|
104
|
+
:apdex_t # tolerate if duration < 4 * tolerate
|
105
|
+
else
|
106
|
+
:apdex_f # otherwise frustrate
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Make a safe attempt to get the URI, without the host and query string.
|
111
|
+
def uri_from_request(req)
|
112
|
+
approximate_uri = case
|
113
|
+
when req.respond_to?(:fullpath ) then req.fullpath
|
114
|
+
when req.respond_to?(:path ) then req.path
|
115
|
+
when req.respond_to?(:request_uri) then req.request_uri
|
116
|
+
when req.respond_to?(:uri ) then req.uri
|
117
|
+
when req.respond_to?(:url ) then req.url
|
118
|
+
end
|
119
|
+
return approximate_uri[%r{^(https?://.*?)?(/[^?]*)}, 2] || '/' if approximate_uri
|
120
|
+
end
|
121
|
+
|
122
|
+
# Make a safe attempt to get the referer from a request object, generally successful when
|
123
|
+
# it's a Rack request.
|
124
|
+
def referer_from_request(req)
|
125
|
+
if req && req.respond_to?(:referer)
|
126
|
+
req.referer.to_s.split('?').first
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
class Transaction
|
5
|
+
module InstanceHelpers
|
6
|
+
|
7
|
+
def agent
|
8
|
+
OneApm::Agent.instance
|
9
|
+
end
|
10
|
+
|
11
|
+
def transaction_sampler
|
12
|
+
agent.transaction_sampler
|
13
|
+
end
|
14
|
+
|
15
|
+
def sql_sampler
|
16
|
+
agent.sql_sampler
|
17
|
+
end
|
18
|
+
|
19
|
+
def recording_web_transaction?
|
20
|
+
web_category?(@category)
|
21
|
+
end
|
22
|
+
|
23
|
+
def web_category?(category)
|
24
|
+
Transaction::WEB_TRANSACTION_CATEGORIES.include?(category)
|
25
|
+
end
|
26
|
+
|
27
|
+
def similar_category?(category)
|
28
|
+
web_category?(@category) == web_category?(category)
|
29
|
+
end
|
30
|
+
|
31
|
+
def queue_time
|
32
|
+
@apdex_start ? @start_time - @apdex_start : 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def had_error?
|
36
|
+
!notable_exceptions.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def notable_exceptions
|
40
|
+
@exceptions.keys.select do |exception|
|
41
|
+
!agent.error_collector.error_is_ignored?(exception)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_custom_parameters(p)
|
46
|
+
if OneApm::Agent.config[:high_security]
|
47
|
+
OneApm::Agent.logger.debug("Unable to add custom attributes #{p.keys.inspect} while in high security mode.")
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
custom_parameters.merge!(p)
|
52
|
+
end
|
53
|
+
|
54
|
+
# For the current web transaction, return the path of the URI minus the host part and query string, or nil.
|
55
|
+
def uri
|
56
|
+
@uri ||= self.class.uri_from_request(@request) unless @request.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
# For the current web transaction, return the full referer, minus the host string, or nil.
|
60
|
+
def referer
|
61
|
+
@referer ||= self.class.referer_from_request(@request)
|
62
|
+
end
|
63
|
+
|
64
|
+
def custom_parameters
|
65
|
+
@custom_parameters ||= {}
|
66
|
+
end
|
67
|
+
|
68
|
+
HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
|
69
|
+
GUID_LENGTH = 16
|
70
|
+
|
71
|
+
# generate a random 64 bit uuid
|
72
|
+
def generate_guid
|
73
|
+
guid = ''
|
74
|
+
GUID_LENGTH.times do |a|
|
75
|
+
guid << HEX_DIGITS[rand(16)]
|
76
|
+
end
|
77
|
+
guid
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
class Transaction
|
5
|
+
|
6
|
+
SUBTRANSACTION_PREFIX = 'Nested/'.freeze
|
7
|
+
CONTROLLER_PREFIX = 'Controller/'.freeze
|
8
|
+
MIDDLEWARE_PREFIX = 'Middleware/Rack/'.freeze
|
9
|
+
TASK_PREFIX = 'OtherTransaction/Background/'.freeze
|
10
|
+
RACK_PREFIX = 'Controller/Rack/'.freeze
|
11
|
+
SINATRA_PREFIX = 'Controller/Sinatra/'.freeze
|
12
|
+
GRAPE_PREFIX = 'Controller/Grape/'.freeze
|
13
|
+
OTHER_TRANSACTION_PREFIX = 'OtherTransaction/'.freeze
|
14
|
+
|
15
|
+
CONTROLLER_MIDDLEWARE_PREFIX = 'Controller/Middleware/Rack'.freeze
|
16
|
+
|
17
|
+
WEB_SUMMARY_METRIC = 'HttpDispatcher'.freeze
|
18
|
+
OTHER_SUMMARY_METRIC = 'OtherTransaction/all'.freeze
|
19
|
+
|
20
|
+
APDEX_S = 'S'.freeze
|
21
|
+
APDEX_T = 'T'.freeze
|
22
|
+
APDEX_F = 'F'.freeze
|
23
|
+
APDEX_METRIC = 'Apdex'.freeze
|
24
|
+
|
25
|
+
QUEUE_TIME_METRIC = 'WebFrontend/QueueTime'.freeze
|
26
|
+
|
27
|
+
NESTED_TRACE_STOP_OPTIONS = { :metric => true }.freeze
|
28
|
+
WEB_TRANSACTION_CATEGORIES = [:controller, :uri, :rack, :sinatra, :grape, :middleware].freeze
|
29
|
+
TRANSACTION_NAMING_SOURCES = [:child, :api].freeze
|
30
|
+
|
31
|
+
MIDDLEWARE_SUMMARY_METRICS = ['Middleware/all'.freeze].freeze
|
32
|
+
EMPTY_SUMMARY_METRICS = [].freeze
|
33
|
+
|
34
|
+
TRACE_OPTIONS_SCOPED = {:metric => true, :scoped_metric => true}.freeze
|
35
|
+
TRACE_OPTIONS_UNSCOPED = {:metric => true, :scoped_metric => false}.freeze
|
36
|
+
|
37
|
+
UNKNOWN_METRIC = '(unknown)'.freeze
|
38
|
+
|
39
|
+
FAILED_TO_STOP_MESSAGE = "Failed during Transaction.stop because there is no current transaction"
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/transaction/sample_buffer/transaction_sample_buffer'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
class Transaction
|
7
|
+
class ForcePersistSampleBuffer < TransactionSampleBuffer
|
8
|
+
|
9
|
+
CAPACITY = 10
|
10
|
+
|
11
|
+
def capacity
|
12
|
+
CAPACITY
|
13
|
+
end
|
14
|
+
|
15
|
+
def allow_sample?(sample)
|
16
|
+
sample.force_persist
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/transaction/sample_buffer/transaction_sample_buffer'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
class Transaction
|
7
|
+
class SlowestSampleBuffer < TransactionSampleBuffer
|
8
|
+
|
9
|
+
CAPACITY = 1
|
10
|
+
|
11
|
+
def capacity
|
12
|
+
CAPACITY
|
13
|
+
end
|
14
|
+
|
15
|
+
def allow_sample?(sample)
|
16
|
+
sample.threshold && sample.duration >= sample.threshold
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/transaction/sample_buffer/transaction_sample_buffer'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
class Transaction
|
7
|
+
class SyntheticsSampleBuffer < TransactionSampleBuffer
|
8
|
+
def capacity
|
9
|
+
OneApm::Agent.config[:'synthetics.traces_limit']
|
10
|
+
end
|
11
|
+
|
12
|
+
def allow_sample?(sample)
|
13
|
+
sample.synthetics_resource_id != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def truncate_samples
|
17
|
+
@samples.slice!(max_capacity..-1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module OneApm
|
4
|
+
class Transaction
|
5
|
+
class TransactionSampleBuffer
|
6
|
+
attr_reader :samples
|
7
|
+
|
8
|
+
SINGLE_BUFFER_MAX = 20
|
9
|
+
NO_SAMPLES = [].freeze
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@samples = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def enabled?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset!
|
20
|
+
@samples = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def harvest_samples
|
24
|
+
@samples
|
25
|
+
ensure
|
26
|
+
reset!
|
27
|
+
end
|
28
|
+
|
29
|
+
def allow_sample?(sample)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def store(sample)
|
34
|
+
return unless enabled?
|
35
|
+
if allow_sample?(sample)
|
36
|
+
add_sample(sample)
|
37
|
+
truncate_samples_if_needed
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def store_previous(previous_samples)
|
42
|
+
return unless enabled?
|
43
|
+
previous_samples.each do |sample|
|
44
|
+
add_sample(sample) if allow_sample?(sample)
|
45
|
+
end
|
46
|
+
truncate_samples_if_needed
|
47
|
+
end
|
48
|
+
|
49
|
+
def truncate_samples_if_needed
|
50
|
+
truncate_samples if full?
|
51
|
+
end
|
52
|
+
|
53
|
+
def full?
|
54
|
+
@samples.length >= max_capacity
|
55
|
+
end
|
56
|
+
|
57
|
+
# Capacity is the desired number of samples a buffer will hold. This
|
58
|
+
# can be user dictated via config if a feature wants.
|
59
|
+
#
|
60
|
+
# This value will be forcibly capped by the max_capacity
|
61
|
+
def capacity
|
62
|
+
raise NotImplementedError.new("TransactionSampleBuffer subclasses must provide a capacity override")
|
63
|
+
end
|
64
|
+
|
65
|
+
# Apply hard upper limit to the capacity to prevent users from
|
66
|
+
# consuming too much memory buffering TT's.
|
67
|
+
#
|
68
|
+
# A typical buffer should NOT override this method (although we do for
|
69
|
+
# odd things like dev-mode)
|
70
|
+
def max_capacity
|
71
|
+
capacity > SINGLE_BUFFER_MAX ? SINGLE_BUFFER_MAX : capacity
|
72
|
+
end
|
73
|
+
|
74
|
+
# Our default truncation strategy is to keep max_capacity
|
75
|
+
# worth of the longest samples. Override this method for alternate
|
76
|
+
# behavior.
|
77
|
+
#
|
78
|
+
# This doesn't use the more convenient #last and #sort_by to avoid
|
79
|
+
# additional array allocations (and abundant alliteration)
|
80
|
+
def truncate_samples
|
81
|
+
@samples.sort!{|a,b| a.duration <=> b.duration}
|
82
|
+
@samples.slice!(0..-(max_capacity + 1))
|
83
|
+
end
|
84
|
+
|
85
|
+
# When pushing a scope different sample buffers potentially want to
|
86
|
+
# know about what's happening to annotate the incoming segments
|
87
|
+
def visit_segment(*)
|
88
|
+
# no-op
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
# If a buffer needs to modify an added sample, override this method.
|
94
|
+
# Bounds checking, allowing samples and truncation belongs elsewhere.
|
95
|
+
def add_sample(sample)
|
96
|
+
@samples << sample
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'one_apm/transaction/sample_buffer/transaction_sample_buffer'
|
4
|
+
|
5
|
+
module OneApm
|
6
|
+
class Transaction
|
7
|
+
class XraySampleBuffer < TransactionSampleBuffer
|
8
|
+
|
9
|
+
attr_writer :xray_session_collection
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
|
14
|
+
# Memoize the config setting since this happens per request
|
15
|
+
@enabled = OneApm::Agent.config[:'xray_session.allow_traces']
|
16
|
+
OneApm::Agent.config.register_callback(:'xray_session.allow_traces') do |new_value|
|
17
|
+
@enabled = new_value
|
18
|
+
end
|
19
|
+
|
20
|
+
@capacity = OneApm::Agent.config[:'xray_session.max_samples']
|
21
|
+
OneApm::Agent.config.register_callback(:'xray_session.max_samples') do |new_value|
|
22
|
+
@capacity = new_value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def xray_session_collection
|
27
|
+
@xray_session_collection ||= OneApm::Agent.instance.agent_command_router.xray_session_collection
|
28
|
+
end
|
29
|
+
|
30
|
+
def capacity
|
31
|
+
@capacity
|
32
|
+
end
|
33
|
+
|
34
|
+
def truncate_samples
|
35
|
+
# First in wins, so stop on allow_sample? instead of truncating
|
36
|
+
end
|
37
|
+
|
38
|
+
def allow_sample?(sample)
|
39
|
+
!full? && !lookup_session_id(sample).nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def enabled?
|
43
|
+
@enabled
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def add_sample(sample)
|
50
|
+
super(sample)
|
51
|
+
sample.xray_session_id = lookup_session_id(sample)
|
52
|
+
end
|
53
|
+
|
54
|
+
def lookup_session_id(sample)
|
55
|
+
xray_session_collection.session_id_for_transaction_name(sample.transaction_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|