faraday-zipkin 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/faraday/zipkin.rb +7 -1
- data/lib/faraday/zipkin/version.rb +1 -1
- data/spec/zipkin_trace_headers_spec.rb +26 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjRlNWZhOWZmYTFkODFjMmNmYjYzODlkZjg2NzMyZmNkYWI3Yzg2Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODY2ZmU5YTQxODM3OTQxZDIzMDU1ODRiNjQ1ZDlkOWI0YzYwYzc4Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODhmYzU1NmUwM2MxYWExNDQ1YmFlODRiYmI5MzU2MjEwMzUyMTZlNTkwNDFl
|
10
|
+
N2JjOTczZjRjYTZmYTAxNDZhYjE2YzU0ZDI1MTA2NWIzMjA1OWFlZTMxMDdl
|
11
|
+
MWJjNDA4NTgxY2I4MWMyYWVhMWU1MzhlZWIxM2ZkNjc3N2VmODE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTZhOWI3ZjdhNmFlZGIxYmFjMTBhODllNjVlNGUyMTA1YmVjMGY1ZTdhZDAy
|
14
|
+
MmI3NDBhZTk3Mjc5ODNhYjhkMGQwZTMyNTQ4N2JhYzk4ZGNlOGZiOGZiOTRm
|
15
|
+
MTRhYWFhMDk1NDg3YWI2MmIwODg3ZjBjNDlmNGUwOGRhYThhYjY=
|
data/lib/faraday/zipkin.rb
CHANGED
@@ -29,11 +29,17 @@ module Faraday
|
|
29
29
|
endpoint = ::Trace::Endpoint.new(::Trace::Endpoint.host_to_i32(url.host), url.port, service_name)
|
30
30
|
|
31
31
|
::Trace.push(trace_id.next_id) do
|
32
|
+
# annotate with method (GET/POST/etc.) and uri path
|
33
|
+
::Trace.set_rpc_name(env[:method].to_s.upcase)
|
34
|
+
::Trace.record(::Trace::BinaryAnnotation.new("http.uri", url.path, "STRING", endpoint))
|
32
35
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::CLIENT_SEND, endpoint))
|
33
36
|
B3_HEADERS.each do |method, header|
|
34
37
|
env[:request_headers][header] = ::Trace.id.send(method).to_s
|
35
38
|
end
|
36
|
-
result = @app.call(env)
|
39
|
+
result = @app.call(env).on_complete do |renv|
|
40
|
+
# record HTTP status code on response
|
41
|
+
::Trace.record(::Trace::BinaryAnnotation.new("http.status", renv[:status], "I16", endpoint))
|
42
|
+
end
|
37
43
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::CLIENT_RECV, endpoint))
|
38
44
|
result
|
39
45
|
end
|
@@ -1,11 +1,29 @@
|
|
1
1
|
describe Faraday::Zipkin::TraceHeaders do
|
2
|
-
|
2
|
+
# allow stubbing of on_complete and response env
|
3
|
+
class ResponseObject
|
4
|
+
attr_reader :env
|
5
|
+
|
6
|
+
def initialize(env, response_env)
|
7
|
+
@env = env
|
8
|
+
@response_env = response_env
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_complete
|
12
|
+
yield @response_env
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:response_env) { { :status => 200 } }
|
18
|
+
let(:wrapped_app) { lambda{|env| ResponseObject.new(env, response_env)} }
|
3
19
|
|
4
20
|
let(:hostname) { 'service.example.com' }
|
5
21
|
let(:host_ip) { 0x11223344 }
|
22
|
+
let(:raw_url) { "https://#{hostname}/some/path/here" }
|
6
23
|
|
7
24
|
def process(body, url, headers={})
|
8
25
|
env = {
|
26
|
+
:method => :post,
|
9
27
|
:url => url,
|
10
28
|
:body => body,
|
11
29
|
:request_headers => Faraday::Utils::Headers.new(headers),
|
@@ -34,12 +52,14 @@ describe Faraday::Zipkin::TraceHeaders do
|
|
34
52
|
|
35
53
|
it 'sets the X-B3 request headers' do
|
36
54
|
# expect SEND then RECV
|
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
|
37
57
|
expect(::Trace).to receive(:record).with(have_value(::Trace::Annotation::CLIENT_SEND).and(have_endpoint(host_ip, service_name))).ordered
|
38
58
|
expect(::Trace).to receive(:record).with(have_value(::Trace::Annotation::CLIENT_RECV).and(have_endpoint(host_ip, service_name))).ordered
|
39
59
|
|
40
60
|
result = nil
|
41
61
|
::Trace.push(trace_id) do
|
42
|
-
result = process('', url)
|
62
|
+
result = process('', url).env
|
43
63
|
end
|
44
64
|
expect(result[:request_headers]['X-B3-TraceId']).to eq('0000000000000001')
|
45
65
|
expect(result[:request_headers]['X-B3-ParentSpanId']).to eq('0000000000000003')
|
@@ -51,7 +71,7 @@ describe Faraday::Zipkin::TraceHeaders do
|
|
51
71
|
|
52
72
|
context 'without tracing id' do
|
53
73
|
it 'generates a new ID, and sets the X-B3 request headers' do
|
54
|
-
result = process('', url)
|
74
|
+
result = process('', url).env
|
55
75
|
expect(result[:request_headers]['X-B3-TraceId']).to match(/^\h{16}$/)
|
56
76
|
expect(result[:request_headers]['X-B3-ParentSpanId']).to match(/^\h{16}$/)
|
57
77
|
expect(result[:request_headers]['X-B3-SpanId']).to match(/^\h{16}$/)
|
@@ -65,14 +85,14 @@ describe Faraday::Zipkin::TraceHeaders do
|
|
65
85
|
let(:service_name) { 'service' }
|
66
86
|
|
67
87
|
context 'request with string URL' do
|
68
|
-
let(:url) {
|
88
|
+
let(:url) { raw_url }
|
69
89
|
|
70
90
|
include_examples 'can make requests'
|
71
91
|
end
|
72
92
|
|
73
93
|
# in testing, Faraday v0.8.x passes a URI object rather than a string
|
74
94
|
context 'request with pre-parsed URL' do
|
75
|
-
let(:url) { URI.parse(
|
95
|
+
let(:url) { URI.parse(raw_url) }
|
76
96
|
|
77
97
|
include_examples 'can make requests'
|
78
98
|
end
|
@@ -84,7 +104,7 @@ describe Faraday::Zipkin::TraceHeaders do
|
|
84
104
|
|
85
105
|
# in testing, Faraday v0.8.x passes a URI object rather than a string
|
86
106
|
context 'request with pre-parsed URL' do
|
87
|
-
let(:url) { URI.parse(
|
107
|
+
let(:url) { URI.parse(raw_url) }
|
88
108
|
|
89
109
|
include_examples 'can make requests'
|
90
110
|
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.2.
|
4
|
+
version: 0.2.1
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|