ruby-zipkin 0.2.6 → 0.2.7
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/ruby-zipkin/trace_filter.rb +0 -2
- data/lib/ruby-zipkin/version.rb +1 -1
- data/lib/ruby-zipkin.rb +40 -9
- metadata +4 -4
@@ -8,7 +8,6 @@ module RubyZipkin
|
|
8
8
|
def self.UriFilterMatches?(uri, keyword_blacklist = [])
|
9
9
|
#exclude static content requests
|
10
10
|
if uri.to_s.match(/.*(\.svg)|(\.ttf)|(\.ott)|(\.woff)/)
|
11
|
-
puts "zipkin uri #{uri} matches!"
|
12
11
|
return true
|
13
12
|
end
|
14
13
|
|
@@ -22,7 +21,6 @@ module RubyZipkin
|
|
22
21
|
#exclude static content requests
|
23
22
|
keyword_blacklist.each do |blacklisted|
|
24
23
|
if keyword.to_s.match(/.*(#{blacklisted}).*/)
|
25
|
-
puts "zipkin keyword #{keyword} matches #{keyword}!"
|
26
24
|
return true
|
27
25
|
end
|
28
26
|
end
|
data/lib/ruby-zipkin/version.rb
CHANGED
data/lib/ruby-zipkin.rb
CHANGED
@@ -26,14 +26,24 @@ module RubyZipkin extend self
|
|
26
26
|
|
27
27
|
def call(env)
|
28
28
|
begin
|
29
|
-
::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@service_name)
|
29
|
+
::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@service_name + "_#{normalized_uri(env['PATH_INFO'])}")
|
30
30
|
::Trace.sample_rate = 0.1
|
31
31
|
env[ZipkinTraceHeader::PARENT_SPAN_ID] = @spanid
|
32
32
|
env[ZipkinTraceHeader::TRACE_ID] = @tid
|
33
|
+
|
34
|
+
# the debug trace
|
35
|
+
#id = ::Trace::TraceId.new(@tid, nil, ::Trace.generate_id, true, ::Trace::Flags::DEBUG)
|
36
|
+
#::Trace.push(id)
|
37
|
+
#::Trace.set_rpc_name("debug")
|
38
|
+
#::Trace.record(::Trace::BinaryAnnotation.new("http.uri", '/debug', "STRING", ::Trace.default_endpoint))
|
39
|
+
|
33
40
|
@status, @headers, @response = @app.call(env)
|
34
41
|
tracing_filter(get_or_create_trace_id2(env), env, @headers)
|
42
|
+
|
43
|
+
#::Trace.pop
|
35
44
|
rescue => e
|
36
45
|
#Tracing errors shouldn't block a request.
|
46
|
+
Rails.logger.info "Zipkin error: #{e} \n #{e.backtrace}"
|
37
47
|
puts "Zipkin error: #{e} \n #{e.backtrace}"
|
38
48
|
end
|
39
49
|
[@status, @headers, @response]
|
@@ -41,32 +51,53 @@ module RubyZipkin extend self
|
|
41
51
|
|
42
52
|
private
|
43
53
|
def tracing_filter(trace_id, env, headers=nil)
|
44
|
-
if RubyZipkin::TraceFilter.UriFilterMatches?(env["PATH_INFO"], @uri_filter_list)
|
45
|
-
puts "ZIPKIN URI FILTER MATCHED. NOT LOGGING"
|
54
|
+
if RubyZipkin::TraceFilter.UriFilterMatches?(normalized_uri(env["PATH_INFO"]), @uri_filter_list)
|
46
55
|
return
|
47
56
|
end
|
48
57
|
@lock.synchronize do
|
49
58
|
puts "zipkin trace id #{trace_id}"
|
50
59
|
::Trace.push(trace_id)
|
51
|
-
|
52
|
-
|
60
|
+
|
61
|
+
set_trace_caption(env)
|
62
|
+
::Trace.record(::Trace::BinaryAnnotation.new("http.uri", normalized_uri(env["PATH_INFO"]), "STRING", ::Trace.default_endpoint))
|
63
|
+
::Trace.record(::Trace::BinaryAnnotation.new("http.status", @status.to_s, "STRING", ::Trace.default_endpoint))
|
53
64
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_RECV, ::Trace.default_endpoint))
|
54
|
-
|
65
|
+
|
66
|
+
add_referer(env)
|
55
67
|
trace_hash(headers)
|
56
|
-
|
68
|
+
trace_hash(env)
|
69
|
+
trace_post_data(env["rack.input"].read)
|
57
70
|
end
|
58
71
|
yield if block_given?
|
59
72
|
ensure
|
60
73
|
@lock.synchronize do
|
61
74
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_SEND, ::Trace.default_endpoint))
|
75
|
+
add_referer(env)
|
62
76
|
::Trace.pop
|
63
|
-
puts 'zipking trace out'
|
64
77
|
end
|
65
78
|
end
|
66
79
|
|
80
|
+
def add_referer(env)
|
81
|
+
if env['HTTP_REFERER']
|
82
|
+
::Trace.record(::Trace::BinaryAnnotation.new("http.referer", env['HTTP_REFERER'], "STRING", ::Trace.default_endpoint))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def normalized_uri(path)
|
87
|
+
path.gsub(/\/\d+/, '/:id')
|
88
|
+
end
|
89
|
+
|
90
|
+
def set_trace_caption(env)
|
91
|
+
::Trace.set_rpc_name("#{env['REQUEST_METHOD']} - #{@status.to_s} - #{normalized_uri(env['PATH_INFO'])}")
|
92
|
+
end
|
93
|
+
|
94
|
+
def trace_post_data(content)
|
95
|
+
MetadataLogger.log('HTTP_REQUEST INPUT', content.to_s)
|
96
|
+
end
|
97
|
+
|
67
98
|
def trace_hash(content)
|
68
99
|
if content
|
69
|
-
content.
|
100
|
+
content.sort.map do |k,v|
|
70
101
|
unless RubyZipkin::TraceFilter.KeywordFilterMatches?(k.to_s, @http_header_filter_list)
|
71
102
|
MetadataLogger.log(k.to_s, v)
|
72
103
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-zipkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
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-10-
|
18
|
+
date: 2013-10-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: finagle-thrift
|