Class: TingYun::Agent::TransactionSampleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ting_yun/agent/transaction/transaction_sample_builder.rb

Defined Under Namespace

Classes: PlaceholderNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now.to_f) ⇒ TransactionSampleBuilder

Returns a new instance of TransactionSampleBuilder.



31
32
33
34
35
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 31

def initialize(time=Time.now.to_f)
  @trace = TingYun::Agent::Transaction::Trace.new(time)
  @trace_start = time
  @current_node = @trace.root_node
end

Instance Attribute Details

#current_nodeObject (readonly)

Returns the value of attribute current_node.



29
30
31
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 29

def current_node
  @current_node
end

#traceObject (readonly)

Returns the value of attribute trace.



29
30
31
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 29

def trace
  @trace
end

Instance Method Details

#finish_trace(time = Time.now.to_f) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 85

def finish_trace(time=Time.now.to_f)

  if @trace.finished
    ::TingYun::Agent.logger.error "Unexpected double-finish_trace of Transaction Trace Object: \n#{@trace.to_s}"
    return
  end

  @trace.root_node.end_trace(time - @trace_start)

  @trace.threshold = transaction_trace_threshold
  @trace.finished = true
  @current_node = nil
end

#node_limitObject



110
111
112
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 110

def node_limit
  Agent.config[:'transaction_tracer.limit_segments']
end

#set_txId_and_txData(txid, txdata) ⇒ Object



105
106
107
108
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 105

def set_txId_and_txData(txid, txdata)
  @current_node[:txId] = txid
  @current_node[:txData] = txdata
end

#trace_entry(time) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 37

def trace_entry(time)
  if @trace.node_count == 0
    node = @trace.create_node(time - @trace_start)
    @trace.root_node = node
    @current_node = node
    return @current_node
  end
  if @trace.node_count < node_limit
    node = @trace.create_node(time - @trace_start)
    @current_node.add_called_node(node)
    @current_node = node

    if @trace.node_count == node_limit
      ::TingYun::Agent.logger.debug("Node limit of #{node_limit} reached, ceasing collection.")
    end
  else
    if @current_node.is_a?(PlaceholderNode)
      @current_node.depth += 1
    else
      @current_node = PlaceholderNode.new(@current_node)
    end
  end
  @current_node
end

#trace_exit(metric_name, time, klass_name, error = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 62

def trace_exit(metric_name, time, klass_name, error = nil)
  if @current_node.is_a?(PlaceholderNode)
    @current_node.depth -= 1
    if @current_node.depth == 0
      @current_node = @current_node.parent_node
    end
  else
    @current_node.metric_name = metric_name
    @current_node.klass = klass_name
    @current_node.end_trace(time - @trace_start)
    @current_node = @current_node.parent_node
  end
  if error
    unless trace.e_set.member? error.object_id
      trace.e_set.add error.object_id
      @current_node["exception"] << {"message" => error.message,
                                     "class" => error.class.to_s,
                                     "stacktrace"=> error.backtrace
      }
    end
  end
end

#transaction_trace_thresholdObject



100
101
102
# File 'lib/ting_yun/agent/transaction/transaction_sample_builder.rb', line 100

def transaction_trace_threshold
  Agent.config[:'nbs.action_tracer.action_threshold']
end