zipkin-tracer 0.0.1

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.
@@ -0,0 +1,35 @@
1
+ # Copyright 2012 Twitter Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ class CarelessScribe
16
+ def initialize(scribe)
17
+ @scribe = scribe
18
+ end
19
+
20
+ def log(*args)
21
+ @scribe.log(*args)
22
+ rescue ThriftClient::NoServersAvailable, Thrift::Exception
23
+ # I couldn't care less
24
+ end
25
+
26
+ def batch(&block)
27
+ @scribe.batch(&block)
28
+ rescue ThriftClient::NoServersAvailable, Thrift::Exception
29
+ # I couldn't care less
30
+ end
31
+
32
+ def method_missing(name, *args)
33
+ @scribe.send(name, *args)
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright 2012 Twitter Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ module ZipkinTracer
15
+ VERSION = "0.0.1"
16
+ end
17
+
@@ -0,0 +1,79 @@
1
+ # Copyright 2012 Twitter Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'finagle-thrift'
15
+ require 'finagle-thrift/trace'
16
+ require 'scribe'
17
+
18
+ require 'zipkin-tracer/careless_scribe'
19
+
20
+ module ZipkinTracer extend self
21
+
22
+ class RackHandler
23
+ def initialize(app)
24
+ @app = app
25
+ @lock = Mutex.new
26
+
27
+ config = app.config.zipkin_tracer
28
+ @service_name = config[:service_name]
29
+ @service_port = config[:service_port]
30
+
31
+ scribe =
32
+ if config[:scribe_server] then
33
+ Scribe.new(config[:scribe_server])
34
+ else
35
+ Scribe.new()
36
+ end
37
+
38
+ scribe_max_buffer =
39
+ if config[:scribe_max_buffer] then
40
+ config[:scribe_max_buffer]
41
+ else
42
+ 10
43
+ end
44
+
45
+ @sample_rate =
46
+ if config[:sample_rate] then
47
+ config[:sample_rate]
48
+ else
49
+ 0.1
50
+ end
51
+
52
+ ::Trace.tracer = ::Trace::ZipkinTracer.new(CarelessScribe.new(scribe), scribe_max_buffer)
53
+ end
54
+
55
+ def call(env)
56
+ id = ::Trace::TraceId.new(::Trace.generate_id, nil, ::Trace.generate_id, true)
57
+ ::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@service_name).with_port(@service_port)
58
+ ::Trace.sample_rate=(@sample_rate)
59
+ tracing_filter(id, env) { @app.call(env) }
60
+ end
61
+
62
+ private
63
+ def tracing_filter(trace_id, env)
64
+ @lock.synchronize do
65
+ ::Trace.push(trace_id)
66
+ ::Trace.set_rpc_name(env["REQUEST_METHOD"]) # get/post and all that jazz
67
+ ::Trace.record(::Trace::BinaryAnnotation.new("http.uri", env["PATH_INFO"], "STRING", ::Trace.default_endpoint))
68
+ ::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_RECV, ::Trace.default_endpoint))
69
+ end
70
+ yield if block_given?
71
+ ensure
72
+ @lock.synchronize do
73
+ ::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_SEND, ::Trace.default_endpoint))
74
+ ::Trace.pop
75
+ end
76
+ end
77
+ end
78
+
79
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zipkin-tracer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Franklin Hu
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-12 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: finagle-thrift
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 31
29
+ segments:
30
+ - 1
31
+ - 2
32
+ - 0
33
+ version: 1.2.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: scribe
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 31
45
+ segments:
46
+ - 0
47
+ - 2
48
+ - 4
49
+ version: 0.2.4
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: Adds tracing instrumentation for ruby applications
53
+ email:
54
+ - franklin@twitter.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - lib/zipkin-tracer/careless_scribe.rb
63
+ - lib/zipkin-tracer/version.rb
64
+ - lib/zipkin-tracer.rb
65
+ homepage: https://github.com/twitter/zipkin
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
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
92
+ version: 1.3.5
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.15
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Ruby tracing via Zipkin
100
+ test_files: []
101
+