tingyun_rpm 1.1.4.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Guardfile +10 -0
- data/lib/ting_yun/agent.rb +1 -0
- data/lib/ting_yun/agent/agent.rb +16 -27
- data/lib/ting_yun/agent/collector/error_collector.rb +7 -18
- data/lib/ting_yun/agent/collector/error_collector/noticed_error.rb +26 -21
- data/lib/ting_yun/agent/collector/middle_ware_collector/cpu_sampler.rb +4 -9
- data/lib/ting_yun/agent/collector/sql_sampler.rb +32 -188
- data/lib/ting_yun/agent/collector/sql_sampler/slow_sql.rb +47 -0
- data/lib/ting_yun/agent/collector/sql_sampler/sql_trace.rb +73 -0
- data/lib/ting_yun/agent/collector/sql_sampler/transaction_sql_data.rb +26 -0
- data/lib/ting_yun/agent/collector/stats_engine/metric_stats.rb +6 -5
- data/lib/ting_yun/agent/collector/stats_engine/stats_hash.rb +2 -2
- data/lib/ting_yun/agent/collector/transaction_sampler.rb +23 -159
- data/lib/ting_yun/agent/collector/transaction_sampler/class_method.rb +130 -0
- data/lib/ting_yun/agent/collector/transaction_sampler/slowest_sample_buffer.rb +1 -1
- data/lib/ting_yun/agent/collector/transaction_sampler/transaction_sample_buffer_base.rb +1 -1
- data/lib/ting_yun/agent/cross_app/cross_app_monitor.rb +29 -79
- data/lib/ting_yun/agent/cross_app/cross_app_tracing.rb +36 -66
- data/lib/ting_yun/agent/database.rb +41 -349
- data/lib/ting_yun/agent/database/connection_manager.rb +44 -0
- data/lib/ting_yun/agent/database/explain_plan_helpers.rb +173 -0
- data/lib/ting_yun/agent/database/obfuscator.rb +151 -0
- data/lib/ting_yun/agent/database/statement.rb +70 -0
- data/lib/ting_yun/agent/event/event_loop.rb +1 -2
- data/lib/ting_yun/agent/instance_methods/connect.rb +8 -20
- data/lib/ting_yun/agent/instance_methods/container_data_manager.rb +2 -3
- data/lib/ting_yun/agent/instance_methods/handle_errors.rb +6 -1
- data/lib/ting_yun/agent/instance_methods/start.rb +13 -81
- data/lib/ting_yun/agent/transaction.rb +48 -391
- data/lib/ting_yun/agent/transaction/apdex.rb +53 -0
- data/lib/ting_yun/agent/transaction/attributes.rb +2 -1
- data/lib/ting_yun/agent/transaction/class_method.rb +127 -0
- data/lib/ting_yun/agent/transaction/exceptions.rb +42 -0
- data/lib/ting_yun/agent/transaction/instance_method.rb +139 -0
- data/lib/ting_yun/agent/transaction/request_attributes.rb +9 -39
- data/lib/ting_yun/agent/transaction/trace.rb +7 -5
- data/lib/ting_yun/agent/transaction/trace_node.rb +1 -3
- data/lib/ting_yun/agent/transaction/traced_method_stack.rb +2 -3
- data/lib/ting_yun/agent/transaction/transaction_sample_builder.rb +6 -1
- data/lib/ting_yun/agent/transaction/transaction_state.rb +59 -17
- data/lib/ting_yun/agent/transaction/transaction_timings.rb +72 -0
- data/lib/ting_yun/configuration.rb +11 -0
- data/lib/ting_yun/configuration/default_source.rb +20 -17
- data/lib/ting_yun/configuration/manager.rb +50 -21
- data/lib/ting_yun/frameworks.rb +1 -0
- data/lib/ting_yun/frameworks/rails.rb +15 -0
- data/lib/ting_yun/instrumentation/active_record.rb +12 -18
- data/lib/ting_yun/instrumentation/middleware_tracing.rb +8 -14
- data/lib/ting_yun/instrumentation/mongo.rb +21 -27
- data/lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb +7 -3
- data/lib/ting_yun/instrumentation/moped.rb +2 -2
- data/lib/ting_yun/instrumentation/net.rb +4 -5
- data/lib/ting_yun/instrumentation/rack.rb +1 -2
- data/lib/ting_yun/instrumentation/rails4/active_record_subscriber.rb +22 -20
- data/lib/ting_yun/instrumentation/redis.rb +2 -2
- data/lib/ting_yun/instrumentation/support/controller_instrumentation.rb +1 -1
- data/lib/ting_yun/instrumentation/support/external_error.rb +19 -16
- data/lib/ting_yun/instrumentation/support/javascript_instrumentor.rb +92 -0
- data/lib/ting_yun/instrumentation/support/thrift_helper.rb +73 -0
- data/lib/ting_yun/instrumentation/thrift.rb +19 -222
- data/lib/ting_yun/logger.rb +1 -0
- data/lib/ting_yun/logger/agent_logger.rb +11 -67
- data/lib/ting_yun/logger/create_logger_helper.rb +72 -0
- data/lib/ting_yun/metrics/metric_data.rb +9 -31
- data/lib/ting_yun/metrics/metric_spec.rb +11 -0
- data/lib/ting_yun/metrics/stats.rb +24 -1
- data/lib/ting_yun/middleware/agent_middleware.rb +28 -0
- data/lib/ting_yun/middleware/browser_monitoring.rb +111 -0
- data/lib/ting_yun/support/coerce.rb +1 -0
- data/lib/ting_yun/support/exception.rb +2 -33
- data/lib/ting_yun/support/local_environment.rb +7 -7
- data/lib/ting_yun/support/serialize/marshaller.rb +7 -25
- data/lib/ting_yun/ting_yun_service.rb +12 -9
- data/lib/ting_yun/ting_yun_service/connection.rb +3 -0
- data/lib/ting_yun/ting_yun_service/http.rb +4 -1
- data/lib/ting_yun/ting_yun_service/request.rb +5 -13
- data/lib/ting_yun/ting_yun_service/upload_service.rb +5 -7
- data/lib/ting_yun/version.rb +3 -5
- data/lib/tingyun_rpm.rb +12 -10
- data/tingyun_rpm.gemspec +3 -0
- metadata +49 -5
- data/.DS_Store +0 -0
- data/lib/ting_yun/agent/collector/base_sampler.rb +0 -2
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ting_yun/support/serialize/json_wrapper'
|
3
|
+
|
4
|
+
module TingYun
|
5
|
+
module Instrumentation
|
6
|
+
module Support
|
7
|
+
module JavascriptInstrument
|
8
|
+
|
9
|
+
GT = "}".freeze
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def browser_timing_header #THREAD_LOCAL_ACCESS
|
14
|
+
return '' unless rum_enable? # unsupport insert script
|
15
|
+
|
16
|
+
state = TingYun::Agent::TransactionState.tl_get
|
17
|
+
return '' unless insert_js?(state)
|
18
|
+
|
19
|
+
bt_config = browser_timing_config(state)
|
20
|
+
|
21
|
+
return '' if bt_config.empty?
|
22
|
+
|
23
|
+
if TingYun::Agent.config[:'nbs.rum.mix_enabled']
|
24
|
+
html_safe_if_needed("<script>(function(w){(w._ty_rum || (w._ty_rum = {})).agent = #{bt_config};})(window);</script>")
|
25
|
+
else
|
26
|
+
html_safe_if_needed("<script>#{browser_instrument("ty_rum.agent=#{bt_config}")}</script>")
|
27
|
+
end
|
28
|
+
rescue => e
|
29
|
+
::TingYun::Agent.logger.debug "Failure during RUM browser_timing_header construction", e
|
30
|
+
''
|
31
|
+
end
|
32
|
+
|
33
|
+
def rum_enable?
|
34
|
+
TingYun::Agent.config[:'nbs.rum.enabled']
|
35
|
+
end
|
36
|
+
|
37
|
+
def insert_js?(state)
|
38
|
+
if !state.current_transaction
|
39
|
+
::TingYun::Agent.logger.debug "Not in transaction. Skipping browser instrumentation."
|
40
|
+
false
|
41
|
+
elsif !state.transaction_traced?
|
42
|
+
::TingYun::Agent.logger.debug "Transaction is not traced. Skipping browser instrumentation."
|
43
|
+
false
|
44
|
+
elsif !state.execution_traced?
|
45
|
+
::TingYun::Agent.logger.debug "Execution is not traced. Skipping browser instrumentation."
|
46
|
+
false
|
47
|
+
else
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def browser_timing_config(state)
|
53
|
+
timings = state.timings
|
54
|
+
|
55
|
+
data = {
|
56
|
+
:id => TingYun::Agent.config[:tingyunIdSecret],
|
57
|
+
:n => state.transaction_name ,
|
58
|
+
:a => timings.app_time_in_millis,
|
59
|
+
:q => timings.queue_time_in_millis,
|
60
|
+
:tid => state.trace_id
|
61
|
+
}
|
62
|
+
TingYun::Support::Serialize::JSONWrapper.dump(data)
|
63
|
+
end
|
64
|
+
|
65
|
+
def html_safe_if_needed(string)
|
66
|
+
string = string.html_safe if string.respond_to?(:html_safe)
|
67
|
+
string
|
68
|
+
end
|
69
|
+
|
70
|
+
def browser_instrument(js)
|
71
|
+
script = TingYun::Agent.config[:'nbs.rum.script']
|
72
|
+
last_brace = script.rindex(GT) if script
|
73
|
+
if last_brace
|
74
|
+
script = script[0..last_brace-1] <<
|
75
|
+
js <<
|
76
|
+
script[last_brace..-1]
|
77
|
+
end
|
78
|
+
script
|
79
|
+
end
|
80
|
+
|
81
|
+
def find_brace_end
|
82
|
+
script = TingYun::Agent.config[:'nbs.rum.script']
|
83
|
+
last_brace = script.rindex(GT) if script
|
84
|
+
last_brace
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ting_yun/support/helper'
|
3
|
+
require 'ting_yun/agent'
|
4
|
+
require 'ting_yun/instrumentation/support/external_error'
|
5
|
+
|
6
|
+
module TingYun
|
7
|
+
module Instrumentation
|
8
|
+
module ThriftHelper
|
9
|
+
def operator result_klass
|
10
|
+
namespaces = result_klass.to_s.split('::')
|
11
|
+
operator_name = namespaces[0].downcase
|
12
|
+
if namespaces.last =~ /_result/
|
13
|
+
operator_name = "#{operator_name}.#{namespaces.last.sub('_result', '').downcase}"
|
14
|
+
elsif namespaces.last =~ /_args/
|
15
|
+
operator_name = "#{operator_name}.#{namespaces.last.sub('_args', '').downcase}"
|
16
|
+
end
|
17
|
+
|
18
|
+
operator_name
|
19
|
+
end
|
20
|
+
|
21
|
+
def operations
|
22
|
+
@operations ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def started_time_and_node(operate)
|
26
|
+
_op_ = operations.delete(operate)
|
27
|
+
time = (_op_ && _op_[:started_time]) || Time.now.to_f
|
28
|
+
node = _op_ && _op_[:node]
|
29
|
+
[time, node]
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def tingyun_socket
|
34
|
+
@iprot.instance_variable_get("@trans").instance_variable_get("@transport")
|
35
|
+
end
|
36
|
+
|
37
|
+
def tingyun_host
|
38
|
+
@tingyun_host ||= tingyun_socket.instance_variable_get("@host") rescue nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def tingyun_port
|
42
|
+
@tingyun_port ||= tingyun_socket.instance_variable_get("@port") rescue nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def metrics operate
|
46
|
+
state = TingYun::Agent::TransactionState.tl_get
|
47
|
+
metrics = if tingyun_host.nil?
|
48
|
+
["External/thrift:%2F%2F#{operate}/#{operate}"]
|
49
|
+
else
|
50
|
+
["External/thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/#{operate}"]
|
51
|
+
end
|
52
|
+
metrics << "External/NULL/ALL"
|
53
|
+
|
54
|
+
if TingYun::Agent::Transaction.recording_web_transaction?
|
55
|
+
metrics << "External/NULL/AllWeb"
|
56
|
+
else
|
57
|
+
metrics << "External/NULL/AllBackground"
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
my_data = state.thrift_return_data
|
62
|
+
|
63
|
+
|
64
|
+
if my_data && TingYun::Agent.config[:'nbs.transaction_tracer.thrift'] && TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
|
65
|
+
uri = "thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/#{operate}"
|
66
|
+
metrics << "cross_app;#{my_data["id"]};#{my_data["action"]};#{uri}"
|
67
|
+
end
|
68
|
+
return metrics
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,77 +1,4 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'ting_yun/support/helper'
|
3
|
-
require 'ting_yun/agent'
|
4
|
-
require 'ting_yun/instrumentation/support/external_error'
|
5
|
-
|
6
|
-
module TingYun
|
7
|
-
module Instrumentation
|
8
|
-
module ThriftHelper
|
9
|
-
def operator result_klass
|
10
|
-
namespaces = result_klass.to_s.split('::')
|
11
|
-
operator_name = namespaces[0].downcase
|
12
|
-
if namespaces.last =~ /_result/
|
13
|
-
operator_name = "#{operator_name}.#{namespaces.last.sub('_result', '').downcase}"
|
14
|
-
elsif namespaces.last =~ /_args/
|
15
|
-
operator_name = "#{operator_name}.#{namespaces.last.sub('_args', '').downcase}"
|
16
|
-
end
|
17
|
-
|
18
|
-
operator_name
|
19
|
-
end
|
20
|
-
|
21
|
-
def operations
|
22
|
-
@operations ||= {}
|
23
|
-
end
|
24
|
-
|
25
|
-
def started_time_and_node(operate)
|
26
|
-
_op_ = operations.delete(operate)
|
27
|
-
time = (_op_ && _op_[:started_time]) || Time.now.to_f
|
28
|
-
node = _op_ && _op_[:node]
|
29
|
-
[time, node]
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def tingyun_socket
|
34
|
-
@iprot.instance_variable_get("@trans").instance_variable_get("@transport")
|
35
|
-
end
|
36
|
-
|
37
|
-
def tingyun_host
|
38
|
-
@tingyun_host ||= tingyun_socket.instance_variable_get("@host") rescue nil
|
39
|
-
end
|
40
|
-
|
41
|
-
def tingyun_port
|
42
|
-
@tingyun_port ||= tingyun_socket.instance_variable_get("@port") rescue nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def metrics operate
|
46
|
-
state = TingYun::Agent::TransactionState.tl_get
|
47
|
-
metrics = if tingyun_host.nil?
|
48
|
-
["External/thrift:%2F%2F#{operate}/#{operate}"]
|
49
|
-
else
|
50
|
-
["External/thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/#{operate}"]
|
51
|
-
end
|
52
|
-
metrics << "External/NULL/ALL"
|
53
|
-
|
54
|
-
if TingYun::Agent::Transaction.recording_web_transaction?
|
55
|
-
metrics << "External/NULL/AllWeb"
|
56
|
-
else
|
57
|
-
metrics << "External/NULL/AllBackground"
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
my_data = state.thrift_return_data
|
62
|
-
|
63
|
-
|
64
|
-
if my_data
|
65
|
-
uri = "thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/#{operate}"
|
66
|
-
metrics << "cross_app;#{my_data["id"]};#{my_data["action"]};#{uri}"
|
67
|
-
end
|
68
|
-
return metrics
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
1
|
+
# encoding: utf-8
|
75
2
|
|
76
3
|
|
77
4
|
|
@@ -89,180 +16,51 @@ TingYun::Support::LibraryDetection.defer do
|
|
89
16
|
end
|
90
17
|
|
91
18
|
executes do
|
92
|
-
# ::Thrift::Processor.module_eval do
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# def same_account?(state)
|
97
|
-
# server_info = TingYun::Agent.config[:tingyunIdSecret].split('|')
|
98
|
-
# client_info = (state.client_tingyun_id_secret || '').split('|')
|
99
|
-
# if !server_info[0].nil? && server_info[0] == client_info[0] && !server_info[0].empty?
|
100
|
-
# return true
|
101
|
-
# else
|
102
|
-
# return false
|
103
|
-
# end
|
104
|
-
# end
|
105
|
-
# def write_result_with_tingyun(result, oprot, name, seqid)
|
106
|
-
#
|
107
|
-
# state = TingYun::Agent::TransactionState.tl_get
|
108
|
-
# oprot.write_message_begin(name, ::Thrift::MessageTypes::REPLY, seqid)
|
109
|
-
#
|
110
|
-
# if state.execution_traced? && same_account?(state)
|
111
|
-
# class_name = "WebAction/thrift/#{self.class.to_s.split('::').first.downcase}.#{name}"
|
112
|
-
# state.current_transaction.default_name = class_name
|
113
|
-
# data = TingYun::Support::Serialize::JSONWrapper.dump("TingyunTxData" => build_payload(state))
|
114
|
-
# oprot.write_field_begin("TingyunField", 11, 6)
|
115
|
-
# oprot.write_string(data)
|
116
|
-
# oprot.write_field_end
|
117
|
-
# write_result_without_tingyun(result, oprot, name, seqid)
|
118
|
-
# state.current_transaction.add_agent_attribute(:httpStatus, 200)
|
119
|
-
# TingYun::Agent::Transaction.stop(state)
|
120
|
-
# else
|
121
|
-
# write_result_without_tingyun(result, oprot, name, seqid)
|
122
|
-
# end
|
123
|
-
# end
|
124
|
-
#
|
125
|
-
# def write_error_with_tingyun(err, oprot, name, seqid)
|
126
|
-
# p 'write_error'
|
127
|
-
# state = TingYun::Agent::TransactionState.tl_get
|
128
|
-
# oprot.write_message_begin(name, ::Thrift::MessageTypes::EXCEPTION, seqid)
|
129
|
-
#
|
130
|
-
# if state.execution_traced? && same_account?(state)
|
131
|
-
#
|
132
|
-
# class_name = "WebAction/thrift/#{self.class.to_s.split('::').first.downcase}.#{name}"
|
133
|
-
# state.current_transaction.default_name = class_name
|
134
|
-
# data = TingYun::Support::Serialize::JSONWrapper.dump("TingyunTxData" => build_payload(state))
|
135
|
-
# oprot.write_field_begin("TingyunField", 11, 6)
|
136
|
-
# oprot.write_string(data)
|
137
|
-
# oprot.write_field_end
|
138
|
-
# write_result_without_tingyun(err, oprot, name, seqid)
|
139
|
-
# p 'write_error end'
|
140
|
-
# state.current_transaction.add_agent_attribute(:httpStatus, 500)
|
141
|
-
#
|
142
|
-
# TingYun::Agent::Transaction.stop(state)
|
143
|
-
# else
|
144
|
-
# write_result_without_tingyun(err, oprot, name, seqid)
|
145
|
-
# end
|
146
|
-
# end
|
147
|
-
#
|
148
|
-
#
|
149
|
-
# def build_payload(state)
|
150
|
-
# state.web_duration = TingYun::Helper.time_to_millis(Time.now - state.current_transaction.start_time)
|
151
|
-
# payload = {
|
152
|
-
# :id => TingYun::Agent.config[:tingyunIdSecret].split('|')[1],
|
153
|
-
# :action => state.current_transaction.best_name,
|
154
|
-
# :trId => state.transaction_sample_builder.trace.guid,
|
155
|
-
# :time => {
|
156
|
-
# :duration => state.web_duration,
|
157
|
-
# :qu => state.queue_duration,
|
158
|
-
# :db => state.sql_duration,
|
159
|
-
# :ex => state.external_duration,
|
160
|
-
# :rds => state.rds_duration,
|
161
|
-
# :mc => state.mc_duration,
|
162
|
-
# :mon => state.mon_duration,
|
163
|
-
# :code => execute_duration(state)
|
164
|
-
# }
|
165
|
-
# }
|
166
|
-
# payload[:tr] = 1 if slow_action_tracer?(state)
|
167
|
-
# payload[:r] = state.client_req_id unless state.client_req_id.nil?
|
168
|
-
# payload
|
169
|
-
# end
|
170
|
-
#
|
171
|
-
# def slow_action_tracer?(state)
|
172
|
-
# if state.web_duration > TingYun::Agent.config[:'nbs.action_tracer.action_threshold']
|
173
|
-
# return true
|
174
|
-
# else
|
175
|
-
# return false
|
176
|
-
# end
|
177
|
-
# end
|
178
|
-
#
|
179
|
-
# def write_result_without_tingyun(result, oprot, name, seqid)
|
180
|
-
# result.write(oprot)
|
181
|
-
# oprot.write_message_end
|
182
|
-
# oprot.trans.flush
|
183
|
-
# end
|
184
|
-
#
|
185
|
-
# def execute_duration(state)
|
186
|
-
# state.web_duration - state.queue_duration - state.sql_duration - state.external_duration - state.rds_duration - state.mc_duration - state.mon_duration
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# alias :write_result :write_result_with_tingyun
|
190
|
-
# alias :write_error :write_error_with_tingyun
|
191
|
-
# # alias :write_result_without_tingyun :write_result
|
192
|
-
# end
|
193
19
|
|
194
20
|
::Thrift::BaseProtocol.class_eval do
|
195
21
|
|
196
22
|
def skip_with_tingyun(type)
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
state.thrift_return_data = my_data["TingyunTxData"]
|
206
|
-
|
207
|
-
transaction_sampler = ::TingYun::Agent.instance.transaction_sampler
|
208
|
-
transaction_sampler.tl_builder.current_node[:txId] = state.request_guid
|
209
|
-
transaction_sampler.tl_builder.current_node[:txData] = my_data["TingyunTxData"]
|
210
|
-
# elsif data.include?("TingyunID")
|
211
|
-
# TingYun::Agent::Transaction.start(state, :thrift, :apdex_start_time => Time.now)
|
212
|
-
# my_data = TingYun::Support::Serialize::JSONWrapper.load data.gsub("'",'"')
|
213
|
-
# save_referring_transaction_info(state, my_data)
|
23
|
+
begin
|
24
|
+
data = skip_without_tingyun(type)
|
25
|
+
ensure
|
26
|
+
if data.is_a? ::String
|
27
|
+
if data.include?("TingyunTxData")
|
28
|
+
my_data = TingYun::Support::Serialize::JSONWrapper.load data.gsub("'",'"')
|
29
|
+
TingYun::Agent::TransactionState.process_thrift_data(my_data["TingyunTxData"])
|
30
|
+
end
|
214
31
|
end
|
215
32
|
end
|
216
33
|
end
|
217
34
|
|
218
|
-
def save_referring_transaction_info(state,data)
|
219
|
-
|
220
|
-
info = data["TingyunID"].split(';')
|
221
|
-
tingyun_id_secret = info[0]
|
222
|
-
client_transaction_id = info.find do |e|
|
223
|
-
e.match(/x=/)
|
224
|
-
end.split('=')[1] rescue nil
|
225
|
-
client_req_id = info.find do |e|
|
226
|
-
e.match(/r=/)
|
227
|
-
end.split('=')[1] rescue nil
|
228
|
-
|
229
|
-
state.client_tingyun_id_secret = tingyun_id_secret
|
230
|
-
state.client_transaction_id = client_transaction_id
|
231
|
-
state.client_req_id = client_req_id
|
232
|
-
state.transaction_sample_builder.trace.tx_id = client_transaction_id
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
35
|
alias :skip_without_tingyun :skip
|
237
36
|
alias :skip :skip_with_tingyun
|
238
37
|
end
|
239
38
|
|
240
39
|
::Thrift::Client.module_eval do
|
40
|
+
require 'ting_yun/instrumentation/support/thrift_helper'
|
241
41
|
|
242
42
|
include TingYun::Instrumentation::ThriftHelper
|
243
43
|
|
244
44
|
|
245
45
|
def send_message_args_with_tingyun(args_class, args = {})
|
46
|
+
return send_message_args_without_tingyun(args_class, args) unless TingYun::Agent.config[:'nbs.transaction_tracer.thrift'] && TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
|
246
47
|
begin
|
247
48
|
state = TingYun::Agent::TransactionState.tl_get
|
248
49
|
return unless state.execution_traced?
|
249
50
|
cross_app_id = TingYun::Agent.config[:tingyunIdSecret] or
|
250
51
|
raise TingYun::Agent::CrossAppTracing::Error, "no tingyunIdSecret configured"
|
251
|
-
|
252
|
-
tingyun_id = "#{cross_app_id};c=1;x=#{txn_guid}"
|
253
|
-
state.transaction_sample_builder.trace.tx_id = txn_guid
|
52
|
+
tingyun_id = "#{cross_app_id};c=1;x=#{state.request_guid}"
|
254
53
|
|
255
54
|
data = TingYun::Support::Serialize::JSONWrapper.dump("TingyunID" => tingyun_id)
|
256
55
|
@oprot.write_field_begin("TingyunField", 11, 6)
|
257
56
|
@oprot.write_string(data)
|
258
57
|
@oprot.write_field_end
|
259
58
|
rescue => e
|
260
|
-
|
59
|
+
TingYun::Agent.logger.error("Failed to thrift send_message_args_with_tingyun : ", e)
|
261
60
|
ensure
|
262
61
|
send_message_args_without_tingyun(args_class, args)
|
263
62
|
end
|
264
63
|
end
|
265
|
-
|
266
64
|
alias :send_message_args_without_tingyun :send_message_args
|
267
65
|
alias :send_message_args :send_message_args_with_tingyun
|
268
66
|
|
@@ -279,7 +77,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
279
77
|
node = stack.push_frame(state,:thrift,t0)
|
280
78
|
operations[tag][:node] = node
|
281
79
|
rescue => e
|
282
|
-
|
80
|
+
TingYun::Agent.logger.debug("Failed to thrift send_message_with_tingyun : ", e)
|
283
81
|
ensure
|
284
82
|
send_message_without_tingyun(name, args_class, args)
|
285
83
|
end
|
@@ -300,7 +98,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
300
98
|
TingYun::Agent.instance.stats_engine.tl_record_scoped_and_unscoped_metrics(base, other_metrics, duration)
|
301
99
|
result
|
302
100
|
rescue => e
|
303
|
-
|
101
|
+
TingYun::Agent.logger.debug("Failed to thrift send_oneway_message_with_tingyun : ", e)
|
304
102
|
return send_oneway_message_without_tingyun(name, args_class, args)
|
305
103
|
end
|
306
104
|
|
@@ -318,7 +116,7 @@ TingYun::Support::LibraryDetection.defer do
|
|
318
116
|
|
319
117
|
|
320
118
|
result = receive_message_without_tingyun(result_klass)
|
321
|
-
|
119
|
+
unless result || result.success
|
322
120
|
e = ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, "#{operate} failed: unknown result")
|
323
121
|
::TingYun::Instrumentation::Support::ExternalError.handle_error(e,metrics(operate)[0])
|
324
122
|
end
|
@@ -332,15 +130,15 @@ TingYun::Support::LibraryDetection.defer do
|
|
332
130
|
)
|
333
131
|
if node
|
334
132
|
node.name = node_name
|
335
|
-
|
336
|
-
transaction_sampler.add_node_info(:uri => "thrift:#{tingyun_host}:#{tingyun_port}/#{operate}")
|
133
|
+
::TingYun::Agent::Collector::TransactionSampler.add_node_info(:uri => "thrift:#{tingyun_host}:#{tingyun_port}/#{operate}")
|
337
134
|
stack = state.traced_method_stack
|
338
135
|
stack.pop_frame(state, node, node_name, t1)
|
339
136
|
end
|
340
137
|
|
341
138
|
result
|
342
139
|
rescue => e
|
343
|
-
|
140
|
+
|
141
|
+
TingYun::Agent.logger.debug("Failed to thrift receive_message_with_tingyun : ", e)
|
344
142
|
return receive_message_without_tingyun(result_klass)
|
345
143
|
end
|
346
144
|
end
|
@@ -349,5 +147,4 @@ TingYun::Support::LibraryDetection.defer do
|
|
349
147
|
alias :receive_message :receive_message_with_tingyun
|
350
148
|
end
|
351
149
|
end
|
352
|
-
|
353
150
|
end
|