Class: TingYun::Agent::Transaction::Trace
- Inherits:
-
Object
- Object
- TingYun::Agent::Transaction::Trace
- Includes:
- Support::Coerce
- Defined in:
- lib/ting_yun/agent/transaction/trace.rb
Constant Summary collapse
- HEX_DIGITS =
(0..15).map{|i| i.to_s(16)}
- GUID_LENGTH =
16
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#finished ⇒ Object
Returns the value of attribute finished.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#metric_name ⇒ Object
Returns the value of attribute metric_name.
-
#node_count ⇒ Object
Returns the value of attribute node_count.
-
#root_node ⇒ Object
Returns the value of attribute root_node.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#tx_id ⇒ Object
Returns the value of attribute tx_id.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #collect_explain_plans! ⇒ Object
- #create_node(time_since_start, metric_name = nil) ⇒ Object
- #custom_params ⇒ Object
- #duration ⇒ Object
-
#initialize(start_time) ⇒ Trace
constructor
A new instance of Trace.
- #prepare_sql_for_transmission!(&block) ⇒ Object
- #prepare_to_send! ⇒ Object
- #request_params ⇒ Object
- #to_collector_array(encoder) ⇒ Object
- #trace_tree ⇒ Object
Methods included from Support::Coerce
event_params, float, int, int_or_nil, log_failure, string
Constructor Details
#initialize(start_time) ⇒ Trace
Returns a new instance of Trace.
13 14 15 16 17 18 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 13 def initialize(start_time) @start_time = start_time @node_count = 0 @prepared = false @guid = generate_guid end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def attributes @attributes end |
#finished ⇒ Object
Returns the value of attribute finished.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def finished @finished end |
#guid ⇒ Object
Returns the value of attribute guid.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def guid @guid end |
#metric_name ⇒ Object
Returns the value of attribute metric_name.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def metric_name @metric_name end |
#node_count ⇒ Object
Returns the value of attribute node_count.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def node_count @node_count end |
#root_node ⇒ Object
Returns the value of attribute root_node.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def root_node @root_node end |
#start_time ⇒ Object
Returns the value of attribute start_time.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def start_time @start_time end |
#threshold ⇒ Object
Returns the value of attribute threshold.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def threshold @threshold end |
#tx_id ⇒ Object
Returns the value of attribute tx_id.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def tx_id @tx_id end |
#uri ⇒ Object
Returns the value of attribute uri.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 11 def uri @uri end |
Instance Method Details
#collect_explain_plans! ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 69 def collect_explain_plans! return unless TingYun::Agent::Database.should_action_collect_explain_plans? threshold = TingYun::Agent.config[:'nbs.action_tracer.action_threshold'] root_node.each_call do |node| if node[:sql] && node.duration > threshold node[:explainPlan] = node.explain_sql end end end |
#create_node(time_since_start, metric_name = nil) ⇒ Object
20 21 22 23 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 20 def create_node(time_since_start, metric_name = nil) @node_count += 1 TingYun::Agent::Transaction::TraceNode.new(time_since_start, metric_name) end |
#custom_params ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 95 def custom_params custom_param = { :threadName => string(attributes.agent_attributes[:threadName]), :referer => string(attributes.agent_attributes[:referer]) || '' } custom_param[:httpStatus] = int(attributes.agent_attributes[:httpStatus]) if attributes.agent_attributes[:httpStatus] custom_param end |
#duration ⇒ Object
25 26 27 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 25 def duration root_node.duration end |
#prepare_sql_for_transmission!(&block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 79 def prepare_sql_for_transmission!(&block) strategy = TingYun::Agent::Database.record_sql_method('nbs.action_tracer.record_sql') root_node.each_call do |node| next unless node[:sql] case strategy when :obfuscated node[:sql] = TingYun::Agent::Database.obfuscate_sql(node[:sql]) when :raw node[:sql] = node[:sql].sql.to_s else node[:sql] = nil end end end |
#prepare_to_send! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 54 def prepare_to_send! return self if @prepared if TingYun::Agent::Database.should_record_sql?('nbs.action_tracer.record_sql') collect_explain_plans! prepare_sql_for_transmission! else root_node.each_call do |node| node.params.delete(:sql) end end @prepared = true self end |
#request_params ⇒ Object
105 106 107 108 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 105 def request_params return {} unless TingYun::Agent.config['nbs.capture_params'] attributes.request_params end |
#to_collector_array(encoder) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 42 def to_collector_array(encoder) [ @start_time.round, duration, TingYun::Helper.correctly_encoded(metric_name)|| '', TingYun::Helper.correctly_encoded(uri||metric_name||''), encoder.encode(trace_tree), tx_id || '', guid ] end |
#trace_tree ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/ting_yun/agent/transaction/trace.rb', line 33 def trace_tree [ @start_time.round, request_params, custom_params, root_node.to_array ] end |