zipkin-tracer 0.33.0 → 0.34.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 +4 -4
- data/lib/zipkin-tracer/application.rb +6 -5
- data/lib/zipkin-tracer/config.rb +0 -2
- data/lib/zipkin-tracer/excon/zipkin-tracer.rb +0 -1
- data/lib/zipkin-tracer/faraday/zipkin-tracer.rb +0 -2
- data/lib/zipkin-tracer/rack/zipkin-tracer.rb +2 -11
- data/lib/zipkin-tracer/rack/zipkin_env.rb +11 -6
- data/lib/zipkin-tracer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba81449b69065fcd0ffcca18f0750e49826896cc8321c3a18d2e6df22a25cd27
|
4
|
+
data.tar.gz: 861e0bfb101b56935c0488c34d3db34154226b2625067c3db7b88e8bb168bfeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f136b2d49f70678fdbb768707418ec099c46e5dceef84efb83d063f057927e1cdd2ff7e750ea3f31a3b0a0a5a02869996131d24b35108ef178711a53f91bc7a
|
7
|
+
data.tar.gz: 78dfc19eee7a3f4b9b77ef8a980783cf2fc79e3087d406c7e89ac1e915cacd941f44b295f40921ca1966ccafa6688b71e5d94b1ef8a4969c4312bd5c408fd44c
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module ZipkinTracer
|
2
|
-
|
3
2
|
# Useful methods on the Application we are instrumenting
|
4
3
|
class Application
|
5
|
-
#
|
6
|
-
def self.routable_request?(
|
4
|
+
# Determines if our framework knows whether the request will be routed to a controller
|
5
|
+
def self.routable_request?(env)
|
7
6
|
return true unless defined?(Rails) # If not running on a Rails app, we can't verify if it is invalid
|
7
|
+
path_info = env[ZipkinTracer::RackHandler::PATH_INFO]
|
8
|
+
http_method = env[ZipkinTracer::RackHandler::REQUEST_METHOD]
|
8
9
|
Rails.application.routes.recognize_path(path_info, method: http_method)
|
9
10
|
true
|
10
11
|
rescue ActionController::RoutingError
|
11
12
|
false
|
12
13
|
end
|
13
14
|
|
14
|
-
def self.
|
15
|
+
def self.route(env)
|
15
16
|
return nil unless defined?(Rails)
|
16
17
|
stub_env = {
|
17
18
|
"PATH_INFO" => env[ZipkinTracer::RackHandler::PATH_INFO],
|
@@ -27,7 +28,7 @@ module ZipkinTracer
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def self.logger
|
30
|
-
if defined?(Rails.logger)
|
31
|
+
if defined?(Rails.logger)
|
31
32
|
Rails.logger
|
32
33
|
else
|
33
34
|
Logger.new(STDOUT)
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -26,8 +26,6 @@ module ZipkinTracer
|
|
26
26
|
@sample_rate = config[:sample_rate] || DEFAULTS[:sample_rate]
|
27
27
|
# A block of code which can be called to do extra annotations of traces
|
28
28
|
@annotate_plugin = config[:annotate_plugin] # call for trace annotation
|
29
|
-
@filter_plugin = config[:filter_plugin] # skip tracing if returns false
|
30
|
-
@whitelist_plugin = config[:whitelist_plugin] # force sampling if returns true
|
31
29
|
# A block of code which can be called to skip traces. Skip tracing if returns false
|
32
30
|
@filter_plugin = config[:filter_plugin]
|
33
31
|
# A block of code which can be called to force sampling. Forces sampling if returns true
|
@@ -25,7 +25,7 @@ module ZipkinTracer
|
|
25
25
|
zipkin_env = ZipkinEnv.new(env, @config)
|
26
26
|
trace_id = zipkin_env.trace_id
|
27
27
|
TraceContainer.with_trace_id(trace_id) do
|
28
|
-
if !trace_id.sampled?
|
28
|
+
if !trace_id.sampled?
|
29
29
|
@app.call(env)
|
30
30
|
else
|
31
31
|
@tracer.with_new_span(trace_id, span_name(env)) do |span|
|
@@ -37,16 +37,8 @@ module ZipkinTracer
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
def routable_request?(env)
|
41
|
-
Application.routable_request?(env[PATH_INFO], env[REQUEST_METHOD])
|
42
|
-
end
|
43
|
-
|
44
|
-
def route(env)
|
45
|
-
Application.get_route(env)
|
46
|
-
end
|
47
|
-
|
48
40
|
def span_name(env)
|
49
|
-
"#{env[REQUEST_METHOD].to_s.downcase} #{route(env)}".strip
|
41
|
+
"#{env[REQUEST_METHOD].to_s.downcase} #{Application.route(env)}".strip
|
50
42
|
end
|
51
43
|
|
52
44
|
def annotate_plugin(span, env, status, response_headers, response_body)
|
@@ -56,7 +48,6 @@ module ZipkinTracer
|
|
56
48
|
def trace!(span, zipkin_env, &block)
|
57
49
|
trace_request_information(span, zipkin_env)
|
58
50
|
span.kind = Trace::Span::Kind::SERVER
|
59
|
-
span.record('whitelisted') if zipkin_env.force_sample?
|
60
51
|
status, headers, body = yield
|
61
52
|
ensure
|
62
53
|
annotate_plugin(span, zipkin_env.env, status, headers, body)
|
@@ -20,10 +20,6 @@ module ZipkinTracer
|
|
20
20
|
@called_with_zipkin_headers ||= B3_REQUIRED_HEADERS.all? { |key| @env.key?(key) }
|
21
21
|
end
|
22
22
|
|
23
|
-
def force_sample?
|
24
|
-
@force_sample ||= @config.whitelist_plugin && @config.whitelist_plugin.call(@env)
|
25
|
-
end
|
26
|
-
|
27
23
|
private
|
28
24
|
|
29
25
|
B3_REQUIRED_HEADERS = %w(HTTP_X_B3_TRACEID HTTP_X_B3_SPANID).freeze
|
@@ -61,15 +57,24 @@ module ZipkinTracer
|
|
61
57
|
end
|
62
58
|
|
63
59
|
def sampled_header_value(parent_trace_sampled)
|
64
|
-
if parent_trace_sampled
|
60
|
+
if parent_trace_sampled # A service upstream decided this goes in all the way
|
65
61
|
parent_trace_sampled
|
66
62
|
else
|
67
|
-
new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered?)
|
63
|
+
new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered? && routable_request?)
|
68
64
|
end
|
69
65
|
end
|
70
66
|
|
67
|
+
def force_sample?
|
68
|
+
@config.whitelist_plugin && @config.whitelist_plugin.call(@env)
|
69
|
+
end
|
70
|
+
|
71
71
|
def filtered?
|
72
72
|
@config.filter_plugin && !@config.filter_plugin.call(@env)
|
73
73
|
end
|
74
|
+
|
75
|
+
def routable_request?
|
76
|
+
Application.routable_request?(@env)
|
77
|
+
end
|
78
|
+
|
74
79
|
end
|
75
80
|
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.
|
4
|
+
version: 0.34.0
|
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: 2019-03-
|
16
|
+
date: 2019-03-28 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -199,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
199
|
requirements:
|
200
200
|
- - ">="
|
201
201
|
- !ruby/object:Gem::Version
|
202
|
-
version: 2.
|
202
|
+
version: 2.3.0
|
203
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
204
|
requirements:
|
205
205
|
- - ">="
|