rubyzipkin 0.3.11 → 0.3.12
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.
- data/lib/rubyzipkin/trace_filter.rb +13 -0
- data/lib/rubyzipkin/version.rb +1 -1
- data/lib/rubyzipkin.rb +18 -5
- metadata +4 -4
@@ -20,6 +20,19 @@ module RubyZipkin
|
|
20
20
|
return false
|
21
21
|
end
|
22
22
|
|
23
|
+
# Matcher to get a custom sample rate for a specific URI paths.
|
24
|
+
# returns the sample rate or nil
|
25
|
+
def self.UriSamplingMatches?(uri, uri_hash = {})
|
26
|
+
|
27
|
+
uri_hash.each do |key, value|
|
28
|
+
if uri.to_s.match key
|
29
|
+
return value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
|
23
36
|
# Filter a string based on a keyword blacklist
|
24
37
|
# Meant to define if a key should be traced or not.
|
25
38
|
def self.KeywordFilterMatches?(keyword, keyword_blacklist = [])
|
data/lib/rubyzipkin/version.rb
CHANGED
data/lib/rubyzipkin.rb
CHANGED
@@ -14,7 +14,7 @@ module RubyZipkin extend self
|
|
14
14
|
|
15
15
|
class RackHandler
|
16
16
|
|
17
|
-
def initialize(app, service_name, scribe_server, scribe_port, uri_filter_list = [], http_header_filter_list = [],
|
17
|
+
def initialize(app, service_name, scribe_server, scribe_port, uri_filter_list = [], http_header_filter_list = [], uri_sample_filter_list = {}, sampling_rate = 0.01, scribe_max_buffer = 10 )
|
18
18
|
@app = app
|
19
19
|
@lock = Mutex.new
|
20
20
|
|
@@ -23,6 +23,7 @@ module RubyZipkin extend self
|
|
23
23
|
@sample_rate = sampling_rate
|
24
24
|
@uri_filter_list = uri_filter_list
|
25
25
|
@http_header_filter_list = http_header_filter_list
|
26
|
+
@uri_sample_filter_list = uri_sample_filter_list
|
26
27
|
@scribe = Scribe.new("#{scribe_server}:#{scribe_port}")
|
27
28
|
::Trace.tracer = ::Trace::ZipkinTracer.new(Scriber.new(@scribe), scribe_max_buffer)
|
28
29
|
end
|
@@ -30,7 +31,9 @@ module RubyZipkin extend self
|
|
30
31
|
def call(env)
|
31
32
|
begin
|
32
33
|
::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@service_name + "_#{normalized_uri(env['PATH_INFO'])}")
|
33
|
-
|
34
|
+
|
35
|
+
set_sample_rate(env)
|
36
|
+
|
34
37
|
env[ZipkinTraceHeader::PARENT_SPAN_ID] = @spanid
|
35
38
|
env[ZipkinTraceHeader::TRACE_ID] = @tid
|
36
39
|
@status, @headers, @response = @app.call(env)
|
@@ -43,6 +46,17 @@ module RubyZipkin extend self
|
|
43
46
|
[@status, @headers, @response]
|
44
47
|
end
|
45
48
|
|
49
|
+
private
|
50
|
+
def set_sample_rate(env)
|
51
|
+
custom_sample_rate =RubyZipkin::TraceFilter.UriSamplingMatches?(normalized_uri(env["PATH_INFO"]), @uri_sample_filter_list)
|
52
|
+
|
53
|
+
if custom_sample_rate
|
54
|
+
::Trace.sample_rate = custom_sample_rate
|
55
|
+
else
|
56
|
+
::Trace.sample_rate = @sample_rate
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
46
60
|
private
|
47
61
|
def tracing_filter(trace_id, env, headers=nil)
|
48
62
|
if RubyZipkin::TraceFilter.UriFilterMatches?(normalized_uri(env["PATH_INFO"]), @uri_filter_list)
|
@@ -115,12 +129,11 @@ module RubyZipkin extend self
|
|
115
129
|
@spanid = Trace.generate_id
|
116
130
|
env[ZipkinTraceHeader::SPAN_ID] = @spanid
|
117
131
|
|
118
|
-
|
119
|
-
Trace::TraceId.new @tid, @parentspan, @spanid, true, ::TRACE::Flags::DEBUG
|
132
|
+
Trace::TraceId.new @tid, @parentspan, @spanid, true
|
120
133
|
end
|
121
134
|
|
122
135
|
def get_or_create_trace_id2(env)
|
123
|
-
::Trace::TraceId.new(::Trace.generate_id, nil, ::Trace.generate_id, true
|
136
|
+
::Trace::TraceId.new(::Trace.generate_id, nil, ::Trace.generate_id, true)
|
124
137
|
end
|
125
138
|
end
|
126
139
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyzipkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 12
|
10
|
+
version: 0.3.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Marcin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-11-
|
18
|
+
date: 2013-11-18 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: scribe
|