zipkin-tracer 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f3c839257069386e2ee919af9359519db3d601d
4
- data.tar.gz: c3a5348a47ffcf3823ef079e7bf59f83bd73cf7a
3
+ metadata.gz: 05f65d2bb130fb08a93c2d8f0a9e0f37af0e880e
4
+ data.tar.gz: 4a2367d64760ae201df8b38bc372812b87779236
5
5
  SHA512:
6
- metadata.gz: 7a1bd29f82318ff6391b9575701ac7a65831147b87dc7c434e7930ad77fb569e87f8485480ff1f6400cdd55ac1320a2a055179001a3d9aa0a5ac27e5a7b743f6
7
- data.tar.gz: fd4800c057745f5ae23bae36dcb34655fc612cb7aa34d7cbd5cf77718c74c09f2debd1745f3c2e158ddd09ec5f219eba8f37ae5f2464af7ddf25dd06353fb1ae
6
+ metadata.gz: 36a3443425732fbe0d0cb61f03530f7ebd0876931097a814a164610b55adad24fa4b26071f55abcd78d68341afc414665c334798e3b80891ae07bcf9acb0775e
7
+ data.tar.gz: 02453b03c11987c52d8192034d2864e462e9961c9f390e2754c78fd2fd875bcbc68e9e5937265483cab4ac19b43f4832e70667e3573a3e5f18a9dbb4f44540c5
@@ -29,13 +29,9 @@ module ZipkinTracer
29
29
 
30
30
  def response_call(datum)
31
31
  if span = datum[:span]
32
- if status = response_status(datum)
33
- span.record_tag(
34
- Trace::BinaryAnnotation::STATUS,
35
- status,
36
- Trace::BinaryAnnotation::Type::STRING,
37
- local_endpoint
38
- )
32
+ status = response_status(datum)
33
+ if status
34
+ record_response_tags(span, status, local_endpoint)
39
35
  end
40
36
  span.record(Trace::Annotation::CLIENT_RECV, local_endpoint)
41
37
  Trace.tracer.end_span(span)
@@ -47,6 +43,7 @@ module ZipkinTracer
47
43
  private
48
44
 
49
45
  SERVER_ADDRESS_SPECIAL_VALUE = '1'.freeze
46
+ STATUS_ERROR_REGEXP = /\A(4.*|5.*)\z/.freeze
50
47
 
51
48
  def b3_headers
52
49
  {
@@ -74,6 +71,14 @@ module ZipkinTracer
74
71
  datum[:response] && datum[:response][:status] && datum[:response][:status].to_s
75
72
  end
76
73
 
74
+ def record_response_tags(span, status, local_endpoint)
75
+ span.record_tag(Trace::BinaryAnnotation::STATUS, status, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
76
+ if STATUS_ERROR_REGEXP.match(status)
77
+ span.record_tag(Trace::BinaryAnnotation::ERROR, status,
78
+ Trace::BinaryAnnotation::Type::STRING, local_endpoint)
79
+ end
80
+ end
81
+
77
82
  def trace!(datum, trace_id)
78
83
  url_string = Excon::Utils::request_uri(datum)
79
84
  url = URI(url_string)
@@ -28,6 +28,8 @@ module ZipkinTracer
28
28
  private
29
29
 
30
30
  SERVER_ADDRESS_SPECIAL_VALUE = '1'.freeze
31
+ STATUS_ERROR_REGEXP = /\A(4.*|5.*)\z/.freeze
32
+
31
33
 
32
34
  def b3_headers
33
35
  {
@@ -46,17 +48,38 @@ module ZipkinTracer
46
48
  local_endpoint = Trace.default_endpoint # The rack middleware set this up for us.
47
49
  remote_endpoint = Trace::Endpoint.remote_endpoint(url, @service_name, local_endpoint.ip_format) # The endpoint we are calling.
48
50
  Trace.tracer.with_new_span(trace_id, env[:method].to_s.downcase) do |span|
51
+ @span = span # So we can record on exceptions
49
52
  # annotate with method (GET/POST/etc.) and uri path
50
53
  span.record_tag(Trace::BinaryAnnotation::PATH, url.path, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
51
54
  span.record_tag(Trace::BinaryAnnotation::SERVER_ADDRESS, SERVER_ADDRESS_SPECIAL_VALUE, Trace::BinaryAnnotation::Type::BOOL, remote_endpoint)
52
55
  span.record(Trace::Annotation::CLIENT_SEND, local_endpoint)
53
56
  response = @app.call(env).on_complete do |renv|
54
- # record HTTP status code on response
55
- span.record_tag(Trace::BinaryAnnotation::STATUS, renv[:status].to_s, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
57
+ record_response_tags(span, renv[:status].to_s, local_endpoint)
56
58
  end
57
59
  span.record(Trace::Annotation::CLIENT_RECV, local_endpoint)
58
60
  end
59
61
  response
62
+ rescue Net::ReadTimeout
63
+ record_error(@span, 'Request timed out.', local_endpoint)
64
+ raise
65
+ rescue Faraday::ConnectionFailed
66
+ record_error(@span, 'Request connection failed.', local_endpoint)
67
+ raise
68
+ rescue Faraday::ClientError
69
+ record_error(@span, 'Generic Faraday client error.', local_endpoint)
70
+ raise
71
+ end
72
+
73
+ def record_error(span, msg, local_endpoint)
74
+ span.record_tag(Trace::BinaryAnnotation::ERROR, msg, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
75
+ end
76
+
77
+ def record_response_tags(span, status, local_endpoint)
78
+ span.record_tag(Trace::BinaryAnnotation::STATUS, status, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
79
+ if STATUS_ERROR_REGEXP.match(status)
80
+ span.record_tag(Trace::BinaryAnnotation::ERROR, status,
81
+ Trace::BinaryAnnotation::Type::STRING, local_endpoint)
82
+ end
60
83
  end
61
84
 
62
85
  end
@@ -120,6 +120,7 @@ module Trace
120
120
  PATH = 'http.path'.freeze
121
121
  STATUS = 'http.status'.freeze
122
122
  LOCAL_COMPONENT = 'lc'.freeze
123
+ ERROR = 'error'.freeze
123
124
 
124
125
  def to_h
125
126
  {
@@ -1,3 +1,3 @@
1
1
  module ZipkinTracer
2
- VERSION = '0.26.0'.freeze
2
+ VERSION = '0.27.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.26.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu