Class: OneApm::Transaction
- Inherits:
-
Object
- Object
- OneApm::Transaction
- Extended by:
- ThreadLocalAccess
- Includes:
- InstanceHelpers, TransactionFinishAppend, TransactionIgnore, TransactionName, TransactionSynthetics
- Defined in:
- lib/one_apm/transaction.rb,
lib/one_apm/transaction/class_methods.rb,
lib/one_apm/transaction/transaction_cpu.rb,
lib/one_apm/transaction/instance_helpers.rb,
lib/one_apm/transaction/metric_constants.rb,
lib/one_apm/transaction/transaction_name.rb,
lib/one_apm/transaction/transaction_apdex.rb,
lib/one_apm/transaction/transaction_ignore.rb,
lib/one_apm/transaction/thread_local_access.rb,
lib/one_apm/transaction/transaction_summary.rb,
lib/one_apm/transaction/transaction_synthetics.rb,
lib/one_apm/transaction/transaction_finish_append.rb,
lib/one_apm/transaction/transaction_jruby_functions.rb,
lib/one_apm/transaction/sample_buffer/xray_sample_buffer.rb,
lib/one_apm/transaction/sample_buffer/slowest_sample_buffer.rb,
lib/one_apm/transaction/sample_buffer/synthetics_sample_buffer.rb,
lib/one_apm/transaction/sample_buffer/transaction_sample_buffer.rb,
lib/one_apm/transaction/sample_buffer/force_persist_sample_buffer.rb,
lib/one_apm/transaction/sample_buffer/developer_mode_sample_buffer.rb
Defined Under Namespace
Modules: InstanceHelpers, ThreadLocalAccess, TransactionFinishAppend, TransactionIgnore, TransactionName, TransactionSynthetics Classes: DeveloperModeSampleBuffer, ForcePersistSampleBuffer, SlowestSampleBuffer, SyntheticsSampleBuffer, TransactionSampleBuffer, XraySampleBuffer
Constant Summary collapse
- OA_SUBTRANSACTION_PREFIX =
'Nested/'.freeze
- OA_CONTROLLER_PREFIX =
'Controller/'.freeze
- OA_MIDDLEWARE_PREFIX =
'Middleware/Rack/'.freeze
- OA_TASK_PREFIX =
'OtherTransaction/Background/'.freeze
- OA_RACK_PREFIX =
'WebTransaction/Rack/'.freeze
- OA_SINATRA_PREFIX =
'WebTransaction/Sinatra/'.freeze
- OA_GRAPE_PREFIX =
'WebTransaction/Grape/'.freeze
- OA_OTHER_TRANSACTION_PREFIX =
'OtherTransaction/'.freeze
- OA_WEB_TRANSACTION_PREFIX =
'WebTransaction/'.freeze
- OA_CONTROLLER_OA_MIDDLEWARE_PREFIX =
'Controller/Middleware/Rack'.freeze
- OA_WEB_SUMMARY_METRIC =
'WebTransaction'.freeze
- OA_OTHER_SUMMARY_METRIC =
'OtherTransaction/all'.freeze
- OA_APDEX_S =
'S'.freeze
- OA_APDEX_T =
'T'.freeze
- OA_APDEX_F =
'F'.freeze
- OA_APDEX_METRIC =
'Apdex'.freeze
- OA_QUEUE_TIME_METRIC =
'WebFrontend/QueueTime'.freeze
- OA_NESTED_TRACE_STOP_OPTIONS =
{ :metric => true }.freeze
- OA_WEB_TRANSACTION_CATEGORIES =
[:controller, :uri, :rack, :sinatra, :grape, :middleware].freeze
- OA_TRANSACTION_NAMING_SOURCES =
[:child, :api].freeze
- OA_MIDDLEWARE_SUMMARY_METRICS =
['Middleware/all'.freeze].freeze
- OA_EMPTY_SUMMARY_METRICS =
[].freeze
- OA_TRACE_OPTIONS_SCOPED =
{:metric => true, :scoped_metric => true}.freeze
- OA_TRACE_OPTIONS_UNSCOPED =
{:metric => true, :scoped_metric => false}.freeze
- OA_TRACE_IGNORE_OPTIONS =
{:metric => false}.freeze
- OA_UNKNOWN_METRIC =
'(unknown)'.freeze
- OA_FAILED_TO_STOP_MESSAGE =
"Failed during Transaction.stop because there is no current transaction"
- OA_JRUBY_CPU_TIME_ERROR =
"Error calculating JRuby CPU Time".freeze
- @@java_classes_loaded =
false
Constants included from InstanceHelpers
InstanceHelpers::GUID_LENGTH, InstanceHelpers::HEX_DIGITS
Instance Attribute Summary collapse
-
#apdex_start ⇒ Object
Returns the value of attribute apdex_start.
-
#cat_path_hashes ⇒ Object
readonly
Returns the value of attribute cat_path_hashes.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#database_metric_name ⇒ Object
readonly
Returns the value of attribute database_metric_name.
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#filtered_params ⇒ Object
Returns the value of attribute filtered_params.
-
#frame_stack ⇒ Object
readonly
Returns the value of attribute frame_stack.
-
#gc_start_snapshot ⇒ Object
readonly
Returns the value of attribute gc_start_snapshot.
-
#guid ⇒ Object
readonly
Returns the value of attribute guid.
-
#http_response_code ⇒ Object
Returns the value of attribute http_response_code.
-
#ignore_frames ⇒ Object
Returns the value of attribute ignore_frames.
-
#jruby_cpu_start ⇒ Object
Returns the value of attribute jruby_cpu_start.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#process_cpu_start ⇒ Object
Returns the value of attribute process_cpu_start.
-
#request ⇒ Object
Returns the value of attribute request.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#transaction_trace ⇒ Object
readonly
Returns the value of attribute transaction_trace.
Attributes included from TransactionSynthetics
#raw_synthetics_header, #synthetics_payload
Class Method Summary collapse
-
.apdex_bucket(duration, failed, apdex_t) ⇒ Object
-
duration: response time * failed: the request is failed or not * apdex_s: satisfy * apdex_t: tolerate * apdex_f: frustrate.
-
- .nested_transaction_name(name) ⇒ Object
-
.referer_from_request(req) ⇒ Object
Make a safe attempt to get the referer from a request object, generally successful when it’s a Rack request.
- .start(state, category, options) ⇒ Object
- .start_new_transaction(state, category, options) ⇒ Object
- .stop(state, end_time = Time.now) ⇒ Object
-
.uri_from_request(req) ⇒ Object
Make a safe attempt to get the URI, without the host and query string.
- .wrap(state, name, category, options = {}) ⇒ Object
Instance Method Summary collapse
-
#abort_transaction!(state) ⇒ Object
Call this to ensure that the current transaction is not saved.
- #apdex_bucket(duration) ⇒ Object
- #apdex_t ⇒ Object
- #background_summary_metrics ⇒ Object
- #cat_path_hash(state) ⇒ Object
- #cat_referring_path_hash(state) ⇒ Object
- #cat_trip_id(state) ⇒ Object
- #commit!(state, end_time, outermost_segment_name) ⇒ Object
- #cpu_burn ⇒ Object
- #create_nested_frame(state, category, options) ⇒ Object
- #ignore_frame?(tx_name) ⇒ Boolean
-
#initialize(category, options) ⇒ Transaction
constructor
A new instance of Transaction.
- #instrumentation_state ⇒ Object
- #jruby_cpu_burn ⇒ Object
- #jruby_cpu_time ⇒ Object
- #merge_metrics ⇒ Object
- #needs_middleware_summary_metrics?(name) ⇒ Boolean
- #normal_cpu_burn ⇒ Object
-
#notice_error(error, options = {}) ⇒ Object
Do not call this.
- #noticed_error_ids ⇒ Object
- #process_cpu ⇒ Object
- #record_apdex(state, end_time = Time.now) ⇒ Object
- #record_cat_path_hash(hash) ⇒ Object
- #record_exceptions ⇒ Object
- #record_gc(state, end_time) ⇒ Object
- #record_queue_time ⇒ Object
-
#record_summary_metrics(outermost_segment_name, end_time) ⇒ Object
The summary metrics recorded by this method all end up with a duration equal to the transaction itself, and an exclusive time of zero.
- #record_transaction_cpu(state) ⇒ Object
-
#send_transaction_finished_event(state, start_time, end_time) ⇒ Object
This event is fired when the transaction is fully completed.
- #start(state) ⇒ Object
- #stop(state, end_time, outermost_frame) ⇒ Object
- #summary_metrics ⇒ Object
- #transaction_specific_apdex_t ⇒ Object
- #user_defined_rules_ignore? ⇒ Boolean
Methods included from ThreadLocalAccess
extract_request_options, recording_web_transaction?, set_default_transaction_name, set_overriding_transaction_name, tl_current
Methods included from InstanceHelpers
#add_custom_parameters, #agent, #custom_parameters, #generate_guid, #had_error?, #notable_exceptions, #queue_time, #recording_web_transaction?, #referer, #similar_category?, #sql_sampler, #transaction_sampler, #uri, #web_category?
Methods included from TransactionFinishAppend
#append_apdex_perf_zone, #append_cat_info, #append_http_response_code, #append_referring_transaction_guid_to, #append_synthetics_to, #include_guid?
Methods included from TransactionName
#best_name, #default_name=, #filter, #freeze_name_and_execute_if_not_ignored, #frozen_name=, #influences_transaction_name?, #log_frozen_name, #make_transaction_name, #name_frozen?, #name_last_frame, #name_set?, #overridden_name=, #promoted_transaction_name, #set_default_transaction_name, #set_overriding_transaction_name
Methods included from TransactionIgnore
#ignore!, #ignore?, #ignore_apdex!, #ignore_apdex?, #ignore_enduser!, #ignore_enduser?
Methods included from TransactionSynthetics
#is_synthetics_request?, #synthetics_account_id, #synthetics_job_id, #synthetics_monitor_id, #synthetics_resource_id, #synthetics_version
Constructor Details
#initialize(category, options) ⇒ Transaction
Returns a new instance of Transaction.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/one_apm/transaction.rb', line 49 def initialize(category, ) @frame_stack = [] @has_children = false self.default_name = [:transaction_name] @overridden_name = nil @frozen_name = nil @category = category @start_time = Time.now @apdex_start = [:apdex_start_time] || @start_time @jruby_cpu_start = jruby_cpu_time @process_cpu_start = process_cpu @gc_start_snapshot = OneApm::Collector::StatsEngine::GCProfiler.take_snapshot @filtered_params = [:filtered_params] || {} @request = [:request] @exceptions = {} @metrics = TransactionMetrics.new @guid = generate_guid @cat_path_hashes = nil @ignore_this_transaction = false @ignore_apdex = false @ignore_enduser = false @ignore_frames = [:ignore_frames] || [] end |
Instance Attribute Details
#apdex_start ⇒ Object
Returns the value of attribute apdex_start.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def apdex_start @apdex_start end |
#cat_path_hashes ⇒ Object (readonly)
Returns the value of attribute cat_path_hashes.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def cat_path_hashes @cat_path_hashes end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def category @category end |
#database_metric_name ⇒ Object (readonly)
Returns the value of attribute database_metric_name.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def database_metric_name @database_metric_name end |
#exceptions ⇒ Object
Returns the value of attribute exceptions.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def exceptions @exceptions end |
#filtered_params ⇒ Object
Returns the value of attribute filtered_params.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def filtered_params @filtered_params end |
#frame_stack ⇒ Object (readonly)
Returns the value of attribute frame_stack.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def frame_stack @frame_stack end |
#gc_start_snapshot ⇒ Object (readonly)
Returns the value of attribute gc_start_snapshot.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def gc_start_snapshot @gc_start_snapshot end |
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def guid @guid end |
#http_response_code ⇒ Object
Returns the value of attribute http_response_code.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def http_response_code @http_response_code end |
#ignore_frames ⇒ Object
Returns the value of attribute ignore_frames.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def ignore_frames @ignore_frames end |
#jruby_cpu_start ⇒ Object
Returns the value of attribute jruby_cpu_start.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def jruby_cpu_start @jruby_cpu_start end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def metrics @metrics end |
#process_cpu_start ⇒ Object
Returns the value of attribute process_cpu_start.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def process_cpu_start @process_cpu_start end |
#request ⇒ Object
Returns the value of attribute request.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def request @request end |
#start_time ⇒ Object
Returns the value of attribute start_time.
30 31 32 |
# File 'lib/one_apm/transaction.rb', line 30 def start_time @start_time end |
#transaction_trace ⇒ Object (readonly)
Returns the value of attribute transaction_trace.
40 41 42 |
# File 'lib/one_apm/transaction.rb', line 40 def transaction_trace @transaction_trace end |
Class Method Details
.apdex_bucket(duration, failed, apdex_t) ⇒ Object
-
duration: response time
-
failed: the request is failed or not
-
apdex_s: satisfy
-
apdex_t: tolerate
-
apdex_f: frustrate
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/one_apm/transaction/class_methods.rb', line 98 def apdex_bucket(duration, failed, apdex_t) case when failed :apdex_f # frustrate if request failed when duration <= apdex_t :apdex_s # satisfy if duration < tolerate when duration <= 4 * apdex_t :apdex_t # tolerate if duration < 4 * tolerate else :apdex_f # otherwise frustrate end end |
.nested_transaction_name(name) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/one_apm/transaction/class_methods.rb', line 83 def nested_transaction_name(name) if name.start_with?(Transaction::OA_WEB_TRANSACTION_PREFIX) || name.start_with?(Transaction::OA_OTHER_TRANSACTION_PREFIX) "#{Transaction::OA_SUBTRANSACTION_PREFIX}#{name}" else name end end |
.referer_from_request(req) ⇒ Object
Make a safe attempt to get the referer from a request object, generally successful when it’s a Rack request.
125 126 127 128 129 |
# File 'lib/one_apm/transaction/class_methods.rb', line 125 def referer_from_request(req) if req && req.respond_to?(:referer) req.referer.to_s.split('?').first end end |
.start(state, category, options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/one_apm/transaction/class_methods.rb', line 15 def start(state, category, ) category ||= :controller txn = state.current_transaction if txn txn.create_nested_frame(state, category, ) else txn = start_new_transaction(state, category, ) end txn rescue => e OneApm::Manager.logger.error("Exception during Transaction.start", e) nil end |
.start_new_transaction(state, category, options) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/one_apm/transaction/class_methods.rb', line 8 def start_new_transaction(state, category, ) txn = Transaction.new(category, ) state.reset(txn) txn.start(state) txn end |
.stop(state, end_time = Time.now) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/one_apm/transaction/class_methods.rb', line 30 def stop(state, end_time=Time.now) txn = state.current_transaction if txn.nil? OneApm::Manager.logger.error(Transaction::OA_FAILED_TO_STOP_MESSAGE) return end nested_frame = txn.frame_stack.pop if txn.frame_stack.empty? txn.stop(state, end_time, nested_frame) state.reset else nested_name = nested_transaction_name(nested_frame.name) if nested_name.start_with?(Transaction::OA_MIDDLEWARE_PREFIX) summary_metrics = Transaction::OA_MIDDLEWARE_SUMMARY_METRICS else summary_metrics = Transaction::OA_EMPTY_SUMMARY_METRICS end = Transaction::OA_NESTED_TRACE_STOP_OPTIONS = Transaction::OA_TRACE_IGNORE_OPTIONS if txn.ignore_frame?(nested_name) OneApm::Support::MethodTracer::Helpers.( state, nested_frame.start_time.to_f, nested_name, summary_metrics, nested_frame, , end_time.to_f) end :transaction_stopped rescue => e state.reset OneApm::Manager.logger.error("Exception during Transaction.stop", e) nil end |
.uri_from_request(req) ⇒ Object
Make a safe attempt to get the URI, without the host and query string.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/one_apm/transaction/class_methods.rb', line 112 def uri_from_request(req) approximate_uri = case when req.respond_to?(:fullpath ) then req.fullpath when req.respond_to?(:path ) then req.path when req.respond_to?(:request_uri) then req.request_uri when req.respond_to?(:uri ) then req.uri when req.respond_to?(:url ) then req.url end return approximate_uri[%r{^(https?://.*?)?(/[^?]*)}, 2] || '/' if approximate_uri end |
.wrap(state, name, category, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/one_apm/transaction/class_methods.rb', line 71 def wrap(state, name, category, = {}) Transaction.start(state, category, .merge(:transaction_name => name)) begin yield rescue => e Transaction.notice_error(e) raise e ensure Transaction.stop(state) end end |
Instance Method Details
#abort_transaction!(state) ⇒ Object
Call this to ensure that the current transaction is not saved
162 163 164 |
# File 'lib/one_apm/transaction.rb', line 162 def abort_transaction!(state) transaction_sampler.ignore_transaction(state) end |
#apdex_bucket(duration) ⇒ Object
6 7 8 |
# File 'lib/one_apm/transaction/transaction_apdex.rb', line 6 def apdex_bucket(duration) Transaction.apdex_bucket(duration, had_error?, apdex_t) end |
#apdex_t ⇒ Object
10 11 12 |
# File 'lib/one_apm/transaction/transaction_apdex.rb', line 10 def apdex_t transaction_specific_apdex_t || OneApm::Manager.config[:apdex_t] end |
#background_summary_metrics ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/one_apm/transaction/transaction_summary.rb', line 14 def background_summary_metrics segments = @frozen_name.split('/') if segments.size > 2 ["OtherTransaction/#{segments[1]}/all", OA_OTHER_SUMMARY_METRIC] else [] end end |
#cat_path_hash(state) ⇒ Object
264 265 266 267 268 269 270 |
# File 'lib/one_apm/transaction.rb', line 264 def cat_path_hash(state) referring_path_hash = cat_referring_path_hash(state) || '0' seed = referring_path_hash.to_i(16) result = agent.cross_app_monitor.path_hash(best_name, seed) record_cat_path_hash(result) result end |
#cat_referring_path_hash(state) ⇒ Object
279 280 281 |
# File 'lib/one_apm/transaction.rb', line 279 def cat_referring_path_hash(state) agent.cross_app_monitor.client_referring_transaction_path_hash(state) end |
#cat_trip_id(state) ⇒ Object
260 261 262 |
# File 'lib/one_apm/transaction.rb', line 260 def cat_trip_id(state) agent.cross_app_monitor.client_referring_transaction_trip_id(state) || guid end |
#commit!(state, end_time, outermost_segment_name) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/one_apm/transaction.rb', line 126 def commit!(state, end_time, outermost_segment_name) record_transaction_cpu(state) record_gc(state, end_time) sql_sampler.on_finishing_transaction(state, @frozen_name) record_summary_metrics(outermost_segment_name, end_time) record_apdex(state, end_time) unless ignore_apdex? record_queue_time record_exceptions merge_metrics send_transaction_finished_event(state, start_time, end_time) end |
#cpu_burn ⇒ Object
6 7 8 |
# File 'lib/one_apm/transaction/transaction_cpu.rb', line 6 def cpu_burn normal_cpu_burn || jruby_cpu_burn end |
#create_nested_frame(state, category, options) ⇒ Object
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/one_apm/transaction.rb', line 234 def create_nested_frame(state, category, ) @has_children = true if [:filtered_params] && ![:filtered_params].empty? @filtered_params = [:filtered_params] end frame_stack.push OneApm::Support::MethodTracer::Helpers.trace_execution_scoped_header(state, Time.now.to_f) name_last_frame([:transaction_name]) set_default_transaction_name([:transaction_name], category) end |
#ignore_frame?(tx_name) ⇒ Boolean
301 302 303 304 |
# File 'lib/one_apm/transaction.rb', line 301 def ignore_frame? tx_name return false if ignore_frames.empty? ignore_frames.any?{|iframe| tx_name.to_s.match(/#{iframe}/)} end |
#instrumentation_state ⇒ Object
226 227 228 |
# File 'lib/one_apm/transaction.rb', line 226 def instrumentation_state @instrumentation_state ||= {} end |
#jruby_cpu_burn ⇒ Object
34 35 36 37 |
# File 'lib/one_apm/transaction/transaction_jruby_functions.rb', line 34 def jruby_cpu_burn return unless @jruby_cpu_start jruby_cpu_time - @jruby_cpu_start end |
#jruby_cpu_time ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/one_apm/transaction/transaction_jruby_functions.rb', line 20 def jruby_cpu_time return nil unless @@java_classes_loaded threadMBean = Java::JavaLangManagement::ManagementFactory.getThreadMXBean() return nil unless threadMBean.isCurrentThreadCpuTimeSupported java_utime = threadMBean.getCurrentThreadUserTime() # ns -1 == java_utime ? 0.0 : java_utime/1e9 rescue => e OneApm::Manager.logger.log_once(:warn, :jruby_cpu_time, OA_JRUBY_CPU_TIME_ERROR, e) OneApm::Manager.logger.debug(OA_JRUBY_CPU_TIME_ERROR, e) nil end |
#merge_metrics ⇒ Object
221 222 223 224 |
# File 'lib/one_apm/transaction.rb', line 221 def merge_metrics return if ignore_frame?(best_name) agent.stats_engine.merge_transaction_metrics!(@metrics, best_name) end |
#needs_middleware_summary_metrics?(name) ⇒ Boolean
23 24 25 |
# File 'lib/one_apm/transaction/transaction_summary.rb', line 23 def needs_middleware_summary_metrics?(name) name.start_with?(OA_MIDDLEWARE_PREFIX) end |
#normal_cpu_burn ⇒ Object
10 11 12 13 |
# File 'lib/one_apm/transaction/transaction_cpu.rb', line 10 def normal_cpu_burn return unless @process_cpu_start process_cpu - @process_cpu_start end |
#notice_error(error, options = {}) ⇒ Object
Do not call this. Invoke the class method instead.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/one_apm/transaction.rb', line 284 def notice_error(error, ={}) # :nodoc: [:uri] ||= uri if uri [:referer] ||= referer if referer if filtered_params && !filtered_params.empty? [:request_params] = filtered_params end .merge!(custom_parameters) if @exceptions[error] @exceptions[error].merge! else @exceptions[error] = end end |
#noticed_error_ids ⇒ Object
230 231 232 |
# File 'lib/one_apm/transaction.rb', line 230 def noticed_error_ids @noticed_error_ids ||= [] end |
#process_cpu ⇒ Object
15 16 17 18 19 |
# File 'lib/one_apm/transaction/transaction_cpu.rb', line 15 def process_cpu return nil if defined? JRuby p = Process.times p.stime + p.utime end |
#record_apdex(state, end_time = Time.now) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/one_apm/transaction.rb', line 187 def record_apdex(state, end_time=Time.now) return unless recording_web_transaction? && state.is_execution_traced? freeze_name_and_execute_if_not_ignored do action_duration = end_time - start_time total_duration = end_time - apdex_start apdex_bucket_global = apdex_bucket(total_duration) apdex_bucket_txn = apdex_bucket(action_duration) @metrics.record_unscoped(OA_APDEX_METRIC, apdex_bucket_global, apdex_t) txn_apdex_metric = @frozen_name.gsub(/^[^\/]+\//, 'Apdex/') @metrics.record_unscoped(txn_apdex_metric, apdex_bucket_txn, apdex_t) end end |
#record_cat_path_hash(hash) ⇒ Object
272 273 274 275 276 277 |
# File 'lib/one_apm/transaction.rb', line 272 def record_cat_path_hash(hash) @cat_path_hashes ||= [] if @cat_path_hashes.size < 10 && !@cat_path_hashes.include?(hash) @cat_path_hashes << hash end end |
#record_exceptions ⇒ Object
214 215 216 217 218 219 |
# File 'lib/one_apm/transaction.rb', line 214 def record_exceptions @exceptions.each do |exception, | [:metric] = best_name agent.error_collector.notice_error(exception, ) end end |
#record_gc(state, end_time) ⇒ Object
173 174 175 176 177 |
# File 'lib/one_apm/transaction.rb', line 173 def record_gc(state, end_time) gc_stop_snapshot = OneApm::Collector::StatsEngine::GCProfiler.take_snapshot gc_delta = OneApm::Collector::StatsEngine::GCProfiler.record_delta(gc_start_snapshot, gc_stop_snapshot) @transaction_trace = transaction_sampler.on_finishing_transaction(state, self, end_time, gc_delta) end |
#record_queue_time ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/one_apm/transaction.rb', line 203 def record_queue_time value = queue_time if value > 0.0 if value < OneApm::Support::MethodTracer::Helpers::OA_MAX_ALLOWED_METRIC_DURATION @metrics.record_unscoped(OA_QUEUE_TIME_METRIC, value) else OneApm::Manager.logger.log_once(:warn, :too_high_queue_time, "Not recording unreasonably large queue time of #{value} s") end end end |
#record_summary_metrics(outermost_segment_name, end_time) ⇒ Object
The summary metrics recorded by this method all end up with a duration equal to the transaction itself, and an exclusive time of zero.
181 182 183 184 185 |
# File 'lib/one_apm/transaction.rb', line 181 def record_summary_metrics(outermost_segment_name, end_time) metrics = summary_metrics metrics << @frozen_name unless @frozen_name == outermost_segment_name @metrics.record_unscoped(metrics, end_time.to_f - start_time.to_f, 0) end |
#record_transaction_cpu(state) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/one_apm/transaction.rb', line 166 def record_transaction_cpu(state) burn = cpu_burn if burn transaction_sampler.notice_transaction_cpu_time(state, burn) end end |
#send_transaction_finished_event(state, start_time, end_time) ⇒ Object
This event is fired when the transaction is fully completed. The metric values and sampler can’t be successfully modified from this event.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/one_apm/transaction.rb', line 143 def send_transaction_finished_event(state, start_time, end_time) duration = end_time.to_f - start_time.to_f payload = { :name => @frozen_name, :start_timestamp => start_time.to_f, :duration => duration, :metrics => @metrics, :custom_params => custom_parameters } append_cat_info(state, duration, payload) append_apdex_perf_zone(duration, payload) append_synthetics_to(state, payload) append_referring_transaction_guid_to(state, payload) append_http_response_code(payload) agent.events.notify(:transaction_finished, payload) end |
#start(state) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/one_apm/transaction.rb', line 76 def start(state) return if !state.is_execution_traced? transaction_sampler.on_start_transaction(state, start_time, uri) sql_sampler.on_start_transaction(state, start_time, uri) agent.events.notify(:start_transaction) OneApm::Agent::BusyCalculator.dispatcher_start(start_time) frame_stack.push OneApm::Support::MethodTracer::Helpers.trace_execution_scoped_header(state, start_time.to_f) name_last_frame @default_name end |
#stop(state, end_time, outermost_frame) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/one_apm/transaction.rb', line 88 def stop(state, end_time, outermost_frame) return if !state.is_execution_traced? freeze_name_and_execute_if_not_ignored ignore! if user_defined_rules_ignore? if @has_children name = Transaction.nested_transaction_name(outermost_frame.name) = OA_TRACE_OPTIONS_SCOPED else name = @frozen_name = OA_TRACE_OPTIONS_UNSCOPED end = OA_TRACE_IGNORE_OPTIONS if ignore_frame?(outermost_frame.name) # These metrics are recorded here instead of in record_summary_metrics # in order to capture the exclusive time associated with the outer-most # TT node. if needs_middleware_summary_metrics?(name) summary_metrics_with_exclusive_time = OA_MIDDLEWARE_SUMMARY_METRICS else summary_metrics_with_exclusive_time = OA_EMPTY_SUMMARY_METRICS end OneApm::Support::MethodTracer::Helpers.( state, start_time.to_f, name, summary_metrics_with_exclusive_time, outermost_frame, , end_time.to_f) OneApm::Agent::BusyCalculator.dispatcher_finish(end_time) commit!(state, end_time, name) unless @ignore_this_transaction end |
#summary_metrics ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/one_apm/transaction/transaction_summary.rb', line 6 def summary_metrics if @frozen_name.start_with?(OA_WEB_TRANSACTION_PREFIX) [OA_WEB_SUMMARY_METRIC] else background_summary_metrics end end |
#transaction_specific_apdex_t ⇒ Object
14 15 16 17 |
# File 'lib/one_apm/transaction/transaction_apdex.rb', line 14 def transaction_specific_apdex_t key = :web_transactions_apdex OneApm::Manager.config[key] && OneApm::Manager.config[key][best_name] end |
#user_defined_rules_ignore? ⇒ Boolean
245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/one_apm/transaction.rb', line 245 def user_defined_rules_ignore? return unless uri return if (rules = OneApm::Manager.config[:"rules.ignore_url_regexes"]).empty? parsed = OneApm::Support::HTTPClients::URIUtil.parse_url(uri) filtered_uri = OneApm::Support::HTTPClients::URIUtil.filter_uri(parsed) rules.any? do |rule| filtered_uri.match(rule) end rescue URI::InvalidURIError => e OneApm::Manager.logger.debug("Error parsing URI: #{uri}", e) false end |