Class: TingYun::Agent::Transaction::TraceNode
- Inherits:
-
Object
- Object
- TingYun::Agent::Transaction::TraceNode
- Defined in:
- lib/ting_yun/agent/transaction/trace_node.rb
Constant Summary collapse
- UNKNOWN_NODE_NAME =
'<unknown>'.freeze
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#called_nodes ⇒ Object
readonly
Returns the value of attribute called_nodes.
-
#count ⇒ Object
Returns the value of attribute count.
-
#datas ⇒ Object
Returns the value of attribute datas.
-
#entry_timestamp ⇒ Object
readonly
Returns the value of attribute entry_timestamp.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#exit_timestamp ⇒ Object
Returns the value of attribute exit_timestamp.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#method ⇒ Object
Returns the value of attribute method.
-
#metric_name ⇒ Object
Returns the value of attribute metric_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params_data ⇒ Object
Returns the value of attribute params_data.
-
#parent_node ⇒ Object
readonly
Returns the value of attribute parent_node.
-
#parentTracerId ⇒ Object
Returns the value of attribute parentTracerId.
-
#tracerId ⇒ Object
Returns the value of attribute tracerId.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #add_called_node(s) ⇒ Object
- #add_error(error) ⇒ Object
- #custom_params ⇒ Object
-
#duration ⇒ Object
return the total duration of this node.
- #each_call(&blk) ⇒ Object
- #end_trace(timestamp) ⇒ Object
- #explain_sql ⇒ Object
-
#initialize(timestamp, metric_name, tracerId, option = {}) ⇒ TraceNode
constructor
A new instance of TraceNode.
- #merge(hash) ⇒ Object
- #params ⇒ Object
- #params=(p) ⇒ Object
- #pre_metric_name(metric_name) ⇒ Object
- #request_params ⇒ Object
- #to_array ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(timestamp, metric_name, tracerId, option = {}) ⇒ TraceNode
Returns a new instance of TraceNode.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 22 def initialize(, metric_name,tracerId,option={}) @type = option[:type] || 'Java' @entry_timestamp = @metric_name = metric_name @called_nodes = nil @count = 1 if metric_name == "ROOT" @parentTracerId = -1 @tracerId = 0 else @tracerId = tracerId end @exception = [] @params_data = {} @backtrace = [] end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def backtrace @backtrace end |
#called_nodes ⇒ Object (readonly)
Returns the value of attribute called_nodes.
12 13 14 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 12 def called_nodes @called_nodes end |
#count ⇒ Object
Returns the value of attribute count.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def count @count end |
#datas ⇒ Object
Returns the value of attribute datas.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def datas @datas end |
#entry_timestamp ⇒ Object (readonly)
Returns the value of attribute entry_timestamp.
12 13 14 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 12 def @entry_timestamp end |
#exception ⇒ Object
Returns the value of attribute exception.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def exception @exception end |
#exit_timestamp ⇒ Object
Returns the value of attribute exit_timestamp.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def @exit_timestamp end |
#klass ⇒ Object
Returns the value of attribute klass.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def klass @klass end |
#method ⇒ Object
Returns the value of attribute method.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def method @method end |
#metric_name ⇒ Object
Returns the value of attribute metric_name.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def metric_name @metric_name end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def name @name end |
#params_data ⇒ Object
Returns the value of attribute params_data.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def params_data @params_data end |
#parent_node ⇒ Object
Returns the value of attribute parent_node.
12 13 14 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 12 def parent_node @parent_node end |
#parentTracerId ⇒ Object
Returns the value of attribute parentTracerId.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def parentTracerId @parentTracerId end |
#tracerId ⇒ Object
Returns the value of attribute tracerId.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def tracerId @tracerId end |
#type ⇒ Object
Returns the value of attribute type.
15 16 17 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 15 def type @type end |
#uri ⇒ Object
Returns the value of attribute uri.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def uri @uri end |
Instance Method Details
#[](key) ⇒ Object
109 110 111 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 109 def [](key) params[key] end |
#[]=(key, value) ⇒ Object
103 104 105 106 107 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 103 def []=(key, value) # only create a parameters field if a parameter is set; this will save # bandwidth etc as most nodes have no parameters params[key] = value end |
#add_called_node(s) ⇒ Object
39 40 41 42 43 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 39 def add_called_node(s) @called_nodes ||= [] @called_nodes << s s.parent_node = self end |
#add_error(error) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 145 def add_error(error) if error.respond_to?(:tingyun_external) exception << {"msg" => error., "name" => "External #{error.tingyun_code}", "stack"=> error.backtrace, "error"=> false } else if ::TingYun::Agent.config[:'nbs.exception.stack_enabled'] exception << {"msg" => error., "name" => error.class.name , "stack"=> error.backtrace.reject! { |t| t.include?('tingyun_rpm') }, "error"=> false } else exception << {"msg" => error., "name" => error.class.name, "stack"=> error.backtrace, "error"=> false } end end end |
#custom_params ⇒ Object
95 96 97 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 95 def custom_params {} end |
#duration ⇒ Object
return the total duration of this node
51 52 53 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 51 def duration TingYun::Helper.time_to_millis(@exit_timestamp - @entry_timestamp) end |
#each_call(&blk) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 125 def each_call(&blk) blk.call self if @called_nodes @called_nodes.each do |node| node.each_call(&blk) end end end |
#end_trace(timestamp) ⇒ Object
45 46 47 48 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 45 def end_trace() @parentTracerId = @parent_node.tracerId unless @parent_node.nil? @exit_timestamp = end |
#explain_sql ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 135 def explain_sql return params[:explainPlan] if params.key?(:explainPlan) statement = params[:sql] return nil unless statement.respond_to?(:config) && statement.respond_to?(:explainer) TingYun::Agent::Database.explain_sql(statement) end |
#merge(hash) ⇒ Object
121 122 123 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 121 def merge(hash) params.merge! hash end |
#params ⇒ Object
113 114 115 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 113 def params @params ||= {} end |
#params=(p) ⇒ Object
117 118 119 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 117 def params=(p) @params = p end |
#pre_metric_name(metric_name) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 56 def pre_metric_name(metric_name) @name ||= if metric_name.start_with?('Database ') "#{metric_name.split('/')[0]}/#{metric_name.split('/')[-1]}" else metric_name end end |
#request_params ⇒ Object
99 100 101 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 99 def request_params {} end |
#to_array ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 64 def to_array [TingYun::Helper.time_to_millis(), TingYun::Helper.time_to_millis(), TingYun::Support::Coerce.string(metric_name), TingYun::Support::Coerce.string(uri)||'', TingYun::Support::Coerce.int(count), TingYun::Support::Coerce.string(klass)||TingYun::Support::Coerce.string(pre_metric_name(metric_name)), TingYun::Support::Coerce.string(method)||'', params] + [(@called_nodes ? @called_nodes.map{|s| s.to_array} : [])] end |
#to_hash ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 76 def to_hash hash = { "parentTracerId" => @parentTracerId, "start" => TingYun::Helper.time_to_millis(), "end" => TingYun::Helper.time_to_millis(), "type"=> params[:type] || @type } hash["tracerId"]= @tracerId if @tracerId!=0 method = params[:method] || TingYun::Support::Coerce.string(method) hash["method"] = method unless method.nil? hash["metric"] = TingYun::Support::Coerce.string(metric_name) unless (metric_name.nil? or metric_name=="ROOT") clazz = params[:klass] || TingYun::Support::Coerce.string(klass) hash["clazz"] = clazz unless clazz.nil? hash["params"] = params_data unless params_data.empty? hash["backtrace"] = backtrace unless backtrace.empty? hash["exception"] = exception unless exception.empty? [hash].concat([(@called_nodes ? @called_nodes.map{|s| s.to_hash} : nil)].compact) end |