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



119
120
121
122
123
124
125
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 119

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
# 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)
  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



127
128
129
130
131
132
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 127

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



134
135
136
137
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 134

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

#start(state, category, options) ⇒ Object



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

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

  # merge params every step into here
  txn.attributes.merge_request_parameters(options[:filtered_params])

  txn
rescue => e
  TingYun::Agent.logger.error("Exception during Transaction.start", e)
end

#start_new_transaction(state, category, options) ⇒ Object



112
113
114
115
116
117
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 112

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, summary_metric_names = []) ⇒ Object



36
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
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 36

def stop(state, end_time = Time.now, 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 = 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.to_f,
        nested_name,
        summary_metrics,
        nested_frame,
        NESTED_TRACE_STOP_OPTIONS,
        end_time.to_f)

  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



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

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
    Transaction.notice_error(e)
    raise e
  ensure
    # when kafka consumer in task, drop original web_action
    Transaction.stop(state, Time.now, summary_metrics) if state.current_transaction
  end
end