Module: TingYun::Agent::Transaction::ClassMethod

Included in:
TingYun::Agent::Transaction
Defined in:
lib/ting_yun/agent/transaction/class_method.rb

Overview

web transaction

Instance Method Summary collapse

Instance Method Details

#metricsObject



13
14
15
16
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 13

def metrics
  txn = tl_current
  txn && txn.metrics
end

#nested_transaction_name(name) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 116

def nested_transaction_name(name)
  if name.start_with?(CONTROLLER_PREFIX) || name.start_with?(BACKGROUND_PREFIX)
    "#{SUBTRANSACTION_PREFIX}#{name}"
  else
    name
  end
end

#notice_error(e, options = {}) ⇒ Object

See TingYun::Agent.notice_error for options and commentary



25
26
27
28
29
30
31
32
33
34
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 25

def notice_error(e, options={})
  state = TingYun::Agent::TransactionState.tl_get
  txn = state.current_transaction
  if txn
    txn.exceptions.notice_error(e, options)
    state.transaction_sample_builder.trace.add_errors_to_current_node(state,e) rescue nil
  elsif TingYun::Agent.instance
    TingYun::Agent.instance.error_collector.notice_error(e, options)
  end
end

#recording_web_transaction?Boolean

THREAD_LOCAL_ACCESS

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 19

def recording_web_transaction? #THREAD_LOCAL_ACCESS
  txn = tl_current
  txn && txn.web_category?(txn.category)
end

#set_default_transaction_name(name, category = nil, node_name = nil) ⇒ Object

THREAD_LOCAL_ACCESS



124
125
126
127
128
129
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 124

def set_default_transaction_name(name, category = nil, node_name = nil) #THREAD_LOCAL_ACCESS
  txn  = tl_current
  name = txn.make_transaction_name(name, category)
  txn.name_last_frame(node_name || name)
  txn.set_default_transaction_name(name, category)
end

#set_frozen_transaction_name!(name) ⇒ Object

THREAD_LOCAL_ACCESS



131
132
133
134
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 131

def set_frozen_transaction_name!(name) #THREAD_LOCAL_ACCESS
  txn  = tl_current
  txn.frozen_name = name
end

#start(state, category, options) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 96

def start(state, category, options)
  category ||= :controller
  txn = state.current_transaction
  if txn
    txn.create_nested_frame(state, category, options)
  else
    txn = start_new_transaction(state, category, options)
  end
  txn
rescue => e
  TingYun::Agent.logger.error("Exception during Transaction.start", e)
end

#start_new_transaction(state, category, options) ⇒ Object



109
110
111
112
113
114
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 109

def start_new_transaction(state, category, options)
  txn = Transaction.new(category, state.client_transaction_id, options)
  state.reset(txn)
  txn.start(state)
  txn
end

#stop(state, end_time = Time.now.to_f, summary_metric_names = []) ⇒ 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 37

def stop(state, end_time = Time.now.to_f, summary_metric_names=[])

  txn = state.current_transaction

  unless txn
    TingYun::Agent.logger.error("Failed during Transaction.stop because there is no current transaction")
    return
  end

  nested_frame = txn.frame_stack.pop

  if txn.frame_stack.empty?
    txn.stop(state, end_time, nested_frame, summary_metric_names)
    state.reset
  else
    nested_name = Transaction.nested_transaction_name nested_frame.name

    # if nested_name.start_with?(MIDDLEWARE_PREFIX)
    #   summary_metrics = MIDDLEWARE_SUMMARY_METRICS
    # else
    #   summary_metrics = EMPTY_SUMMARY_METRICS
    # end
    # summary_metrics = summary_metric_names unless summary_metric_names.empty?

    TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_footer(
        state,
        nested_frame.start_time,
        nested_name,
        EMPTY_SUMMARY_METRICS,
        nested_frame,
        NESTED_TRACE_STOP_OPTIONS,
        end_time)

  end

  :transaction_stopped
rescue => e
  state.reset
  TingYun::Agent.logger.error("Exception during Transaction.stop", e)
  nil
end

#tl_currentObject



9
10
11
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 9

def tl_current
  TingYun::Agent::TransactionState.tl_get.current_transaction
end

#wrap(state, name, category, options = {}, summary_metrics = []) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 79

def wrap(state, name, category, options = {}, summary_metrics=[])
  Transaction.start(state, category, options.merge(:transaction_name => name))

  begin
    # We shouldn't raise from Transaction.start, but only wrap the yield
    # to be absolutely sure we don't report agent problems as app errors
    yield
  rescue => e
    ::TingYun::Agent.notice_error(e,:type=> :exception)
    raise e
  ensure
    # when kafka consumer in task, drop original web_action
    Transaction.stop(state, Time.now.to_f, summary_metrics) if state.current_transaction
  end
end