zipkin-tracer 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzUzN2QzOWMyMzczNmIxNGRhMzU0YWIzNzU4NWNkZWU3NjY0YTcxOA==
4
+ ZTkwMjRjNjFiYzM3NmIyZTE5YmNiN2FiZWI0MDU2ODAxZjllMDJiZg==
5
5
  data.tar.gz: !binary |-
6
- MDBkMTNiNmU5N2E0NGIwY2ZiZmI1MTYzMTFiYTU5ODkxNmI5NDMxYQ==
6
+ MzYyNjU3NmQyNjNhMzM3ZWNmY2IxZmViNzljM2IyODMyZDYwZGU5ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjY1NmFkODBiYzgyZWE4MTA5ZjQwOWU2MDRlZDIyYmZmYmMyZjA0MGNiOWE2
10
- ZWQ4MTBiOGU4N2RmNGRhYmE0MjI3MGIyMjg0MjE1OWE4NzM5NWY1MDBlYmQ2
11
- NzhlZTc1NGZiNjM3ZGQzYTg2ZDU5NmY1M2Q3YmZkNWNmZjgwODQ=
9
+ ZDcwZDYxNTFkNTQ0ODk5MjcxYjY3MTUxNDNkNWFhMTRmNzU4YzMzZDQ1YjE5
10
+ NDhiZjFiODg4YjQ0YzU2ODZlNDEwZWNiMTgzN2JmNmI5MTQzMGMxMWM1OTRl
11
+ ZWVmODk4ODRmZWYwNTcyYjliZjkwMWNhMzEwNzdmZTJmYTg2MDE=
12
12
  data.tar.gz: !binary |-
13
- NmRjYmYyZWM4OGEzYmMyMTUzYzE5MzNjOGQxZDkyZTRiYTgxYzkyYzg3MTIy
14
- YWRiYzkwYmIxYmM3MmIzZmFkZmJlMmZmOTBiM2FjZWFjNjA0ZGMwY2ZhNmI4
15
- ZjVmNzU4ZGUwYzczZmNkM2U0M2ZmNjQxZDRkZDI2YTY3MmVlOTU=
13
+ NmE1NTI0Njc3MTVlMjdmODkyNGY2ZTczNzk3MTZmMzllYmQ5ZTZjOWMzMjQz
14
+ MzY1NjRlNzZkMDViMTA4NzM1OTZmMjQ4ZTZkNTRmNGFiYjBlYzBkNjc0N2I4
15
+ OTdlNTBhODIwM2I5ZjNkYmE0NWQyYWMzMzMxYjQ0NzExODc2YmQ=
@@ -20,31 +20,47 @@ module ZipkinTracer
20
20
  end
21
21
 
22
22
  def call(env)
23
- # handle either a URI object (passed by Faraday v0.8.x in testing), or something string-izable
24
- url = env[:url].respond_to?(:host) ? env[:url] : URI.parse(env[:url].to_s)
25
- local_endpoint = Trace.default_endpoint # The rack middleware set this up for us.
26
- remote_endpoint = callee_endpoint(url, local_endpoint.ip_format) # The endpoint we are calling.
27
- response = nil
28
23
  trace_id = Trace.id.next_id
29
24
  with_trace_id(trace_id) do
30
25
  B3_HEADERS.each do |method, header|
31
26
  env[:request_headers][header] = trace_id.send(method).to_s
32
27
  end
33
- # annotate with method (GET/POST/etc.) and uri path
34
- @tracer.set_rpc_name(trace_id, env[:method].to_s.downcase)
35
- @tracer.record(trace_id, Trace::BinaryAnnotation.new('http.uri', url.path, 'STRING', local_endpoint))
36
- @tracer.record(trace_id, Trace::BinaryAnnotation.new('sa', '1', 'BOOL', remote_endpoint))
37
- @tracer.record(trace_id, Trace::Annotation.new(Trace::Annotation::CLIENT_SEND, local_endpoint))
38
- response = @app.call(env).on_complete do |renv|
39
- # record HTTP status code on response
40
- @tracer.record(trace_id, Trace::BinaryAnnotation.new('http.status', renv[:status].to_s, 'STRING', local_endpoint))
28
+ if trace_id.sampled?
29
+ trace!(env, trace_id)
30
+ else
31
+ @app.call(env)
41
32
  end
42
- @tracer.record(trace_id, Trace::Annotation.new(Trace::Annotation::CLIENT_RECV, local_endpoint))
43
33
  end
44
- response
45
34
  end
46
35
 
47
36
  private
37
+ SERVER_ADDRESS = 'sa'
38
+ SERVER_ADDRESS_SPECIAL_VALUE = '1'
39
+ STRING_TYPE = 'STRING'
40
+ BOOLEAN_TYPE = 'BOOL'
41
+ URI_KEY = 'http.uri'
42
+ STATUS_KEY = 'http.status'
43
+ UNKNOWN_URL = 'unknown'
44
+
45
+
46
+ def trace!(env, trace_id)
47
+ response = nil
48
+ # handle either a URI object (passed by Faraday v0.8.x in testing), or something string-izable
49
+ url = env[:url].respond_to?(:host) ? env[:url] : URI.parse(env[:url].to_s)
50
+ local_endpoint = Trace.default_endpoint # The rack middleware set this up for us.
51
+ remote_endpoint = callee_endpoint(url, local_endpoint.ip_format) # The endpoint we are calling.
52
+ # annotate with method (GET/POST/etc.) and uri path
53
+ @tracer.set_rpc_name(trace_id, env[:method].to_s.downcase)
54
+ @tracer.record(trace_id, Trace::BinaryAnnotation.new(URI_KEY, url.path, STRING_TYPE, local_endpoint))
55
+ @tracer.record(trace_id, Trace::BinaryAnnotation.new(SERVER_ADDRESS, SERVER_ADDRESS_SPECIAL_VALUE, BOOLEAN_TYPE, remote_endpoint))
56
+ @tracer.record(trace_id, Trace::Annotation.new(Trace::Annotation::CLIENT_SEND, local_endpoint))
57
+ response = @app.call(env).on_complete do |renv|
58
+ # record HTTP status code on response
59
+ @tracer.record(trace_id, Trace::BinaryAnnotation.new(STATUS_KEY, renv[:status].to_s, STRING_TYPE, local_endpoint))
60
+ end
61
+ @tracer.record(trace_id, Trace::Annotation.new(Trace::Annotation::CLIENT_RECV, local_endpoint))
62
+ response
63
+ end
48
64
 
49
65
  def with_trace_id(trace_id, &block)
50
66
  Trace.push(trace_id)
@@ -54,7 +70,7 @@ module ZipkinTracer
54
70
  end
55
71
 
56
72
  def callee_endpoint(url, ip_format)
57
- service_name = @service_name || url.host.split('.').first || 'unknown' # default to url-derived service name
73
+ service_name = @service_name || url.host.split('.').first || UNKNOWN_URL # default to url-derived service name
58
74
  Trace::Endpoint.make_endpoint(url.host, url.port, service_name, ip_format)
59
75
  end
60
76
  end
@@ -12,5 +12,5 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  module ZipkinTracer
15
- VERSION = "0.10.0"
15
+ VERSION = "0.10.1"
16
16
  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.10.0
4
+ version: 0.10.1
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: 2015-12-29 00:00:00.000000000 Z
16
+ date: 2016-01-10 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: finagle-thrift