class OneApm::TransactionSampleBuilder
a builder is created with every sampled transaction, to dynamically generate the sampled data. It is a thread-local object, and is not accessed by any other thread so no need for synchronization.
@api private
Constants
- OA_TT_THRESHOLD_KEY
Attributes
current_segment[R]
sample[R]
sample_start[R]
Public Class Methods
new(time=Time.now)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 46 def initialize(time=Time.now) @sample = OneApm::TransactionSample.new(time.to_f) @sample_start = time.to_f @current_segment = @sample.root_segment end
Public Instance Methods
finish_trace(time=Time.now.to_f, custom_params={})
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 99 def finish_trace(time=Time.now.to_f, custom_params={}) # Should never get called twice, but in a rare case that we can't # reproduce in house it does. log forensics and return gracefully if @sample.finished OneApm::Manager.logger.error "Unexpected double-finish_trace of Transaction Trace Object: \n#{@sample.to_s}" return end @sample.root_segment.end_trace(time.to_f - @sample_start) @sample.params[:custom_params] ||= {} @sample.params[:custom_params].merge!(normalize_params(custom_params)) # If we ever implement saving of TTs based on the record_tt flag on the # calling and called applications, we should change this flag's value. @sample.force_persist = false @sample.threshold = transaction_trace_threshold @sample.finished = true @current_segment = nil end
ignore_transaction()
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 60 def ignore_transaction @ignore = true end
ignored?()
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 56 def ignored? @ignore end
sample_id()
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 52 def sample_id @sample.sample_id end
scope_depth()
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 130 def scope_depth depth = -1 # have to account for the root current = @current_segment while(current) depth += 1 current = current.parent_segment end depth end
segment_limit()
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 64 def segment_limit OneApm::Manager.config[:'transaction_tracer.limit_segments'] end
set_request_params(params)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 146 def set_request_params(params) if OneApm::Manager.config[:capture_params] params = normalize_params(params) @sample.params[:request_params].merge!(params) @sample.params[:request_params].delete :controller @sample.params[:request_params].delete :action end end
set_transaction_cpu_time(cpu_time)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 159 def set_transaction_cpu_time(cpu_time) @sample.set_custom_param(:cpu_time, cpu_time) end
set_transaction_name(name)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 155 def set_transaction_name(name) @sample.transaction_name = name end
set_transaction_uri(uri)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 142 def set_transaction_uri(uri) @sample.params[:uri] ||= uri end
trace_entry(time)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 68 def trace_entry(time) if @sample.count_segments < segment_limit segment = @sample.create_segment(time.to_f - @sample_start) @current_segment.add_called_segment(segment) @current_segment = segment if @sample.count_segments == segment_limit() OneApm::Manager.logger.debug("Segment limit of #{segment_limit} reached, ceasing collection.") end else if @current_segment.is_a?(PlaceholderSegment) @current_segment.depth += 1 else @current_segment = PlaceholderSegment.new(@current_segment) end end @current_segment end
trace_exit(metric_name, time)
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 86 def trace_exit(metric_name, time) if @current_segment.is_a?(PlaceholderSegment) @current_segment.depth -= 1 if @current_segment.depth == 0 @current_segment = @current_segment.parent_segment end else @current_segment.metric_name = metric_name @current_segment.end_trace(time.to_f - @sample_start) @current_segment = @current_segment.parent_segment end end
transaction_trace_threshold()
click to toggle source
# File lib/one_apm/transaction/transaction_sample_builder.rb, line 120 def transaction_trace_threshold state = TransactionState.tl_get source_class = OneApm::Manager.config.source(OA_TT_THRESHOLD_KEY).class if source_class == Configuration::DefaultSource && state.current_transaction state.current_transaction.apdex_t * 4 else OneApm::Manager.config[OA_TT_THRESHOLD_KEY] end end