Class: OneApm::TransactionSample
- Inherits:
-
Object
- Object
- OneApm::TransactionSample
- Includes:
- Coerce, TransactionAnalysis
- Defined in:
- lib/one_apm/transaction/segment.rb,
lib/one_apm/transaction/summary_segment.rb,
lib/one_apm/transaction/composite_segment.rb,
lib/one_apm/transaction/transaction_sample.rb
Defined Under Namespace
Classes: CompositeSegment, Segment, SummarySegment
Constant Summary collapse
- @@start_time =
Time.now
Instance Attribute Summary collapse
-
#finished ⇒ Object
Returns the value of attribute finished.
-
#force_persist ⇒ Object
Returns the value of attribute force_persist.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#params ⇒ Object
Returns the value of attribute params.
-
#prepared ⇒ Object
writeonly
Sets the attribute prepared.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#root_segment ⇒ Object
Returns the value of attribute root_segment.
-
#sample_id ⇒ Object
readonly
Returns the value of attribute sample_id.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#synthetics_resource_id ⇒ Object
Returns the value of attribute synthetics_resource_id.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#xray_session_id ⇒ Object
Returns the value of attribute xray_session_id.
Instance Method Summary collapse
- #count_segments ⇒ Object
-
#create_segment(relative_timestamp, metric_name = nil) ⇒ Object
relative_timestamp is seconds since the start of the transaction.
- #duration ⇒ Object
-
#each_segment(&block) ⇒ Object
Iterates recursively over each segment in the entire transaction sample tree.
-
#each_segment_with_nest_tracking(&block) ⇒ Object
Iterates recursively over each segment in the entire transaction sample tree while keeping track of nested segments.
-
#ensure_segment_count_set(count) ⇒ Object
makes sure that the parameter cache for segment count is set to the correct value.
-
#find_segment(id) ⇒ Object
Searches the tree recursively for the segment with the given id.
- #forced? ⇒ Boolean
-
#initialize(time = Time.now.to_f, sample_id = nil) ⇒ TransactionSample
constructor
A new instance of TransactionSample.
- #path_string ⇒ Object
-
#prepare_to_send! ⇒ Object
Return a new transaction sample that can be sent to the OneApm service.
- #prepared? ⇒ Boolean
- #set_custom_param(name, value) ⇒ Object
-
#timestamp ⇒ Object
offset from start of app.
- #to_array ⇒ Object
- #to_collector_array(encoder) ⇒ Object
- #to_s ⇒ Object
- #to_s_compact ⇒ Object
- #transaction_name ⇒ Object
- #transaction_name=(new_name) ⇒ Object
Methods included from Coerce
#event_params, #float, #int, #int_or_nil, #log_failure, #string
Methods included from TransactionAnalysis
#breakdown_data, #database_time, #render_time, #sql_segments
Constructor Details
#initialize(time = Time.now.to_f, sample_id = nil) ⇒ TransactionSample
Returns a new instance of TransactionSample.
26 27 28 29 30 31 32 33 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 26 def initialize(time = Time.now.to_f, sample_id = nil) @sample_id = sample_id || object_id @start_time = time @params = { :segment_count => -1, :request_params => {} } @segment_count = -1 @root_segment = create_segment 0.0, "ROOT" @prepared = false end |
Instance Attribute Details
#finished ⇒ Object
Returns the value of attribute finished.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def finished @finished end |
#force_persist ⇒ Object
Returns the value of attribute force_persist.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def force_persist @force_persist end |
#guid ⇒ Object
Returns the value of attribute guid.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def guid @guid end |
#params ⇒ Object
Returns the value of attribute params.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def params @params end |
#prepared=(value) ⇒ Object (writeonly)
Sets the attribute prepared
22 23 24 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 22 def prepared=(value) @prepared = value end |
#profile ⇒ Object
Returns the value of attribute profile.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def profile @profile end |
#root_segment ⇒ Object
Returns the value of attribute root_segment.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def root_segment @root_segment end |
#sample_id ⇒ Object (readonly)
Returns the value of attribute sample_id.
21 22 23 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 21 def sample_id @sample_id end |
#start_time ⇒ Object
Returns the value of attribute start_time.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def start_time @start_time end |
#synthetics_resource_id ⇒ Object
Returns the value of attribute synthetics_resource_id.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def synthetics_resource_id @synthetics_resource_id end |
#threshold ⇒ Object
Returns the value of attribute threshold.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def threshold @threshold end |
#xray_session_id ⇒ Object
Returns the value of attribute xray_session_id.
18 19 20 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 18 def xray_session_id @xray_session_id end |
Instance Method Details
#count_segments ⇒ Object
39 40 41 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 39 def count_segments @segment_count end |
#create_segment(relative_timestamp, metric_name = nil) ⇒ Object
relative_timestamp is seconds since the start of the transaction
100 101 102 103 104 105 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 100 def create_segment(, metric_name=nil) raise TypeError.new("Frozen Transaction Sample") if finished @params[:segment_count] += 1 @segment_count += 1 OneApm::TransactionSample::Segment.new(, metric_name) end |
#duration ⇒ Object
107 108 109 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 107 def duration root_segment.duration end |
#each_segment(&block) ⇒ Object
Iterates recursively over each segment in the entire transaction sample tree
113 114 115 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 113 def each_segment(&block) @root_segment.each_segment(&block) end |
#each_segment_with_nest_tracking(&block) ⇒ Object
Iterates recursively over each segment in the entire transaction sample tree while keeping track of nested segments
119 120 121 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 119 def each_segment_with_nest_tracking(&block) @root_segment.each_segment_with_nest_tracking(&block) end |
#ensure_segment_count_set(count) ⇒ Object
makes sure that the parameter cache for segment count is set to the correct value
45 46 47 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 45 def ensure_segment_count_set(count) params[:segment_count] ||= count end |
#find_segment(id) ⇒ Object
Searches the tree recursively for the segment with the given id. note that this is an internal id, not an ActiveRecord id
129 130 131 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 129 def find_segment(id) @root_segment.find_segment(id) end |
#forced? ⇒ Boolean
95 96 97 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 95 def forced? !!@force_persist || !int_or_nil(xray_session_id).nil? end |
#path_string ⇒ Object
83 84 85 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 83 def path_string @root_segment.path_string end |
#prepare_to_send! ⇒ Object
Return a new transaction sample that can be sent to the OneApm service.
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 156 def prepare_to_send! return self if @prepared if Agent::Database.should_record_sql? collect_explain_plans! prepare_sql_for_transmission! else strip_sql! end @prepared = true self end |
#prepared? ⇒ Boolean
35 36 37 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 35 def prepared? @prepared end |
#set_custom_param(name, value) ⇒ Object
54 55 56 57 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 54 def set_custom_param(name, value) @params[:custom_params] ||= {} @params[:custom_params][name] = value end |
#timestamp ⇒ Object
offset from start of app
50 51 52 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 50 def @start_time - @@start_time.to_f end |
#to_array ⇒ Object
61 62 63 64 65 66 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 61 def to_array [ float(@start_time), @params[:request_params], @params[:custom_params], @root_segment.to_array ] end |
#to_collector_array(encoder) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 68 def to_collector_array(encoder) trace_tree = encoder.encode(self.to_array) [ Helper.time_to_millis(@start_time), Helper.time_to_millis(duration), string(transaction_name), string(@params[:uri]), trace_tree, string(@guid), nil, forced?, int_or_nil(xray_session_id), string(synthetics_resource_id) ] end |
#to_s ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 133 def to_s s = "Transaction Sample collected at #{Time.at(start_time)}\n" s << " {\n" s << " Path: #{params[:path]} \n" params.each do |k,v| next if k == :path s << " #{k}: " << case v when Enumerable then v.map(&:to_s).sort.join("; ") when String then v when Float then '%6.3s' % v when Fixnum then v.to_s when nil then '' else raise "unexpected value type for #{k}: '#{v}' (#{v.class})" end << "\n" end s << " }\n\n" s << @root_segment.to_debug_str(0) end |
#to_s_compact ⇒ Object
123 124 125 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 123 def to_s_compact @root_segment.to_s_compact end |
#transaction_name ⇒ Object
87 88 89 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 87 def transaction_name @params[:path] end |
#transaction_name=(new_name) ⇒ Object
91 92 93 |
# File 'lib/one_apm/transaction/transaction_sample.rb', line 91 def transaction_name=(new_name) @params[:path] = new_name end |