Class: OneApm::TransactionSampleBuilder Private
- Inherits:
-
Object
- Object
- OneApm::TransactionSampleBuilder
- Includes:
- CollectionHelper
- Defined in:
- lib/one_apm/transaction/transaction_sample_builder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Defined Under Namespace
Classes: PlaceholderSegment
Constant Summary collapse
- OA_TT_THRESHOLD_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:'transaction_tracer.transaction_threshold'
Constants included from CollectionHelper
CollectionHelper::OA_DEFAULT_ARRAY_TRUNCATION_SIZE, CollectionHelper::OA_DEFAULT_TRUNCATION_SIZE
Instance Attribute Summary collapse
- #current_segment ⇒ Object readonly private
- #sample ⇒ Object readonly private
- #sample_start ⇒ Object readonly private
Instance Method Summary collapse
- #finish_trace(time = Time.now.to_f, custom_params = {}) ⇒ Object private
- #ignore_transaction ⇒ Object private
- #ignored? ⇒ Boolean private
-
#initialize(time = Time.now) ⇒ TransactionSampleBuilder
constructor
private
A new instance of TransactionSampleBuilder.
- #sample_id ⇒ Object private
- #scope_depth ⇒ Object private
- #segment_limit ⇒ Object private
- #set_request_params(params) ⇒ Object private
- #set_transaction_cpu_time(cpu_time) ⇒ Object private
- #set_transaction_name(name) ⇒ Object private
- #set_transaction_uri(uri) ⇒ Object private
- #trace_entry(time) ⇒ Object private
- #trace_exit(metric_name, time) ⇒ Object private
- #transaction_trace_threshold ⇒ Object private
Methods included from CollectionHelper
#normalize_params, #strip_oa_from_backtrace
Constructor Details
#initialize(time = Time.now) ⇒ TransactionSampleBuilder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TransactionSampleBuilder.
46 47 48 49 50 |
# 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 |
Instance Attribute Details
#current_segment ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 42 def current_segment @current_segment end |
#sample ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 42 def sample @sample end |
#sample_start ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 42 def sample_start @sample_start end |
Instance Method Details
#finish_trace(time = Time.now.to_f, custom_params = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 60 def ignore_transaction @ignore = true end |
#ignored? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 56 def ignored? @ignore end |
#sample_id ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 52 def sample_id @sample.sample_id end |
#scope_depth ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
130 131 132 133 134 135 136 137 138 139 140 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 149 150 151 152 153 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
159 160 161 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
142 143 144 |
# File 'lib/one_apm/transaction/transaction_sample_builder.rb', line 142 def set_transaction_uri(uri) @sample.params[:uri] ||= uri end |
#trace_entry(time) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 91 92 93 94 95 96 97 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
120 121 122 123 124 125 126 127 128 |
# 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 |