faraday-zipkin 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +7 -0
- data/lib/faraday/zipkin.rb +6 -6
- data/lib/faraday/zipkin/version.rb +1 -1
- data/spec/zipkin_trace_headers_spec.rb +13 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmM0ZTc5MjhmMTJkODNiYjg1MjEyODM2MDJiMGI0YmNjMDJhMjRhZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjI3MmUxMTFkNjVjODc5NTZhOThlODVkNTg4M2U5N2I1MmFkNTc4Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWNmNDA4ZGFjMWU5MzVlNDI4YjFmNDRkNzkyOGQ4NTZhY2Q0Y2IxZmQzMDZl
|
10
|
+
M2UyNTQ4ZTMzYWQ3MDEyNzRjMjMwYjFkODg3MGY4ZDkzYTdiNDYwM2FjMWEz
|
11
|
+
NzBiYTAxMjY2NzJiODhkOTk4YTM1ZDk3NzQ2MzkyZmY1ZWM4ZDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzNlNzBmZWEzNmQ5Njg1OTA1OWU1OTA4NjRiMmFmMGExZDkxN2VmMDQ3MTYx
|
14
|
+
ODY4MzI3YmQ0OWVjMzRmODVmY2ZiZjQ1Y2JkZDM0MTVlZDU3MTlmNjEwNGRi
|
15
|
+
MzQ2MzFkOTEzZDg4OGJlZTVkYTU3M2JiN2MzNDg1YjU4MWI2OGI=
|
data/.travis.yml
ADDED
data/lib/faraday/zipkin.rb
CHANGED
@@ -21,24 +21,24 @@ module Faraday
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def call(env)
|
24
|
-
trace_id = ::Trace.id
|
25
|
-
|
26
24
|
# handle either a URI object (passed by Faraday v0.8.x in testing), or something string-izable
|
27
25
|
url = env[:url].respond_to?(:host) ? env[:url] : URI.parse(env[:url].to_s)
|
28
26
|
service_name = @service_name || url.host.split('.').first # default to url-derived service name
|
29
27
|
endpoint = ::Trace::Endpoint.new(::Trace::Endpoint.host_to_i32(url.host), url.port, service_name)
|
30
28
|
|
29
|
+
trace_id = ::Trace.id
|
31
30
|
::Trace.push(trace_id.next_id) do
|
31
|
+
B3_HEADERS.each do |method, header|
|
32
|
+
env[:request_headers][header] = ::Trace.id.send(method).to_s
|
33
|
+
end
|
34
|
+
|
32
35
|
# annotate with method (GET/POST/etc.) and uri path
|
33
36
|
::Trace.set_rpc_name(env[:method].to_s.upcase)
|
34
37
|
::Trace.record(::Trace::BinaryAnnotation.new("http.uri", url.path, "STRING", endpoint))
|
35
38
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::CLIENT_SEND, endpoint))
|
36
|
-
B3_HEADERS.each do |method, header|
|
37
|
-
env[:request_headers][header] = ::Trace.id.send(method).to_s
|
38
|
-
end
|
39
39
|
result = @app.call(env).on_complete do |renv|
|
40
40
|
# record HTTP status code on response
|
41
|
-
::Trace.record(::Trace::BinaryAnnotation.new("http.status", renv[:status], "I16", endpoint))
|
41
|
+
::Trace.record(::Trace::BinaryAnnotation.new("http.status", [renv[:status]].pack('n'), "I16", endpoint))
|
42
42
|
end
|
43
43
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::CLIENT_RECV, endpoint))
|
44
44
|
result
|
@@ -43,20 +43,24 @@ describe Faraday::Zipkin::TraceHeaders do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
before(:each) {
|
46
|
+
::Trace.sample_rate = 0.1 # make sure initialized
|
46
47
|
allow(::Trace::Endpoint).to receive(:host_to_i32).with(hostname).and_return(host_ip)
|
47
48
|
}
|
48
49
|
|
49
50
|
shared_examples 'can make requests' do
|
51
|
+
def expect_tracing
|
52
|
+
# expect SEND then RECV
|
53
|
+
expect(::Trace).to receive(:set_rpc_name).with('POST')
|
54
|
+
expect(::Trace).to receive(:record).with(instance_of(::Trace::BinaryAnnotation)).twice # http.uri, http.status
|
55
|
+
expect(::Trace).to receive(:record).with(have_value(::Trace::Annotation::CLIENT_SEND).and(have_endpoint(host_ip, service_name))).ordered
|
56
|
+
expect(::Trace).to receive(:record).with(have_value(::Trace::Annotation::CLIENT_RECV).and(have_endpoint(host_ip, service_name))).ordered
|
57
|
+
end
|
58
|
+
|
50
59
|
context 'with tracing id' do
|
51
60
|
let(:trace_id) { ::Trace::TraceId.new(1, 2, 3, true) }
|
52
61
|
|
53
62
|
it 'sets the X-B3 request headers' do
|
54
|
-
|
55
|
-
expect(::Trace).to receive(:set_rpc_name).with('POST')
|
56
|
-
expect(::Trace).to receive(:record).with(instance_of(::Trace::BinaryAnnotation)).twice # http.uri, http.status
|
57
|
-
expect(::Trace).to receive(:record).with(have_value(::Trace::Annotation::CLIENT_SEND).and(have_endpoint(host_ip, service_name))).ordered
|
58
|
-
expect(::Trace).to receive(:record).with(have_value(::Trace::Annotation::CLIENT_RECV).and(have_endpoint(host_ip, service_name))).ordered
|
59
|
-
|
63
|
+
expect_tracing
|
60
64
|
result = nil
|
61
65
|
::Trace.push(trace_id) do
|
62
66
|
result = process('', url).env
|
@@ -70,7 +74,10 @@ describe Faraday::Zipkin::TraceHeaders do
|
|
70
74
|
end
|
71
75
|
|
72
76
|
context 'without tracing id' do
|
77
|
+
after(:each) { ::Trace.pop }
|
78
|
+
|
73
79
|
it 'generates a new ID, and sets the X-B3 request headers' do
|
80
|
+
expect_tracing
|
74
81
|
result = process('', url).env
|
75
82
|
expect(result[:request_headers]['X-B3-TraceId']).to match(/^\h{16}$/)
|
76
83
|
expect(result[:request_headers]['X-B3-ParentSpanId']).to match(/^\h{16}$/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-zipkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Salomon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -117,6 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- .gitignore
|
119
119
|
- .rspec
|
120
|
+
- .travis.yml
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE.txt
|
122
123
|
- README.md
|