zipkin-tracer 0.34.0 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba81449b69065fcd0ffcca18f0750e49826896cc8321c3a18d2e6df22a25cd27
4
- data.tar.gz: 861e0bfb101b56935c0488c34d3db34154226b2625067c3db7b88e8bb168bfeb
3
+ metadata.gz: 3145da3d93716701cfe338e782717243946ec9d7b8337a4f67f4680dd2b3b06c
4
+ data.tar.gz: 857aa5010bbf1eaa5de81bf4bbfb17ba008c3e986e417740cdee6491e327fd7a
5
5
  SHA512:
6
- metadata.gz: 5f136b2d49f70678fdbb768707418ec099c46e5dceef84efb83d063f057927e1cdd2ff7e750ea3f31a3b0a0a5a02869996131d24b35108ef178711a53f91bc7a
7
- data.tar.gz: 78dfc19eee7a3f4b9b77ef8a980783cf2fc79e3087d406c7e89ac1e915cacd941f44b295f40921ca1966ccafa6688b71e5d94b1ef8a4969c4312bd5c408fd44c
6
+ metadata.gz: '085a771261ce989e0412d80080607872fd440e814877be5d2095c6a1d4d8fb8da7654583e52e940dece17406b425d26e76cced98419d866b5acd6970641d5f70'
7
+ data.tar.gz: 3d1041e44ae618d3886f47169b871b827e1246e37d6c7536207ea1eaf0b5120da8a1e56d878610b7f27c38beac26f2567a551f675d70325012122899ac6d128b
@@ -8,7 +8,7 @@ module ZipkinTracer
8
8
  attr_reader :service_name, :json_api_host,
9
9
  :zookeeper, :sample_rate, :logger, :log_tracing,
10
10
  :annotate_plugin, :filter_plugin, :whitelist_plugin,
11
- :sampled_as_boolean, :record_on_server_receive,
11
+ :sampled_as_boolean,
12
12
  :kafka_producer, :kafka_topic, :trace_id_128bit
13
13
 
14
14
  def initialize(app, config_hash)
@@ -39,8 +39,6 @@ module ZipkinTracer
39
39
  if @sampled_as_boolean
40
40
  @logger && @logger.warn("Using a boolean in the Sampled header is deprecated. Consider setting sampled_as_boolean to false")
41
41
  end
42
- # Record the given tags on server receive, even if the zipkin headers were present in the incoming request?
43
- @record_on_server_receive = parse_tags(config[:record_on_server_receive])
44
42
 
45
43
  # When set to true, high 8-bytes will be prepended to trace_id.
46
44
  # The upper 4-bytes are epoch seconds and the lower 4-bytes are random.
@@ -74,14 +72,6 @@ module ZipkinTracer
74
72
  trace_id_128bit: false
75
73
  }
76
74
 
77
- def parse_tags(tag_names)
78
- return {} unless present?(tag_names)
79
- names = tag_names.split(",").map(&:strip)
80
- (ZipkinTracer::RackHandler::DEFAULT_SERVER_RECV_TAGS.keys & names).each_with_object({}) do |name, tags|
81
- tags[name] = ZipkinTracer::RackHandler::DEFAULT_SERVER_RECV_TAGS[name]
82
- end
83
- end
84
-
85
75
  def present?(str)
86
76
  return false if str.nil?
87
77
  !!(/\A[[:space:]]*\z/ !~ str)
@@ -27,8 +27,7 @@ module ZipkinTracer
27
27
 
28
28
  def response_call(datum)
29
29
  if span = datum[:span]
30
- status = response_status(datum)
31
- record_response_tags(span, status) if status
30
+ span.record_status(response_status(datum))
32
31
  Trace.tracer.end_span(span)
33
32
  end
34
33
 
@@ -37,8 +36,6 @@ module ZipkinTracer
37
36
 
38
37
  private
39
38
 
40
- STATUS_ERROR_REGEXP = /\A(4.*|5.*)\z/.freeze
41
-
42
39
  def b3_headers
43
40
  {
44
41
  trace_id: 'X-B3-TraceId',
@@ -61,11 +58,6 @@ module ZipkinTracer
61
58
  datum[:response] && datum[:response][:status] && datum[:response][:status].to_s
62
59
  end
63
60
 
64
- def record_response_tags(span, status)
65
- span.record_tag(Trace::Span::Tag::STATUS, status)
66
- span.record_tag(Trace::Span::Tag::ERROR, status) if STATUS_ERROR_REGEXP.match(status)
67
- end
68
-
69
61
  def trace!(datum, trace_id)
70
62
  method = datum[:method].to_s
71
63
  url_string = Excon::Utils::request_uri(datum)
@@ -25,8 +25,6 @@ module ZipkinTracer
25
25
 
26
26
  private
27
27
 
28
- STATUS_ERROR_REGEXP = /\A(4.*|5.*)\z/.freeze
29
-
30
28
  def b3_headers
31
29
  {
32
30
  trace_id: 'X-B3-TraceId',
@@ -51,7 +49,7 @@ module ZipkinTracer
51
49
  span.record_tag(Trace::Span::Tag::METHOD, method.upcase)
52
50
  span.record_tag(Trace::Span::Tag::PATH, url.path)
53
51
  response = @app.call(env).on_complete do |renv|
54
- record_response_tags(span, renv[:status].to_s)
52
+ span.record_status(renv[:status])
55
53
  end
56
54
  end
57
55
  response
@@ -70,10 +68,5 @@ module ZipkinTracer
70
68
  span.record_tag(Trace::Span::Tag::ERROR, msg)
71
69
  end
72
70
 
73
- def record_response_tags(span, status)
74
- span.record_tag(Trace::Span::Tag::STATUS, status)
75
- span.record_tag(Trace::Span::Tag::ERROR, status) if STATUS_ERROR_REGEXP.match(status)
76
- end
77
-
78
71
  end
79
72
  end
@@ -11,10 +11,6 @@ module ZipkinTracer
11
11
  PATH_INFO = Rack::PATH_INFO rescue 'PATH_INFO'.freeze
12
12
  REQUEST_METHOD = Rack::REQUEST_METHOD rescue 'REQUEST_METHOD'.freeze
13
13
 
14
- DEFAULT_SERVER_RECV_TAGS = {
15
- Trace::Span::Tag::PATH => PATH_INFO
16
- }.freeze
17
-
18
14
  def initialize(app, config = nil)
19
15
  @app = app
20
16
  @config = Config.new(app, config).freeze
@@ -37,6 +33,11 @@ module ZipkinTracer
37
33
 
38
34
  private
39
35
 
36
+ SERVER_RECV_TAGS = {
37
+ Trace::Span::Tag::PATH => PATH_INFO,
38
+ Trace::Span::Tag::METHOD => REQUEST_METHOD
39
+ }.freeze
40
+
40
41
  def span_name(env)
41
42
  "#{env[REQUEST_METHOD].to_s.downcase} #{Application.route(env)}".strip
42
43
  end
@@ -46,23 +47,17 @@ module ZipkinTracer
46
47
  end
47
48
 
48
49
  def trace!(span, zipkin_env, &block)
49
- trace_request_information(span, zipkin_env)
50
- span.kind = Trace::Span::Kind::SERVER
51
50
  status, headers, body = yield
52
51
  ensure
52
+ trace_server_information(span, zipkin_env, status)
53
+
53
54
  annotate_plugin(span, zipkin_env.env, status, headers, body)
54
55
  end
55
56
 
56
- def trace_request_information(span, zipkin_env)
57
- tags = if !@config.record_on_server_receive.empty?
58
- # if the user specified tags to record on server receive, use these no matter what
59
- @config.record_on_server_receive
60
- elsif !zipkin_env.called_with_zipkin_headers?
61
- # if the request comes from a non zipkin-enabled source record the default tags
62
- DEFAULT_SERVER_RECV_TAGS
63
- end
64
- return if tags.nil?
65
- tags.each { |annotation_key, env_key| span.record_tag(annotation_key, zipkin_env.env[env_key]) }
57
+ def trace_server_information(span, zipkin_env, status)
58
+ span.kind = Trace::Span::Kind::SERVER
59
+ span.record_status(status)
60
+ SERVER_RECV_TAGS.each { |annotation_key, env_key| span.record_tag(annotation_key, zipkin_env.env[env_key]) }
66
61
  end
67
62
  end
68
63
  end
@@ -221,7 +221,7 @@ module Trace
221
221
  end
222
222
 
223
223
  def record_tag(key, value)
224
- @tags[key] = value
224
+ @tags[key] = value.to_s
225
225
  end
226
226
 
227
227
  def record_local_component(value)
@@ -232,6 +232,15 @@ module Trace
232
232
  !@span_id.parent_id.nil?
233
233
  end
234
234
 
235
+ STATUS_ERROR_REGEXP = /\A(4.*|5.*)\z/.freeze
236
+
237
+ def record_status(status)
238
+ return if status.nil?
239
+ status = status.to_s
240
+ record_tag(Tag::STATUS, status)
241
+ record_tag(Tag::ERROR, status) if STATUS_ERROR_REGEXP.match(status)
242
+ end
243
+
235
244
  private
236
245
 
237
246
  UNKNOWN_DURATION = 0 # mark duration was not set
@@ -1,3 +1,3 @@
1
1
  module ZipkinTracer
2
- VERSION = '0.34.0'.freeze
2
+ VERSION = '0.35.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipkin-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-03-28 00:00:00.000000000 Z
16
+ date: 2019-03-30 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: faraday