rubyzipkin 0.3.12 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rubyzipkin/headers.rb +6 -6
- data/lib/rubyzipkin/metadata_logger.rb +5 -3
- data/lib/rubyzipkin/permanent_header_filter.rb +18 -0
- data/lib/rubyzipkin/trace_filter.rb +8 -1
- data/lib/rubyzipkin/tracesampler.rb +1 -1
- data/lib/rubyzipkin/version.rb +1 -1
- data/lib/rubyzipkin.rb +17 -11
- metadata +6 -5
data/lib/rubyzipkin/headers.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Tracing HTTP header types
|
2
2
|
module RubyZipkin
|
3
3
|
module ZipkinTraceHeader
|
4
|
-
TRACE_ID = "X-
|
5
|
-
SPAN_ID = "X-
|
6
|
-
PARENT_SPAN_ID = "X-
|
7
|
-
TRACE_SAMPLED = "X-
|
8
|
-
TRACE_FLAGS = "X-
|
9
|
-
FORCE_SAMPLE = "X-FORCE-SAMPLE"
|
4
|
+
TRACE_ID = "X-B3-TRACEID"
|
5
|
+
SPAN_ID = "X-B3-SPANID"
|
6
|
+
PARENT_SPAN_ID = "X-B3-PARENTSPANID"
|
7
|
+
TRACE_SAMPLED = "X-B3-SAMPLED"
|
8
|
+
TRACE_FLAGS = "X-B3-FLAGS"
|
9
|
+
FORCE_SAMPLE = "X-B3-FORCE-SAMPLE"
|
10
10
|
end
|
11
11
|
end
|
@@ -6,11 +6,12 @@ module RubyZipkin
|
|
6
6
|
class MetadataLogger
|
7
7
|
|
8
8
|
# log a key value pair into a zipkin trace as a KV span value
|
9
|
-
|
9
|
+
# since logging can ve quite extensive, we set a cap for the max size in bytes for a trace header
|
10
|
+
def self.log(key, value, max_size_bytes = 512)
|
10
11
|
if key.to_s == "action_controller.rescue.request" || key.to_s == "action_controller.rescue.response"
|
11
|
-
::Trace.record(::Trace::BinaryAnnotation.new(key, value.as_json.to_s, "STRING", ::Trace.default_endpoint))
|
12
|
+
::Trace.record(::Trace::BinaryAnnotation.new(key, value.as_json.to_s[0..max_size_bytes], "STRING", ::Trace.default_endpoint))
|
12
13
|
else
|
13
|
-
::Trace.record(::Trace::BinaryAnnotation.new(key, value.to_s, "STRING", ::Trace.default_endpoint))
|
14
|
+
::Trace.record(::Trace::BinaryAnnotation.new(key, value.to_s[0..max_size_bytes], "STRING", ::Trace.default_endpoint))
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -22,5 +23,6 @@ module RubyZipkin
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
26
|
+
|
25
27
|
end
|
26
28
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# There's certain HTTP which just shouldn't be logged and we know about them
|
2
|
+
# Reasons are either security, or size
|
3
|
+
# Specifically session data, cookies, exception rescues.
|
4
|
+
#
|
5
|
+
# This was we don't need each client to black list them and having to set this up on their Initial config.
|
6
|
+
module RubyZipkin
|
7
|
+
module PermanentFilter
|
8
|
+
HEADERS =
|
9
|
+
[
|
10
|
+
"rack.session",
|
11
|
+
"rack.session.record",
|
12
|
+
"rack.session.options",
|
13
|
+
"rack.request.cookie_hash",
|
14
|
+
"rack.request.cookie_string",
|
15
|
+
"rack.request.form_vars"
|
16
|
+
]
|
17
|
+
end
|
18
|
+
end
|
@@ -12,7 +12,7 @@ module RubyZipkin
|
|
12
12
|
end
|
13
13
|
|
14
14
|
keyword_blacklist.each do |key|
|
15
|
-
if uri.to_s.match key
|
15
|
+
if uri.to_s.match key or uri.to
|
16
16
|
return true
|
17
17
|
end
|
18
18
|
end
|
@@ -42,6 +42,13 @@ module RubyZipkin
|
|
42
42
|
return true
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
PermanentFilter::HEADERS.each do |blacklisted|
|
47
|
+
if keyword.to_s.match(/.*(#{blacklisted}).*/)
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
45
52
|
false
|
46
53
|
end
|
47
54
|
end
|
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 = [], uri_sample_filter_list = {}, sampling_rate = 0.
|
17
|
+
def initialize(app, service_name, scribe_server, scribe_port, uri_filter_list = [], http_header_filter_list = [], uri_sample_filter_list = {}, sampling_rate = 0.0001, scribe_max_buffer = 50 )
|
18
18
|
@app = app
|
19
19
|
@lock = Mutex.new
|
20
20
|
|
@@ -33,15 +33,15 @@ module RubyZipkin extend self
|
|
33
33
|
::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@service_name + "_#{normalized_uri(env['PATH_INFO'])}")
|
34
34
|
|
35
35
|
set_sample_rate(env)
|
36
|
-
|
36
|
+
trace_id = get_or_create_trace_id(env)
|
37
37
|
env[ZipkinTraceHeader::PARENT_SPAN_ID] = @spanid
|
38
38
|
env[ZipkinTraceHeader::TRACE_ID] = @tid
|
39
|
+
|
39
40
|
@status, @headers, @response = @app.call(env)
|
40
|
-
|
41
|
+
|
42
|
+
tracing_filter(trace_id, env, @headers)
|
41
43
|
rescue => e
|
42
44
|
#Tracing errors shouldn't block a request.
|
43
|
-
puts "Zipkin error: #{e} \n #{e.backtrace}"
|
44
|
-
raise e
|
45
45
|
end
|
46
46
|
[@status, @headers, @response]
|
47
47
|
end
|
@@ -99,7 +99,8 @@ module RubyZipkin extend self
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def trace_post_data(content)
|
102
|
-
|
102
|
+
# Slightly large size cap to the request input to accomodate larger JSON bodies.
|
103
|
+
MetadataLogger.log('HTTP_REQUEST INPUT', content.to_s, 2048)
|
103
104
|
end
|
104
105
|
|
105
106
|
def trace_hash(content)
|
@@ -113,23 +114,28 @@ module RubyZipkin extend self
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def get_or_create_trace_id(env)
|
117
|
+
|
116
118
|
if env[ZipkinTraceHeader::TRACE_ID].nil? or env[ZipkinTraceHeader::TRACE_ID].to_s.empty?
|
117
119
|
@tid = Trace.generate_id
|
118
|
-
@parentspan = nil
|
119
|
-
|
120
120
|
env[ZipkinTraceHeader::TRACE_ID] = @tid
|
121
121
|
else
|
122
122
|
@tid = env[ZipkinTraceHeader::TRACE_ID]
|
123
|
+
end
|
123
124
|
|
124
|
-
|
125
|
+
if env[ZipkinTraceHeader::SPAN_ID].nil? or env[ZipkinTraceHeader::SPAN_ID].to_s.empty?
|
126
|
+
@parentspan = nil
|
127
|
+
else
|
125
128
|
@parentspan = env[ZipkinTraceHeader::SPAN_ID]
|
126
|
-
end
|
127
129
|
end
|
128
130
|
|
129
131
|
@spanid = Trace.generate_id
|
132
|
+
|
133
|
+
# Save into headers
|
134
|
+
env[ZipkinTraceHeader::TRACE_ID] = @trace_id
|
130
135
|
env[ZipkinTraceHeader::SPAN_ID] = @spanid
|
136
|
+
env[ZipkinTraceHeader::PARENT_SPAN_ID] = @parentspan
|
131
137
|
|
132
|
-
Trace::TraceId.new
|
138
|
+
Trace::TraceId.new(@tid, @parentspan, @spanid, true)
|
133
139
|
end
|
134
140
|
|
135
141
|
def get_or_create_trace_id2(env)
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
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-
|
18
|
+
date: 2013-12-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: scribe
|
@@ -77,6 +77,7 @@ extra_rdoc_files: []
|
|
77
77
|
files:
|
78
78
|
- lib/rubyzipkin/headers.rb
|
79
79
|
- lib/rubyzipkin/metadata_logger.rb
|
80
|
+
- lib/rubyzipkin/permanent_header_filter.rb
|
80
81
|
- lib/rubyzipkin/scriber.rb
|
81
82
|
- lib/rubyzipkin/trace_filter.rb
|
82
83
|
- lib/rubyzipkin/tracesampler.rb
|