tingyun_rpm 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -0
  3. data/lib/ting_yun/agent.rb +7 -1
  4. data/lib/ting_yun/agent/collector/error_collector.rb +103 -25
  5. data/lib/ting_yun/agent/collector/error_collector/error_trace_array.rb +2 -0
  6. data/lib/ting_yun/agent/collector/error_collector/noticed_error.rb +20 -13
  7. data/lib/ting_yun/agent/collector/transaction_sampler.rb +4 -1
  8. data/lib/ting_yun/agent/collector/transaction_sampler/class_method.rb +4 -4
  9. data/lib/ting_yun/agent/cross_app/cross_app_tracing.rb +1 -3
  10. data/lib/ting_yun/agent/instance_methods/container_data_manager.rb +6 -0
  11. data/lib/ting_yun/agent/method_tracer_helpers.rb +6 -4
  12. data/lib/ting_yun/agent/transaction.rb +15 -15
  13. data/lib/ting_yun/agent/transaction/apdex.rb +1 -1
  14. data/lib/ting_yun/agent/transaction/class_method.rb +14 -17
  15. data/lib/ting_yun/agent/transaction/exceptions.rb +19 -6
  16. data/lib/ting_yun/agent/transaction/instance_method.rb +8 -4
  17. data/lib/ting_yun/agent/transaction/trace.rb +23 -4
  18. data/lib/ting_yun/agent/transaction/trace_node.rb +26 -6
  19. data/lib/ting_yun/agent/transaction/traced_method_stack.rb +2 -2
  20. data/lib/ting_yun/agent/transaction/transaction_sample_builder.rb +17 -8
  21. data/lib/ting_yun/configuration/default_source.rb +22 -1
  22. data/lib/ting_yun/http/abstract_request.rb +23 -0
  23. data/lib/ting_yun/http/curb_wrappers.rb +76 -0
  24. data/lib/ting_yun/http/excon_wrappers.rb +81 -0
  25. data/lib/ting_yun/http/http_client_request.rb +2 -2
  26. data/lib/ting_yun/http/net_http_request.rb +2 -2
  27. data/lib/ting_yun/http/typhoeus_wrappers.rb +88 -0
  28. data/lib/ting_yun/instrumentation/bunny.rb +3 -3
  29. data/lib/ting_yun/instrumentation/curb.rb +191 -0
  30. data/lib/ting_yun/instrumentation/excon.rb +131 -0
  31. data/lib/ting_yun/instrumentation/grape.rb +4 -2
  32. data/lib/ting_yun/instrumentation/kafka.rb +3 -3
  33. data/lib/ting_yun/instrumentation/memcached.rb +1 -1
  34. data/lib/ting_yun/instrumentation/middleware_proxy.rb +17 -1
  35. data/lib/ting_yun/instrumentation/middleware_tracing.rb +1 -1
  36. data/lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb +1 -0
  37. data/lib/ting_yun/instrumentation/net.rb +24 -24
  38. data/lib/ting_yun/instrumentation/rack.rb +10 -10
  39. data/lib/ting_yun/instrumentation/rails3/action_controller.rb +1 -1
  40. data/lib/ting_yun/instrumentation/rake.rb +8 -4
  41. data/lib/ting_yun/instrumentation/support/action_controller_subscriber.rb +1 -1
  42. data/lib/ting_yun/instrumentation/support/action_view_subscriber.rb +2 -2
  43. data/lib/ting_yun/instrumentation/support/active_record_subscriber.rb +2 -2
  44. data/lib/ting_yun/instrumentation/support/controller_instrumentation.rb +3 -3
  45. data/lib/ting_yun/instrumentation/support/external_error.rb +4 -4
  46. data/lib/ting_yun/instrumentation/support/external_helper.rb +6 -1
  47. data/lib/ting_yun/instrumentation/thrift.rb +1 -1
  48. data/lib/ting_yun/instrumentation/typhoeus.rb +75 -0
  49. data/lib/ting_yun/support/exception.rb +2 -0
  50. data/lib/ting_yun/support/http_clients/uri_util.rb +12 -7
  51. data/lib/ting_yun/ting_yun_service.rb +1 -1
  52. data/lib/ting_yun/ting_yun_service/upload_service.rb +15 -3
  53. data/lib/ting_yun/version.rb +2 -2
  54. metadata +9 -3
  55. data/lib/ting_yun/http/generic_request.rb +0 -8
@@ -14,12 +14,12 @@ module TingYun
14
14
  module_function
15
15
 
16
16
  def capture_exception(response,request)
17
- if response && response.code =~ /^[4,5][0-9][0-9]$/ && response.code!='401'
17
+ if response && response.code.to_s =~ /^[4,5][0-9][0-9]$/ && response.code.to_s!='401'
18
18
  e = TingYun::Support::Exception::InternalServerError.new("#{response.code}: #{response.message}")
19
- klass = "External/#{request.uri.to_s.gsub('/','%2F')}/#{request.from}"
19
+ klass = "External/#{request.uri.to_s.gsub(/\/\z/,'').gsub('/','%2F')}/#{request.from}"
20
20
  set_attributes(e, klass, response.code)
21
21
 
22
- TingYun::Agent.notice_error(e)
22
+ TingYun::Agent.notice_error(e,:type=>:exception)
23
23
  end
24
24
  end
25
25
 
@@ -37,7 +37,7 @@ module TingYun
37
37
  set_attributes(e, klass, 1000)
38
38
  end
39
39
 
40
- TingYun::Agent.notice_error(e)
40
+ TingYun::Agent.notice_error(e,:type=>:exception)
41
41
  end
42
42
 
43
43
  def set_attributes(exception, klass, code)
@@ -25,7 +25,12 @@ module TingYun
25
25
  end
26
26
 
27
27
  def self.metrics_for_message(product, ip_host, operation)
28
- metrics =["AllWeb", "All"]
28
+ if TingYun::Agent::Transaction.recording_web_transaction?
29
+ metrics =["AllWeb", "All"]
30
+ else
31
+ metrics =["AllBackground", "All"]
32
+ end
33
+
29
34
  metrics = metrics.map { |suffix| "Message #{product}/NULL/#{suffix}" }
30
35
  metrics.unshift "Message #{product}/#{ip_host}/#{operation}"
31
36
  end
@@ -117,7 +117,7 @@ TingYun::Support::LibraryDetection.defer do
117
117
 
118
118
 
119
119
  result = receive_message_without_tingyun(result_klass)
120
- unless result || result.success
120
+ unless result && result.success
121
121
  e = ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, "#{operate} failed: unknown result")
122
122
  ::TingYun::Instrumentation::Support::ExternalError.handle_error(e,metrics(operate)[0])
123
123
  end
@@ -0,0 +1,75 @@
1
+ TingYun::Support::LibraryDetection.defer do
2
+ named :typhoeus
3
+
4
+
5
+ depends_on do
6
+ defined?(Typhoeus) && defined?(Typhoeus::VERSION)
7
+ end
8
+
9
+ depends_on do
10
+ TingYun::Instrumentation::TyphoeusTracing.is_supported_version?
11
+ end
12
+
13
+ executes do
14
+ ::TingYun::Agent.logger.info 'Installing Typhoeus instrumentation'
15
+ require 'ting_yun/agent/cross_app/cross_app_tracing'
16
+ require 'ting_yun/http/typhoeus_wrappers'
17
+ require 'ting_yun/agent/method_tracer_helpers'
18
+ end
19
+
20
+ # Basic request tracing
21
+ executes do
22
+ Typhoeus.before do |request|
23
+ TingYun::Instrumentation::TyphoeusTracing.trace(request)
24
+
25
+ # Ensure that we always return a truthy value from the before block,
26
+ # otherwise Typhoeus will bail out of the instrumentation.
27
+ true
28
+ end
29
+ end
30
+
31
+ # Apply single TT node for Hydra requests until async support
32
+ executes do
33
+ class Typhoeus::Hydra
34
+
35
+
36
+ def run_with_tingyun(*args)
37
+ TingYun::Agent::MethodTracerHelpers.trace_execution_scoped("External/Multiple/Typhoeus::Hydra/run") do
38
+ run_without_tingyun(*args)
39
+ end
40
+ end
41
+
42
+ alias run_without_tingyun run
43
+ alias run run_with_tingyun
44
+ end
45
+ end
46
+
47
+
48
+ end
49
+
50
+
51
+ module TingYun::Instrumentation::TyphoeusTracing
52
+
53
+ EARLIEST_VERSION = TingYun::Support::VersionNumber.new("0.5.3")
54
+
55
+ def self.is_supported_version?
56
+ TingYun::Support::VersionNumber.new(Typhoeus::VERSION) >= TingYun::Instrumentation::TyphoeusTracing::EARLIEST_VERSION
57
+ end
58
+
59
+ def self.request_is_hydra_enabled?(request)
60
+ request.respond_to?(:hydra) && request.hydra
61
+ end
62
+
63
+ def self.trace(request)
64
+ if TingYun::Agent.tl_is_execution_traced? && !request_is_hydra_enabled?(request)
65
+ wrapped_request = ::TingYun::Http::TyphoeusHTTPRequest.new(request)
66
+ state = TingYun::Agent::TransactionState.tl_get
67
+ t0 = Time.now.to_f
68
+ segment = TingYun::Agent::CrossAppTracing.start_trace(state, t0, wrapped_request)
69
+ request.on_complete do
70
+ wrapped_response = ::TingYun::Http::TyphoeusHTTPResponse.new(request.response)
71
+ TingYun::Agent::CrossAppTracing.finish_trace(TingYun::Agent::TransactionState.tl_get,t0, segment, wrapped_request, wrapped_response )
72
+ end
73
+ end
74
+ end
75
+ end
@@ -40,7 +40,9 @@ module TingYun
40
40
  end
41
41
  end
42
42
 
43
+ #跨应用错误
43
44
  class InternalServerError < StandardError
45
+
44
46
  end
45
47
 
46
48
  end
@@ -24,14 +24,19 @@ module TingYun
24
24
  # There are valid URI strings that some HTTP client libraries will
25
25
  # accept that the stdlib URI module doesn't handle. If we find that
26
26
  # Addressable is around, use that to normalize out our URL's.
27
- def self.parse_url(url)
28
- if defined?(::Addressable::URI)
29
- address = ::Addressable::URI.parse(url)
30
- address.normalize!
31
- URI.parse(address.to_s)
32
- else
33
- URI.parse(url)
27
+ def self.parse_and_normalize_url(url)
28
+ uri = url
29
+ unless ::URI === uri
30
+ if defined?(::Addressable::URI)
31
+ address = ::Addressable::URI.parse(url)
32
+ address.normalize!
33
+ uri = ::URI.parse(address.to_s)
34
+ else
35
+ uri = ::URI.parse(url)
36
+ end
34
37
  end
38
+ uri.host.downcase! unless uri.host.nil?
39
+ uri
35
40
  end
36
41
 
37
42
  QUESTION_MARK = "?".freeze
@@ -37,7 +37,7 @@ module TingYun
37
37
 
38
38
  @license_key = license_key || TingYun::Agent.config[:'license_key']
39
39
  @request_timeout = TingYun::Agent.config[:timeout]
40
- @data_version = TingYun::VERSION::STRING
40
+ @data_version = "1.4"
41
41
  @marshaller =TingYun::Support::Serialize::JsonMarshaller.new
42
42
  @metric_id_cache = {}
43
43
  @quantile_cache = {}
@@ -23,7 +23,7 @@ module TingYun
23
23
  end
24
24
 
25
25
  def metric_data(stats_hash, base_quantile_hash)
26
- action_array, adpex_array, general_array, components_array, errors_array = build_metric_data_array(stats_hash, base_quantile_hash)
26
+ action_array, adpex_array, general_array, components_array, errors_array,exception_array = build_metric_data_array(stats_hash, base_quantile_hash)
27
27
 
28
28
  upload_data = {
29
29
  :type => 'perfMetrics',
@@ -34,7 +34,8 @@ module TingYun
34
34
  :apdex => adpex_array,
35
35
  :components => components_array,
36
36
  :general => general_array,
37
- :errors => errors_array
37
+ :errors => errors_array,
38
+ :exceptions => exception_array
38
39
  }
39
40
  upload_data.merge!(:config => {"nbs.quantile" => TingYun::Agent.config[:'nbs.quantile']}) if TingYun::Agent.config[:'nbs.quantile']
40
41
  result = invoke_remote(:upload, [upload_data])
@@ -53,6 +54,7 @@ module TingYun
53
54
  general_array = []
54
55
  components_array = []
55
56
  errors_array = []
57
+ exception_array = []
56
58
 
57
59
  calculate_quantile(base_quantile_hash.hash)
58
60
 
@@ -68,6 +70,8 @@ module TingYun
68
70
  adpex_array << TingYun::Metrics::MetricData.new(metric_spec, stats, metric_id)
69
71
  elsif metric_spec.name.start_with?('Errors') && metric_spec.scope.empty?
70
72
  errors_array << TingYun::Metrics::MetricData.new(metric_spec, stats, metric_id)
73
+ elsif metric_spec.name.start_with?('Exception') && metric_spec.scope.empty?
74
+ exception_array << TingYun::Metrics::MetricData.new(metric_spec, stats, metric_id)
71
75
  else
72
76
  if metric_spec.scope.empty?
73
77
  general_array << TingYun::Metrics::MetricData.new(metric_spec, stats, metric_id) unless metric_spec.name.start_with?("View","Middleware","Nested","Rack")
@@ -79,7 +83,7 @@ module TingYun
79
83
  end
80
84
  end
81
85
 
82
- [action_array, adpex_array, general_array, components_array, errors_array]
86
+ [action_array, adpex_array, general_array, components_array, errors_array,exception_array]
83
87
  end
84
88
 
85
89
  def generate_action(metric_spec, stats, metric_id)
@@ -132,6 +136,14 @@ module TingYun
132
136
  invoke_remote(:upload, [upload_data], :encoder=> json)
133
137
  end
134
138
 
139
+ def exception_data(unsent_exceptions)
140
+ upload_data = {
141
+ :type => 'exceptionTraceData',
142
+ :exceptions => unsent_exceptions
143
+ }
144
+ invoke_remote(:upload, [upload_data], :encoder=> json)
145
+ end
146
+
135
147
 
136
148
  def action_trace_data(traces)
137
149
  upload_data = {
@@ -4,8 +4,8 @@
4
4
  module TingYun
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 4
8
- TINY = 2
7
+ MINOR = 5
8
+ TINY = 0
9
9
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tingyun_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tingyun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -354,12 +354,17 @@ files:
354
354
  - lib/ting_yun/frameworks/rails5.rb
355
355
  - lib/ting_yun/frameworks/ruby.rb
356
356
  - lib/ting_yun/frameworks/sinatra.rb
357
- - lib/ting_yun/http/generic_request.rb
357
+ - lib/ting_yun/http/abstract_request.rb
358
+ - lib/ting_yun/http/curb_wrappers.rb
359
+ - lib/ting_yun/http/excon_wrappers.rb
358
360
  - lib/ting_yun/http/http_client_request.rb
359
361
  - lib/ting_yun/http/net_http_request.rb
362
+ - lib/ting_yun/http/typhoeus_wrappers.rb
360
363
  - lib/ting_yun/instrumentation/active_record.rb
361
364
  - lib/ting_yun/instrumentation/bunny.rb
365
+ - lib/ting_yun/instrumentation/curb.rb
362
366
  - lib/ting_yun/instrumentation/data_mapper.rb
367
+ - lib/ting_yun/instrumentation/excon.rb
363
368
  - lib/ting_yun/instrumentation/grape.rb
364
369
  - lib/ting_yun/instrumentation/http_client.rb
365
370
  - lib/ting_yun/instrumentation/kafka.rb
@@ -409,6 +414,7 @@ files:
409
414
  - lib/ting_yun/instrumentation/support/thrift_helper.rb
410
415
  - lib/ting_yun/instrumentation/support/transaction_namer.rb
411
416
  - lib/ting_yun/instrumentation/thrift.rb
417
+ - lib/ting_yun/instrumentation/typhoeus.rb
412
418
  - lib/ting_yun/logger.rb
413
419
  - lib/ting_yun/logger/agent_logger.rb
414
420
  - lib/ting_yun/logger/create_logger_helper.rb
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- module TingYun
3
- module Http
4
- class GenericRequest
5
-
6
- end
7
- end
8
- end