zipkin-tracer 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer.rb +47 -6
- metadata +97 -68
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODM0MDUyZmVmZTcyNjkwODQ1ZjMxOTdhYjQ1NWUzNzE3N2NiNTgwNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmI1NTA2NTk0YzdlZDdlYjlmNjZjYmRlYzFlOGJmOGVlY2U3ZTk5Ng==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2YyMjk4MDU0MDk3ZDYxMjdmMGU4MGIwMzZhZmM4ZDM4NzM1MTUzMmU2OTFi
|
10
|
+
YjRiNmI1OWM0NTJlYmUwNDA5YThlODI0ZTI0MWFiNGI3OTQwMTFkYjA5MTk0
|
11
|
+
ZjAyYjBiMGJmYTNmNjkxMmI2YjczNjQ1ZGQ0YjQ4Y2VhMWZjOGI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGJlM2E0MDM2MzViMDVjMTMwYmU5ZjczMWY0ZmU1MTExNTYyOTIyOTRhODBj
|
14
|
+
YWQwMWU4ZTAwZmIyYmZhMzlhMjA4MzU5NDE5ODRkOWNiOTRhYzg1NTk4ZDU1
|
15
|
+
MGU5ZWE5ZjlkOTAxYTY5Yjg2ZDQ3ZDY3OTMxMWM1Y2Y5OWRlNGU=
|
data/lib/zipkin-tracer.rb
CHANGED
@@ -20,11 +20,14 @@ require 'zipkin-tracer/careless_scribe'
|
|
20
20
|
module ZipkinTracer extend self
|
21
21
|
|
22
22
|
class RackHandler
|
23
|
-
|
23
|
+
B3_REQUIRED_HEADERS = %w[HTTP_X_B3_TRACEID HTTP_X_B3_PARENTSPANID HTTP_X_B3_SPANID HTTP_X_B3_SAMPLED]
|
24
|
+
B3_OPT_HEADERS = %w[HTTP_X_B3_FLAGS]
|
25
|
+
|
26
|
+
def initialize(app, config=nil)
|
24
27
|
@app = app
|
25
28
|
@lock = Mutex.new
|
26
29
|
|
27
|
-
config
|
30
|
+
config ||= app.config.zipkin_tracer # if not specified, try on app (e.g. Rails 3+)
|
28
31
|
@service_name = config[:service_name]
|
29
32
|
@service_port = config[:service_port]
|
30
33
|
|
@@ -49,31 +52,69 @@ module ZipkinTracer extend self
|
|
49
52
|
0.1
|
50
53
|
end
|
51
54
|
|
55
|
+
@annotate_plugin = config[:annotate_plugin] # call for trace annotation
|
56
|
+
@filter_plugin = config[:filter_plugin] # skip tracing if returns false
|
57
|
+
@whitelist_plugin = config[:whitelist_plugin] # force sampling if returns true
|
58
|
+
|
52
59
|
::Trace.tracer = ::Trace::ZipkinTracer.new(CarelessScribe.new(scribe), scribe_max_buffer)
|
53
60
|
end
|
54
61
|
|
55
62
|
def call(env)
|
56
|
-
|
63
|
+
# skip certain requests
|
64
|
+
return @app.call(env) if filtered?(env)
|
65
|
+
|
57
66
|
::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@service_name).with_port(@service_port)
|
58
67
|
::Trace.sample_rate=(@sample_rate)
|
59
|
-
|
68
|
+
whitelisted = force_sample?(env)
|
69
|
+
id = get_or_create_trace_id(env, whitelisted) # note that this depends on the sample rate being set
|
70
|
+
tracing_filter(id, env, whitelisted) { @app.call(env) }
|
60
71
|
end
|
61
72
|
|
62
73
|
private
|
63
|
-
def
|
74
|
+
def annotate(env, status, response_headers, response_body)
|
75
|
+
@annotate_plugin.call(env, status, response_headers, response_body) if @annotate_plugin
|
76
|
+
end
|
77
|
+
|
78
|
+
def filtered?(env)
|
79
|
+
@filter_plugin && !@filter_plugin.call(env)
|
80
|
+
end
|
81
|
+
|
82
|
+
def force_sample?(env)
|
83
|
+
@whitelist_plugin && @whitelist_plugin.call(env)
|
84
|
+
end
|
85
|
+
|
86
|
+
def tracing_filter(trace_id, env, whitelisted=false)
|
64
87
|
@lock.synchronize do
|
65
88
|
::Trace.push(trace_id)
|
66
89
|
::Trace.set_rpc_name(env["REQUEST_METHOD"]) # get/post and all that jazz
|
67
90
|
::Trace.record(::Trace::BinaryAnnotation.new("http.uri", env["PATH_INFO"], "STRING", ::Trace.default_endpoint))
|
68
91
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_RECV, ::Trace.default_endpoint))
|
92
|
+
::Trace.record(::Trace::Annotation.new('whitelisted', ::Trace.default_endpoint)) if whitelisted
|
69
93
|
end
|
70
|
-
yield if block_given?
|
94
|
+
status, headers, body = yield if block_given?
|
71
95
|
ensure
|
72
96
|
@lock.synchronize do
|
73
97
|
::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_SEND, ::Trace.default_endpoint))
|
98
|
+
annotate(env, status, headers, body)
|
74
99
|
::Trace.pop
|
75
100
|
end
|
76
101
|
end
|
102
|
+
|
103
|
+
private
|
104
|
+
def get_or_create_trace_id(env, whitelisted, default_flags = ::Trace::Flags::EMPTY)
|
105
|
+
trace_parameters = if B3_REQUIRED_HEADERS.all? { |key| env.has_key?(key) }
|
106
|
+
env.values_at(*B3_REQUIRED_HEADERS)
|
107
|
+
else
|
108
|
+
new_id = Trace.generate_id
|
109
|
+
[new_id, nil, new_id, ("true" if whitelisted || Trace.should_sample?)]
|
110
|
+
end
|
111
|
+
trace_parameters[3] = (trace_parameters[3] == "true")
|
112
|
+
|
113
|
+
trace_parameters += env.values_at(*B3_OPT_HEADERS) # always check flags
|
114
|
+
trace_parameters[4] = (trace_parameters[4] || default_flags).to_i
|
115
|
+
|
116
|
+
Trace::TraceId.new(*trace_parameters)
|
117
|
+
end
|
77
118
|
end
|
78
119
|
|
79
120
|
end
|
metadata
CHANGED
@@ -1,101 +1,130 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipkin-tracer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Franklin Hu
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-07-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: finagle-thrift
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
version: 1.2.0
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
34
20
|
type: :runtime
|
35
|
-
|
36
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
37
28
|
name: scribe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.4
|
34
|
+
type: :runtime
|
38
35
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
42
38
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 31
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 2
|
48
|
-
- 4
|
39
|
+
- !ruby/object:Gem::Version
|
49
40
|
version: 0.2.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
50
48
|
type: :runtime
|
51
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thin
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
52
97
|
description: Adds tracing instrumentation for ruby applications
|
53
|
-
email:
|
98
|
+
email:
|
54
99
|
- franklin@twitter.com
|
55
100
|
executables: []
|
56
|
-
|
57
101
|
extensions: []
|
58
|
-
|
59
102
|
extra_rdoc_files: []
|
60
|
-
|
61
|
-
files:
|
103
|
+
files:
|
62
104
|
- lib/zipkin-tracer/careless_scribe.rb
|
63
105
|
- lib/zipkin-tracer/version.rb
|
64
106
|
- lib/zipkin-tracer.rb
|
65
107
|
homepage: https://github.com/twitter/zipkin
|
66
108
|
licenses: []
|
67
|
-
|
109
|
+
metadata: {}
|
68
110
|
post_install_message:
|
69
111
|
rdoc_options: []
|
70
|
-
|
71
|
-
require_paths:
|
112
|
+
require_paths:
|
72
113
|
- lib
|
73
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
|
-
requirements:
|
85
|
-
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
hash: 17
|
88
|
-
segments:
|
89
|
-
- 1
|
90
|
-
- 3
|
91
|
-
- 5
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
92
123
|
version: 1.3.5
|
93
124
|
requirements: []
|
94
|
-
|
95
125
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 2.1.11
|
97
127
|
signing_key:
|
98
|
-
specification_version:
|
128
|
+
specification_version: 4
|
99
129
|
summary: Ruby tracing via Zipkin
|
100
130
|
test_files: []
|
101
|
-
|