faraday-zipkin 0.0.1 → 0.1.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 +8 -8
- data/README.md +10 -3
- data/faraday-zipkin.gemspec +1 -1
- data/lib/faraday/zipkin/version.rb +1 -1
- data/lib/faraday/zipkin.rb +12 -6
- data/spec/zipkin_trace_headers_spec.rb +25 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzUwZDc2ZDFjODFlODBmNjA1ZjZmMWQ0ODdlMDYyNWFhN2U2NGUwMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDcxYTc2ODYwMTMzZDg5NzJiYzBjM2MzOTQzN2M0NGE2MDQzNTA1Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTc4YTMxNDM0ZjQ3YWUzYmQ5ZGM2NmM2ZTA1NjEwMjZjMjEyZGZiMmM1ZDMy
|
10
|
+
MDFkZjY5OTcwMDBiOGMwMTQwZTRhYjU0MDM2NTJmZGZjMjQzYzRiNjliOTM1
|
11
|
+
YjZiN2YxNDFiOTAzOGE4MjFlNGJkZmZhMzVhMjY0YjQyYWZjMTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWFkNjUyZjc0MzFhMGQxNDQ1MGM3OWMyNjE5ZmRiYTEyMGJiMzk3MzgwMmM5
|
14
|
+
ZWZmZjE5NDAzMmI0ZGYyYWMwMTM4YzI5NTUyNzY2NTBlYmQ4NGNkMTM1OGI0
|
15
|
+
YzJlNTA1NjQyMDg1MDY4NzdiMmU4ZTk5NjE4ZGYxZWI2ODczMGY=
|
data/README.md
CHANGED
@@ -2,13 +2,20 @@
|
|
2
2
|
|
3
3
|
Faraday middleware to generate Zipkin tracing headers.
|
4
4
|
|
5
|
+
For more information about Zipkin, go to
|
6
|
+
http://twitter.github.io/zipkin
|
7
|
+
http://github.com/twitter/zipkin
|
8
|
+
|
9
|
+
This gem implements the client side described at
|
10
|
+
http://twitter.github.io/zipkin/instrument.html
|
11
|
+
|
5
12
|
Note that you should also be using the zipkin-tracer Rack middleware
|
6
13
|
to generate trace IDs around your requests:
|
7
14
|
https://github.com/twitter/zipkin/tree/master/zipkin-gems/zipkin-tracer
|
8
15
|
|
9
|
-
Zipkin tracing headers are documented at
|
16
|
+
Zipkin tracing headers for HTTP APIs are documented at
|
10
17
|
https://github.com/twitter/zipkin/blob/master/doc/collector-api.md
|
11
|
-
|
18
|
+
|
12
19
|
## Usage
|
13
20
|
|
14
21
|
Include Faraday::Zipkin::TraceHeaders as a Faraday middleware:
|
@@ -25,7 +32,7 @@ Include Faraday::Zipkin::TraceHeaders as a Faraday middleware:
|
|
25
32
|
|
26
33
|
## Contributing
|
27
34
|
|
28
|
-
1. Fork it ( https://github.com/
|
35
|
+
1. Fork it ( https://github.com/Oscil8/faraday-zipkin/fork )
|
29
36
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
37
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/faraday-zipkin.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "faraday", ">= 0.8"
|
22
22
|
spec.add_dependency "thrift", "~> 0.9.0"
|
23
|
-
spec.add_dependency "finagle-thrift", "~> 1.
|
23
|
+
spec.add_dependency "finagle-thrift", "~> 1.2.0"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/faraday/zipkin.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'finagle-thrift'
|
3
3
|
require 'finagle-thrift/trace'
|
4
|
+
require 'uri'
|
4
5
|
|
5
|
-
require
|
6
|
+
require 'faraday/zipkin/version'
|
6
7
|
|
7
8
|
module Faraday
|
8
9
|
module Zipkin
|
@@ -11,8 +12,7 @@ module Faraday
|
|
11
12
|
:trace_id => "X-B3-TraceId",
|
12
13
|
:parent_id => "X-B3-ParentSpanId",
|
13
14
|
:span_id => "X-B3-SpanId",
|
14
|
-
:sampled => "X-B3-Sampled"
|
15
|
-
:flags => "X-B3-Flags"
|
15
|
+
:sampled => "X-B3-Sampled"
|
16
16
|
}.freeze
|
17
17
|
|
18
18
|
def initialize(app)
|
@@ -21,10 +21,16 @@ module Faraday
|
|
21
21
|
|
22
22
|
def call(env)
|
23
23
|
trace_id = ::Trace.id
|
24
|
-
|
25
|
-
|
24
|
+
host = URI.parse(env[:url]).host
|
25
|
+
::Trace.push(trace_id.next_id) do
|
26
|
+
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::CLIENT_SEND, host))
|
27
|
+
B3_HEADERS.each do |method, header|
|
28
|
+
env[:request_headers][header] = ::Trace.id.send(method).to_s
|
29
|
+
end
|
30
|
+
result = @app.call(env)
|
31
|
+
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::CLIENT_RECV, host))
|
32
|
+
result
|
26
33
|
end
|
27
|
-
@app.call(env)
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
@@ -1,28 +1,49 @@
|
|
1
1
|
describe Faraday::Zipkin::TraceHeaders do
|
2
2
|
let(:middleware) { described_class.new(lambda{|env| env}) }
|
3
|
+
let(:hostname) { 'service.example.com' }
|
3
4
|
|
4
5
|
def process(body, headers={})
|
5
6
|
env = {
|
7
|
+
:url => "https://#{hostname}/some/path/here",
|
6
8
|
:body => body,
|
7
9
|
:request_headers => Faraday::Utils::Headers.new(headers),
|
8
10
|
}
|
9
11
|
middleware.call(env)
|
10
12
|
end
|
11
13
|
|
14
|
+
# custom matcher for trace annotation
|
15
|
+
RSpec::Matchers.define :have_value_and_host do |v, h|
|
16
|
+
match { |actual| actual.value == v && actual.host == h }
|
17
|
+
end
|
18
|
+
|
12
19
|
context 'request' do
|
13
20
|
context 'with tracing id' do
|
14
|
-
let(:trace_id) { ::Trace::TraceId.new(1, 2, 3, true
|
21
|
+
let(:trace_id) { ::Trace::TraceId.new(1, 2, 3, true) }
|
15
22
|
|
16
23
|
it 'sets the X-B3 request headers' do
|
24
|
+
# expect SEND then RECV
|
25
|
+
expect(::Trace).to receive(:record).with(have_value_and_host(::Trace::Annotation::CLIENT_SEND, hostname)).ordered
|
26
|
+
expect(::Trace).to receive(:record).with(have_value_and_host(::Trace::Annotation::CLIENT_RECV, hostname)).ordered
|
27
|
+
|
17
28
|
result = nil
|
18
29
|
::Trace.push(trace_id) do
|
19
30
|
result = process('')
|
20
31
|
end
|
21
32
|
expect(result[:request_headers]['X-B3-TraceId']).to eq('0000000000000001')
|
22
|
-
expect(result[:request_headers]['X-B3-ParentSpanId']).to eq('
|
23
|
-
expect(result[:request_headers]['X-B3-SpanId']).
|
33
|
+
expect(result[:request_headers]['X-B3-ParentSpanId']).to eq('0000000000000003')
|
34
|
+
expect(result[:request_headers]['X-B3-SpanId']).not_to eq('0000000000000003')
|
35
|
+
expect(result[:request_headers]['X-B3-SpanId']).to match(/^\h{16}$/)
|
24
36
|
expect(result[:request_headers]['X-B3-Sampled']).to eq('true')
|
25
|
-
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'without tracing id' do
|
41
|
+
it 'generates a new ID, and sets the X-B3 request headers' do
|
42
|
+
result = process('')
|
43
|
+
expect(result[:request_headers]['X-B3-TraceId']).to match(/^\h{16}$/)
|
44
|
+
expect(result[:request_headers]['X-B3-ParentSpanId']).to match(/^\h{16}$/)
|
45
|
+
expect(result[:request_headers]['X-B3-SpanId']).to match(/^\h{16}$/)
|
46
|
+
expect(result[:request_headers]['X-B3-Sampled']).to match(/(true|false)/)
|
26
47
|
end
|
27
48
|
end
|
28
49
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.2.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|