tingyun_rpm 1.6.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ting_yun/agent.rb +9 -2
  3. data/lib/ting_yun/agent/agent.rb +3 -2
  4. data/lib/ting_yun/agent/collector/error_collector/noticed_error.rb +1 -1
  5. data/lib/ting_yun/agent/collector/sql_sampler.rb +2 -2
  6. data/lib/ting_yun/agent/collector/transaction_sampler.rb +2 -2
  7. data/lib/ting_yun/agent/collector/transaction_sampler/class_method.rb +22 -7
  8. data/lib/ting_yun/agent/collector/transaction_sampler/slowest_sample_buffer.rb +3 -3
  9. data/lib/ting_yun/agent/collector/transaction_sampler/transaction_sample_buffer_base.rb +15 -2
  10. data/lib/ting_yun/agent/cross_app/cross_app_monitor.rb +22 -19
  11. data/lib/ting_yun/agent/cross_app/cross_app_tracing.rb +48 -14
  12. data/lib/ting_yun/agent/database.rb +1 -1
  13. data/lib/ting_yun/agent/datastore.rb +13 -2
  14. data/lib/ting_yun/agent/datastore/metric_helper.rb +8 -7
  15. data/lib/ting_yun/agent/instance_methods/connect.rb +21 -8
  16. data/lib/ting_yun/agent/instance_methods/container_data_manager.rb +20 -8
  17. data/lib/ting_yun/agent/instance_methods/start.rb +3 -3
  18. data/lib/ting_yun/agent/instance_methods/start_worker_thread.rb +9 -4
  19. data/lib/ting_yun/agent/method_tracer_helpers.rb +29 -1
  20. data/lib/ting_yun/agent/transaction.rb +24 -6
  21. data/lib/ting_yun/agent/transaction/attributes.rb +17 -2
  22. data/lib/ting_yun/agent/transaction/class_method.rb +1 -0
  23. data/lib/ting_yun/agent/transaction/instance_method.rb +10 -4
  24. data/lib/ting_yun/agent/transaction/request_attributes.rb +42 -3
  25. data/lib/ting_yun/agent/transaction/trace.rb +53 -6
  26. data/lib/ting_yun/agent/transaction/trace_node.rb +48 -12
  27. data/lib/ting_yun/agent/transaction/traced_method_stack.rb +1 -1
  28. data/lib/ting_yun/agent/transaction/transaction_sample_builder.rb +12 -11
  29. data/lib/ting_yun/agent/transaction/transaction_state.rb +16 -5
  30. data/lib/ting_yun/agent/transaction/transaction_timings.rb +1 -1
  31. data/lib/ting_yun/configuration/default_source.rb +327 -16
  32. data/lib/ting_yun/configuration/manager.rb +0 -1
  33. data/lib/ting_yun/configuration/server_source.rb +8 -2
  34. data/lib/ting_yun/configuration/yaml_source.rb +1 -1
  35. data/lib/ting_yun/frameworks/instance_methods.rb +2 -2
  36. data/lib/ting_yun/frameworks/rails.rb +2 -2
  37. data/lib/ting_yun/http/abstract_request.rb +12 -0
  38. data/lib/ting_yun/http/curb_wrappers.rb +1 -1
  39. data/lib/ting_yun/http/excon_wrappers.rb +9 -1
  40. data/lib/ting_yun/http/http_client_request.rb +13 -2
  41. data/lib/ting_yun/http/net_http_request.rb +10 -2
  42. data/lib/ting_yun/http/typhoeus_wrappers.rb +1 -1
  43. data/lib/ting_yun/instrumentation/active_record.rb +3 -5
  44. data/lib/ting_yun/instrumentation/bunny.rb +48 -44
  45. data/lib/ting_yun/instrumentation/grape.rb +4 -2
  46. data/lib/ting_yun/instrumentation/http_client.rb +1 -1
  47. data/lib/ting_yun/instrumentation/kafka.rb +18 -15
  48. data/lib/ting_yun/instrumentation/middleware_proxy.rb +3 -2
  49. data/lib/ting_yun/instrumentation/mongo.rb +2 -2
  50. data/lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb +9 -9
  51. data/lib/ting_yun/instrumentation/rails3/action_controller.rb +3 -3
  52. data/lib/ting_yun/instrumentation/rake.rb +2 -1
  53. data/lib/ting_yun/instrumentation/redis.rb +6 -0
  54. data/lib/ting_yun/instrumentation/sidekiq.rb +1 -1
  55. data/lib/ting_yun/instrumentation/sinatra/action.rb +1 -1
  56. data/lib/ting_yun/instrumentation/support/action_cable_subscriber.rb +2 -2
  57. data/lib/ting_yun/instrumentation/support/action_controller_subscriber.rb +4 -4
  58. data/lib/ting_yun/instrumentation/support/action_view_subscriber.rb +14 -1
  59. data/lib/ting_yun/instrumentation/support/active_record_helper.rb +6 -2
  60. data/lib/ting_yun/instrumentation/support/active_record_subscriber.rb +14 -7
  61. data/lib/ting_yun/instrumentation/support/event_formatter.rb +7 -2
  62. data/lib/ting_yun/instrumentation/support/external_error.rb +1 -1
  63. data/lib/ting_yun/instrumentation/support/external_helper.rb +27 -4
  64. data/lib/ting_yun/instrumentation/support/javascript_instrumentor.rb +1 -1
  65. data/lib/ting_yun/instrumentation/support/method_instrumentation.rb +6 -1
  66. data/lib/ting_yun/instrumentation/support/parameter_filtering.rb +1 -1
  67. data/lib/ting_yun/instrumentation/support/thrift_helper.rb +4 -3
  68. data/lib/ting_yun/instrumentation/thrift.rb +7 -7
  69. data/lib/ting_yun/logger/create_logger_helper.rb +1 -1
  70. data/lib/ting_yun/middleware/agent_middleware.rb +1 -1
  71. data/lib/ting_yun/middleware/browser_monitoring.rb +3 -2
  72. data/lib/ting_yun/support/collector.rb +7 -1
  73. data/lib/ting_yun/ting_yun_service.rb +38 -21
  74. data/lib/ting_yun/ting_yun_service/http.rb +5 -3
  75. data/lib/ting_yun/ting_yun_service/request.rb +32 -6
  76. data/lib/ting_yun/ting_yun_service/upload_service.rb +25 -3
  77. data/lib/ting_yun/version.rb +4 -3
  78. data/lib/tingyun_rpm.rb +0 -2
  79. data/tingyun_rpm.gemspec +1 -0
  80. metadata +2 -2
@@ -9,8 +9,9 @@ module TingYun
9
9
  module Datastore
10
10
  def self.wrap(product, operation, collection = nil, ip_address = nil, port = nil, dbname=nil, callback = nil )
11
11
  return yield unless operation
12
-
13
- klass_name, *metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for(product, operation, ip_address , port, dbname,collection )
12
+ klass_name, *metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for(product, operation, ip_address ,
13
+ port,
14
+ dbname,collection )
14
15
  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, {}, nil, klass_name) do
15
16
  t0 = Time.now
16
17
  begin
@@ -20,6 +21,16 @@ module TingYun
20
21
  if callback
21
22
  callback.call(elapsed_time)
22
23
  end
24
+ config = {
25
+ :product => product,
26
+ :operation => operation,
27
+ :database => collection,
28
+ :host => ip_address,
29
+ :port => port,
30
+ :type => product,
31
+ :nosql => klass_name
32
+ }
33
+ ::TingYun::Agent::Collector::TransactionSampler.notice_nosql_statement(config,elapsed_time*1000, :nosql)
23
34
  end
24
35
  end
25
36
  end
@@ -20,19 +20,19 @@ module TingYun
20
20
 
21
21
  def self.metric_name(product, collection, operation,host,port,dbname)
22
22
  if checkNosql(product)
23
- return "#{product}/#{host}:#{port}%2F#{dbname}%2F#{collection}/#{operation}" if product=="MongoDB"
24
- "#{product}/#{host}:#{port}%2F#{collection}/#{operation}"
23
+ return "#{product}/#{host}:#{port}/#{dbname}/#{collection}/#{operation}" if product=="MongoDB"
24
+ "#{product}/#{host}:#{port}/#{collection}/#{operation}"
25
25
  else
26
- "Database #{product}/#{host}:#{port}%2F#{dbname}%2F#{collection}/#{operation}"
26
+ "Database #{product}/#{host}:#{port}/#{dbname}/#{collection}/#{operation}"
27
27
  end
28
28
  end
29
29
 
30
30
  def self.metric_name_others(product, collection, operation)
31
31
  collection ||= 'NULL'
32
32
  if checkNosql(product)
33
- "#{product}%2F#{collection}/#{operation}"
33
+ "#{product}/#{collection}/#{operation}"
34
34
  else
35
- "Database #{product}%2F#{collection}/#{operation}"
35
+ "Database #{product}/#{collection}/#{operation}"
36
36
  end
37
37
  end
38
38
 
@@ -68,9 +68,10 @@ module TingYun
68
68
  end
69
69
 
70
70
  if checkNosql(product)
71
- metrics << (product=="MongoDB" ? "#{product}/#{host}:#{port}%2F#{dbname}/All" : "#{product}/#{host}:#{port}/All")
71
+ metrics << (product=="MongoDB" ? "#{product}/#{host}:#{port}/#{dbname}/All" :
72
+ "#{product}/#{host}:#{port}/All")
72
73
  else
73
- metrics << "Database #{product}/#{host}:#{port}%2F#{dbname}/All"
74
+ metrics << "Database #{product}/#{host}:#{port}/#{dbname}/All"
74
75
  end
75
76
  metrics.unshift metric_name(product, collection, operation,host,port,dbname) if collection
76
77
  metrics.unshift "#{product}/#{host}:#{port}/#{operation}" if product=="Memcached"
@@ -7,6 +7,7 @@ require 'ting_yun/agent/instance_methods/handle_errors'
7
7
  require 'ting_yun/environment_report'
8
8
 
9
9
 
10
+
10
11
  module TingYun
11
12
  module Agent
12
13
  module InstanceMethods
@@ -70,14 +71,23 @@ module TingYun
70
71
  def connect_settings
71
72
  sanitize_environment_report
72
73
  settings = {
73
- :pid => $$,
74
- :port => ::TingYun::Agent.config[:port],
75
74
  :host => local_host,
76
- :appName => ::TingYun::Agent.config.app_names,
75
+ :port => ::TingYun::Agent.config[:port],
76
+ :instanceName => ::TingYun::Agent.config[:'instance.name'],
77
+ :appName => ::TingYun::Agent.config[:app_name],
77
78
  :language => 'Ruby',
78
- :agentVersion => ::TingYun::VERSION::STRING,
79
- :env => @environment_report,
80
- :config => ::TingYun::Agent.config.to_collector_hash
79
+ :agentVersion => TingYun::VERSION::STRING,
80
+ :firstRun => @connect_state==:first,
81
+ :oneAgentUuid=> 'oneAgentUuid',
82
+ :environment => {
83
+ :meta => {
84
+ :pid => $$,
85
+ :agentVersion => ::TingYun::VERSION::STRING,
86
+ :readonly => true
87
+ },
88
+ :env => @environment_report,
89
+ :config => ::TingYun::Agent.config.to_collector_hash
90
+ }
81
91
  }
82
92
  settings
83
93
  end
@@ -108,13 +118,15 @@ module TingYun
108
118
  handle_force_restart(e)
109
119
  retry
110
120
  rescue TingYun::Support::Exception::ServerConnectionException => e
111
- handle_delay_restart(e, 60)
121
+ handle_delay_restart(e, 30)
112
122
  retry
113
123
  rescue => e
114
- handle_delay_restart(e, 60)
124
+ handle_delay_restart(e, 30)
115
125
  retry
116
126
  end
117
127
 
128
+
129
+
118
130
  # Takes a hash of configuration data returned from the
119
131
  # server and uses it to set local variables and to
120
132
  # initialize various parts of the agent that are configured
@@ -151,6 +163,7 @@ module TingYun
151
163
  TingYun::Agent.disable_all_tracing { connect!(:keep_retrying => false) }
152
164
  end
153
165
  end
166
+
154
167
  end
155
168
  end
156
169
  end
@@ -7,7 +7,6 @@ require 'ting_yun/agent/collector/transaction_sampler'
7
7
 
8
8
  require 'ting_yun/agent/collector/sql_sampler'
9
9
 
10
-
11
10
  module TingYun
12
11
  module Agent
13
12
  module InstanceMethods
@@ -32,7 +31,7 @@ module TingYun
32
31
  def init_containers
33
32
  @stats_engine = TingYun::Agent::Collector::StatsEngine.new
34
33
  @error_collector = TingYun::Agent::Collector::ErrorCollector.new
35
- @transaction_sampler = TingYun::Agent::Collector::TransactionSampler.new
34
+ @transaction_sampler = TingYun::Agent::Collector::TransactionSampler.new
36
35
  @sql_sampler = TingYun::Agent::Collector::SqlSampler.new
37
36
  end
38
37
 
@@ -49,12 +48,12 @@ module TingYun
49
48
 
50
49
  @events.notify(:middleware_harvest)
51
50
  @service.session do # use http keep-alive
52
- harvest_and_send_errors
53
- harvest_and_send_external_errors
54
- harvest_and_send_exceptions
55
- harvest_and_send_timeslice_data
51
+ # harvest_and_send_errors
52
+ # harvest_and_send_external_errors
53
+ # harvest_and_send_exceptions
54
+ # harvest_and_send_timeslice_data
56
55
  harvest_and_send_transaction_traces
57
- harvest_and_send_slowest_sql
56
+ # harvest_and_send_slowest_sql
58
57
  end
59
58
  end
60
59
 
@@ -123,7 +122,7 @@ module TingYun
123
122
  items
124
123
  end
125
124
 
126
- def send_data_to_endpoint(endpoint, items, container)
125
+ def send_data_to_endpointV2(endpoint, items, container)
127
126
  TingYun::Agent.logger.info("Sending #{items.size} items to #{endpoint}")
128
127
  begin
129
128
  if container.respond_to?(:harvest_base_quantile_hash!)
@@ -142,6 +141,19 @@ module TingYun
142
141
 
143
142
  end
144
143
 
144
+ def send_data_to_endpoint(endpoint, items, container)
145
+ TingYun::Agent.logger.info("Sending #{items.size} items to #{endpoint}")
146
+ begin
147
+ @service.send(endpoint, items)
148
+ rescue => e
149
+ TingYun::Agent.logger.info("Unable to send #{endpoint} data, will try again later. Error: ", e)
150
+ # container.merge!(items)
151
+ raise
152
+ ensure
153
+ items = nil # to GC
154
+ end
155
+ end
156
+
145
157
  end
146
158
 
147
159
  end
@@ -12,10 +12,10 @@ module TingYun
12
12
  # Check to see if the agent should start, returning +true+ if it should.
13
13
  # should hava the vaild app_name, unstart-state and able to start
14
14
  # The agent is disabled when it is not force enabled by the
15
- # 'nbs.agent_enabled' option (e.g. in a manual start), or
15
+ # 'agent_enabled' option (e.g. in a manual start), or
16
16
  # enabled normally through the configuration file
17
17
  def agent_should_start?
18
- return false if already_started? || !TingYun::Agent.config[:'nbs.agent_enabled']
18
+ return false if already_started? || !TingYun::Agent.config[:'agent_enabled']
19
19
  unless app_name_configured?
20
20
  TingYun::Agent.logger.error "No application name configured.",
21
21
  "The Agent cannot start without at least one. Please check your ",
@@ -136,7 +136,7 @@ module TingYun
136
136
  end
137
137
 
138
138
  return if !needs_restart ||
139
- !Agent.config[:'nbs.agent_enabled'] || disconnected?
139
+ !Agent.config[:'agent_enabled'] || disconnected?
140
140
 
141
141
  ::TingYun::Agent.logger.debug "Starting the worker thread in #{Process.pid} (parent #{Process.ppid}) after forking."
142
142
 
@@ -37,17 +37,22 @@ module TingYun
37
37
 
38
38
  def create_and_run_event_loop
39
39
  @event_loop = TingYun::Agent::Event::EventLoop.new
40
-
41
- @event_loop.on(:report_data) do
42
- transmit_data
40
+ @event_loop.on(:getCmd) do
41
+ @service.getCmd
43
42
  end
44
- @event_loop.fire_every(Agent.config[:data_report_period], :report_data)
43
+ @event_loop.fire_every(30, :getCmd)
44
+ #
45
+ # @event_loop.on(:report_data) do
46
+ # transmit_data
47
+ # end
48
+ # @event_loop.fire_every(Agent.config[:data_report_period], :report_data)
45
49
 
46
50
  @event_loop.on(:create_new_logfile) do
47
51
  TingYun::Logger::CreateLoggerHelper.create_new_logfile
48
52
  end
49
53
  @event_loop.fire_every(TingYun::Agent.config[:agent_log_file_check_days]*60*60*24, :create_new_logfile)
50
54
 
55
+
51
56
  @event_loop.run
52
57
  end
53
58
  end
@@ -22,7 +22,8 @@ module TingYun
22
22
  end
23
23
  end
24
24
 
25
- def trace_execution_scoped_footer(state, t0, first_name, metric_names, expected_frame, options, t1=Time.now.to_f, klass_name=nil, error = nil)
25
+ def trace_execution_scoped_footerV2(state, t0, first_name, metric_names, expected_frame, options, t1=Time.now
26
+ .to_f, klass_name=nil, error = nil)
26
27
  log_errors(:trace_execution_scoped_footer) do
27
28
  if expected_frame
28
29
  stack = state.traced_method_stack
@@ -49,6 +50,33 @@ module TingYun
49
50
  end
50
51
  end
51
52
 
53
+ def trace_execution_scoped_footer(state, t0, first_name, metric_names, expected_frame, options, t1=Time.now.to_f, klass_name=nil, error = nil)
54
+ log_errors(:trace_execution_scoped_footer) do
55
+ if expected_frame
56
+ stack = state.traced_method_stack
57
+ create_metrics = options.has_key?(:metric) ? options[:metric] : true
58
+ frame = stack.pop_frame(state, expected_frame, first_name, t1, create_metrics, klass_name, error)
59
+
60
+ if create_metrics
61
+ duration = (t1 - t0)*1000
62
+ exclusive = duration - frame.children_time
63
+ if duration < 0
64
+ ::TingYun::Agent.logger.log_once(:warn, "metric_duration_negative:#{first_name}",
65
+ "Metric #{first_name} has negative duration: #{duration} ms")
66
+ end
67
+ if exclusive < 0
68
+ ::TingYun::Agent.logger.log_once(:warn, "metric_exclusive_negative:#{first_name}",
69
+ "Metric #{first_name} has negative exclusive time: duration = #{duration} ms, child_time = #{frame.children_time}")
70
+ end
71
+ # record_metrics(state, first_name, metric_names, duration, exclusive, options)
72
+ # if first_name.start_with?('WebAction')
73
+ # state.current_transaction.base_quantile_hash[first_name] = duration
74
+ # end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
52
80
  def record_metrics(state, first_name, other_names, duration, exclusive, options)
53
81
  record_scoped_metric = options.has_key?(:scoped_metric) ? options[:scoped_metric] : true
54
82
  stat_engine = TingYun::Agent.instance.stats_engine
@@ -25,9 +25,10 @@ module TingYun
25
25
 
26
26
 
27
27
  SUBTRANSACTION_PREFIX = 'Nested/'.freeze
28
- CONTROLLER_PREFIX = 'WebAction/'.freeze
29
- BACKGROUND_PREFIX = 'BackgroundAction/'.freeze
30
- RAKE_TRANSACTION_PREFIX = 'BackgroundAction/Rake'.freeze
28
+ CONTROLLER_PREFIX = 'Transaction/'.freeze
29
+ COSS_CONTROLLER_PREFIX = 'WebAction/'.freeze
30
+ BACKGROUND_PREFIX = 'TaskAction/'.freeze
31
+ RAKE_TRANSACTION_PREFIX = 'TaskAction/Rake'.freeze
31
32
  TASK_PREFIX = 'OtherTransaction/Background/'.freeze
32
33
  RACK_PREFIX = 'Rack/'.freeze
33
34
  SINATRA_PREFIX = 'WebAction/Sinatra/'.freeze
@@ -67,7 +68,6 @@ module TingYun
67
68
 
68
69
  def initialize(category, client_transaction_id, options)
69
70
  @start_time = Time.now.to_f
70
-
71
71
  @exceptions = TingYun::Agent::Transaction::Exceptions.new
72
72
  @metrics = TingYun::Agent::TransactionMetrics.new
73
73
  @attributes = TingYun::Agent::Transaction::Attributes.new
@@ -85,6 +85,7 @@ module TingYun
85
85
 
86
86
  if request = options[:request]
87
87
  @request_attributes = TingYun::Agent::Transaction::RequestAttributes.new request
88
+ @attributes.merge_request_header(@request_attributes.header.select{|k,v|k.start_with?("HTTP")})
88
89
  else
89
90
  @request_attributes = nil
90
91
  end
@@ -118,7 +119,6 @@ module TingYun
118
119
 
119
120
 
120
121
  def stop(state, end_time, outermost_frame, summary_metrics = [])
121
-
122
122
  freeze_name_and_execute
123
123
 
124
124
  if @has_children or @is_mq
@@ -149,7 +149,7 @@ module TingYun
149
149
  end
150
150
 
151
151
 
152
- def commit(state, end_time, outermost_node_name)
152
+ def commitV2(state, end_time, outermost_node_name)
153
153
 
154
154
  assign_agent_attributes(state)
155
155
 
@@ -167,6 +167,24 @@ module TingYun
167
167
  TingYun::Agent.instance.stats_engine.record_base_quantile(@base_quantile_hash) unless @exceptions.had_error?
168
168
  end
169
169
 
170
+ def commit(state, end_time, outermost_node_name)
171
+
172
+ assign_agent_attributes(state)
173
+
174
+
175
+ TingYun::Agent.instance.transaction_sampler.on_finishing_transaction(state, self, end_time,@exceptions)
176
+
177
+ TingYun::Agent.instance.sql_sampler.on_finishing_transaction(state, @frozen_name)
178
+ #
179
+ # record_summary_metrics(state, outermost_node_name, end_time) unless @exceptions.had_error?
180
+ # @apdex.record_apdex(@frozen_name, end_time, @exceptions.had_error?)
181
+ # @exceptions.record_exceptions(@attributes)
182
+ #
183
+ #
184
+ # TingYun::Agent.instance.stats_engine.merge_transaction_metrics!(@metrics, best_name)
185
+ # TingYun::Agent.instance.stats_engine.record_base_quantile(@base_quantile_hash) unless @exceptions.had_error?
186
+ end
187
+
170
188
  end
171
189
  end
172
190
  end
@@ -5,11 +5,14 @@ module TingYun
5
5
  class Transaction
6
6
  class Attributes
7
7
 
8
- attr_accessor :agent_attributes, :request_params, :custom_params
8
+ attr_accessor :agent_attributes, :request_params, :custom_params, :response_header,:request_header,:user_info
9
9
  def initialize
10
10
  @agent_attributes = {:httpStatus => 0} #defaul value
11
11
  @request_params = {}
12
- @custom_params = {}
12
+ @custom_params = {:threadId => $$}
13
+ @response_header = {}
14
+ @request_header = {}
15
+ @user_info = {}
13
16
  end
14
17
 
15
18
  # no longer to care about the value if nil or not
@@ -24,6 +27,18 @@ module TingYun
24
27
  def add_custom_params(key, value)
25
28
  @custom_params[key] = value
26
29
  end
30
+
31
+ def add_request_params(key, value)
32
+ @request_header[key] = value
33
+ end
34
+
35
+ def merge_request_header(hash)
36
+ @request_header.merge!(hash) if hash
37
+ end
38
+
39
+ def add_user_info(key, value)
40
+ @user_info[key] = value
41
+ end
27
42
  end
28
43
  end
29
44
  end
@@ -48,6 +48,7 @@ module TingYun
48
48
  if txn.frame_stack.empty?
49
49
  txn.stop(state, end_time, nested_frame, summary_metric_names)
50
50
  state.reset
51
+ TingYun::Agent.upload
51
52
  else
52
53
  nested_name = Transaction.nested_transaction_name nested_frame.name
53
54
 
@@ -14,15 +14,14 @@ module TingYun
14
14
  end
15
15
 
16
16
  def create_nested_frame(state, category, options)
17
-
18
17
  if options[:filtered_params] && !options[:filtered_params].empty?
19
18
  attributes.merge_request_parameters(options[:filtered_params])
20
19
  end
20
+ state.add_current_node_params(:method => options[:method]) unless options[:method].nil?
21
21
  @has_children = true
22
22
  frame_stack.push TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_header(state, Time.now.to_f)
23
23
  name_last_frame(options[:transaction_name])
24
-
25
- set_default_transaction_name(options[:transaction_name], category)
24
+ set_default_transaction_name("#{state.action_type}/#{options[:transaction_name]}", category)
26
25
  end
27
26
 
28
27
 
@@ -89,11 +88,15 @@ module TingYun
89
88
 
90
89
  if @request_attributes
91
90
  @request_attributes.assign_agent_attributes @attributes
91
+ @request_attributes.assign_user_info_attributes @attributes
92
92
  end
93
93
 
94
94
  @attributes.add_agent_attribute(:tx_id, @guid);
95
+ @attributes.add_agent_attribute(:tmd5, state.transaction_name_md5);
95
96
  @attributes.add_agent_attribute(:metric_name, best_name);
96
97
  @attributes.add_agent_attribute(:trace_id, state.trace_id || "0")
98
+ @attributes.add_agent_attribute(:refid, state.extenel_req_id)
99
+ @attributes.add_agent_attribute(:cross, state.call_list)
97
100
  end
98
101
 
99
102
 
@@ -135,7 +138,10 @@ module TingYun
135
138
  unless @frozen_name
136
139
  @frozen_name = best_name
137
140
  end
138
- @frozen_name = CONTROLLER_PREFIX + @frozen_name unless @frozen_name.start_with? CONTROLLER_PREFIX,BACKGROUND_PREFIX
141
+ state = TingYun::Agent::TransactionState.tl_get
142
+ unless @frozen_name.start_with? CONTROLLER_PREFIX, BACKGROUND_PREFIX, COSS_CONTROLLER_PREFIX
143
+ @frozen_name = state.action_type + @frozen_name
144
+ end
139
145
  yield if block_given?
140
146
  end
141
147
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'ting_yun/support/http_clients/uri_util'
4
+ require 'ting_yun/support/serialize/json_wrapper'
4
5
 
5
6
  module TingYun
6
7
  module Agent
@@ -8,7 +9,7 @@ module TingYun
8
9
  class RequestAttributes
9
10
 
10
11
  attr_reader :request_path, :referer, :accept, :content_length, :host,
11
- :port, :user_agent, :request_method, :header, :cookie
12
+ :port, :user_agent, :request_method, :header, :cookie, :ip, :url, :params,:queryString
12
13
 
13
14
  HTTP_ACCEPT_HEADER_KEY = 'HTTP_ACCEPT'.freeze
14
15
 
@@ -23,17 +24,55 @@ module TingYun
23
24
  @user_agent = attribute_from_request request, :user_agent
24
25
  @request_method = attribute_from_request request, :request_method
25
26
  @cookie = set_cookie(request)
27
+ @ip = attribute_from_env(request, 'HTTP_X_FORWARDED_FOR')|| request.ip
28
+ @url = request.scheme + "://"+ request.host_with_port + @request_path
29
+ @params = request.params
30
+ @queryString = request.query_string
26
31
  end
27
32
 
28
33
  def assign_agent_attributes(attributes)
29
34
  attributes.add_agent_attribute :request_path, request_path
30
- attributes.add_agent_attribute :referer, referer
35
+ attributes.add_agent_attribute :referer, referer unless referer.nil?
31
36
  attributes.add_agent_attribute :accept, accept
32
- attributes.add_agent_attribute :contentLength, content_length
37
+ attributes.add_agent_attribute :contentLength, content_length unless content_length.nil?
33
38
  attributes.add_agent_attribute :host, host
34
39
  attributes.add_agent_attribute :port, port
35
40
  attributes.add_agent_attribute :userAgent, user_agent
36
41
  attributes.add_agent_attribute :method, request_method
42
+ attributes.add_agent_attribute :ip, ip
43
+ attributes.add_agent_attribute :url, url
44
+ attributes.add_agent_attribute :queryString, queryString
45
+ attributes.response_header.merge! attributes.agent_attributes
46
+ attributes.add_agent_attribute :params, params
47
+ attributes.add_agent_attribute :cookie, @cookie
48
+ end
49
+
50
+ def assign_user_info_attributes(attributes)
51
+ rule = TingYun::Support::Serialize::JSONWrapper.load(TingYun::Agent.config[:'user_info.rules'])
52
+ rule["list"].each do |r|
53
+ if [2,9].include?(r["type"]) && !@params.nil?
54
+ attributes.add_user_info("origin"=> 1)
55
+ attributes.add_user_info("value"=> @params[r["value"]])
56
+ elsif [7,10].include?(r["type"]) && !@cookie.nil?
57
+ attributes.add_user_info("origin"=> 1)
58
+ attributes.add_user_info("value"=> @cookie[r["value"]])
59
+ end
60
+ end
61
+ end
62
+
63
+ def assign_request_attributes(attributes)
64
+ attributes.add_request_params :request_path, request_path
65
+ attributes.add_request_params :referer, referer unless referer.nil?
66
+ attributes.add_request_params :accept, accept
67
+ attributes.add_request_params(:contentLength, content_length) unless content_length.nil?
68
+ attributes.add_request_params :host, host
69
+ attributes.add_request_params :port, port
70
+ attributes.add_request_params :userAgent, user_agent
71
+ attributes.add_request_params :method, request_method
72
+ attributes.add_request_params :ip, ip
73
+ attributes.add_request_params :url, url
74
+ attributes.add_request_params :params, params
75
+ attributes.add_request_params :queryString, queryString
37
76
  end
38
77
 
39
78