zipkin-tracer 0.6.3 → 0.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzRlNmRmNWM4ZDlhMGVkNTZhZmUzMDQwNjA5MGZkODI2NTlhZmM3Yw==
4
+ YzJiNzAzYmI1YTJkNzc2YTViYzdhZjM5YzZjMmZkZTJiYjEyNWNhYQ==
5
5
  data.tar.gz: !binary |-
6
- Yzc4ZGJmOWQ3YjdmZDFjMDJlMGZlM2QxZTU5NzFiZDMxNDgyNTU5ZQ==
6
+ ZGQzMDkwYTdiODdlYTRhNjFkYWRjYmU4OTU4MWFiNjViNTRkYTI0Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDk0OTBhZjg2ZmZhZDY2YmE5MDE2YWViNDI5MDkxZjQzOWJlOGU3YmNjZmJj
10
- YTc4M2QyMzIyZTI4NTJhZmZkNDgyNDBjYTI1ODBkYzFjYTVhMDU5NjQ5NzZj
11
- ZjExYzVjMTFhNDdkZjVjNjIxZTBkZWRiOWM3N2JiZWUzZTEwNWI=
9
+ ODQ5NWQ0YzA1OTI2MjMyNWM3NGIwNTNlODZkOGVhY2I3OWMzOTJhOWFlZmMw
10
+ MTgzZjU3ODBlNTViNmMwMzYyOTE2ODYxNjY5ZjdjN2IwMTA3ZDk0NjRjZGIw
11
+ MjYzNjBhZWY4YzNjMmQyNjY1MWVjZTdiODdkYmFjMjRiNmUyNzU=
12
12
  data.tar.gz: !binary |-
13
- ZmZkMDIwMjcxMGQwNDRkZTZhNjczNzA0OGFiNzliZjUxZjRiMDM5NTkwM2Fj
14
- YmQzNDc3YzFhOTEwZDZkZGVmMjJiNGYzMmMwMGIyNDcxMGE2OTRkMmEyMDEz
15
- NWE3N2UyNjIwM2ZhMzQzYjQ1OTBhOTVlMGM2MzA4Y2VlYTY0ZWE=
13
+ Zjc4MzJmYTg1ODEzYWVmM2YyODA1ZTRjZGNiNWRmODA2MTlhYWY1MTc0OGQw
14
+ MDk3NzcxYTRjZTAwOTAyOTM1NDdmYjEwOWZkZGNkOGM5NTVmZmRjZTZlODQx
15
+ NmE3Y2ZiOGMxOTBmMGZhMDg4ODk4YjU0NTU4ODhkNTQwZDNjOTM=
@@ -1,35 +1,70 @@
1
1
  # Copyright 2012 Twitter Inc.
2
- #
2
+ #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
- #
6
+ #
7
7
  # http://www.apache.org/licenses/LICENSE-2.0
8
- #
8
+ #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- class CarelessScribe
16
- def initialize(scribe)
17
- @scribe = scribe
15
+ require 'sucker_punch'
16
+
17
+
18
+ module ScribeThrift
19
+ # This is here just for the monkey partching
20
+ class Client
21
+ # This method in the original class was both sending and receiving logs.
22
+ # The original class: https://github.com/twitter/scribe/blob/master/vendor/gen-rb/scribe.rb
23
+ # Receiving logs may take even several seconds, depending on the buffering of the collector.
24
+ # We are just sending and forgetting here, we do not really care about the result
25
+ def Log(messages)
26
+ send_Log(messages)
27
+ 0 # 0 means success , the original code called recv_Log()
28
+ end
18
29
  end
30
+ end
19
31
 
20
- def log(*args)
21
- @scribe.log(*args)
32
+ # SuckerPunch creates a queue and a thread pool to work on jobs on the queue
33
+ # calling perform adds the code to the queue
34
+ class AsyncScribe
35
+ include SuckerPunch::Job
36
+
37
+ PROTOCOL_TIMEOUT = 10 # If the timeout is low, the protocol will lose spans when collector is not fast enough
38
+ CATEGORY = 'ruby' # Thrift-client already uses this as default, seems to not affect anything
39
+ ADD_NEWLINES_TO_MESSAGES = true # True is the default in Thrift-client, seems a necessary internal hack
40
+
41
+ def perform(server_address, *args)
42
+ # May seem wasteful to open a new connection per each span but the way the scribe is done
43
+ # it is difficult to ensure there will be no threading issues unless we create here the connection
44
+ scribe = Scribe.new(server_address, CATEGORY, ADD_NEWLINES_TO_MESSAGES, timeout: PROTOCOL_TIMEOUT)
45
+ scribe.log(*args)
22
46
  rescue ThriftClient::NoServersAvailable, Thrift::Exception
23
47
  # I couldn't care less
24
48
  end
25
49
 
50
+ end
51
+
52
+ # Scribe which rescue thrift errors to avoid them to raise to the client
53
+ class CarelessScribe
54
+
55
+ def initialize(scribe_server_address)
56
+ @server_address = scribe_server_address
57
+ end
58
+
59
+ def log(*args)
60
+ AsyncScribe.new.async.perform(@server_address, *args)
61
+ end
62
+
26
63
  def batch(&block)
27
- @scribe.batch(&block)
64
+ yield #We just yield here
65
+ # the block finagle-thrift-1.4.1/lib/finagle-thrift/tracer.rb flush! method will call log also.
28
66
  rescue ThriftClient::NoServersAvailable, Thrift::Exception
29
67
  # I couldn't care less
30
68
  end
31
69
 
32
- def method_missing(name, *args)
33
- @scribe.send(name, *args)
34
- end
35
- end
70
+ end
@@ -36,23 +36,23 @@ module ZipkinTracer extend self
36
36
  config = Config.new(app, config)
37
37
 
38
38
  ::Trace.tracer = if config.using_scribe?
39
- scribe = config.scribe_server ? Scribe.new(config.scribe_server) : Scribe.new()
40
- ::Trace::ZipkinTracer.new(CarelessScribe.new(scribe), config.scribe_max_buffer)
39
+ ::Trace::ZipkinTracer.new(CarelessScribe.new(config.scribe_server), config.scribe_max_buffer)
41
40
  elsif config.using_kafka?
42
41
  kafkaTracer = ::Trace::ZipkinKafkaTracer.new
43
42
  kafkaTracer.connect(config.zookeeper)
44
43
  kafkaTracer
44
+ else
45
+ ::Trace::NullTracer.new
45
46
  end
46
- @config = config
47
+ ::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(config.service_name).with_port(config.service_port)
48
+ ::Trace.sample_rate=(config.sample_rate)
47
49
 
50
+ @config = config
48
51
  end
49
52
 
50
53
  def call(env)
51
54
  # skip certain requests
52
55
  return @app.call(env) if filtered?(env) || !routable_request?(env)
53
-
54
- ::Trace.default_endpoint = ::Trace.default_endpoint.with_service_name(@config.service_name).with_port(@config.service_port)
55
- ::Trace.sample_rate=(@config.sample_rate)
56
56
  whitelisted = force_sample?(env)
57
57
  id = get_or_create_trace_id(env, whitelisted) # note that this depends on the sample rate being set
58
58
  tracing_filter(id, env, whitelisted) { @app.call(env) }
@@ -84,22 +84,32 @@ module ZipkinTracer extend self
84
84
  def tracing_filter(trace_id, env, whitelisted=false)
85
85
  synchronize do
86
86
  ::Trace.push(trace_id)
87
- ::Trace.set_rpc_name(env["REQUEST_METHOD"]) # get/post and all that jazz
88
- ::Trace.record(::Trace::BinaryAnnotation.new("http.uri", env["PATH_INFO"], "STRING", ::Trace.default_endpoint))
87
+ #if called by a service, the caller already added the information
88
+ add_request_information(env) unless called_with_zipkin_headers?(env)
89
89
  ::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_RECV, ::Trace.default_endpoint))
90
90
  ::Trace.record(::Trace::Annotation.new('whitelisted', ::Trace.default_endpoint)) if whitelisted
91
91
  end
92
92
  status, headers, body = yield if block_given?
93
93
  ensure
94
94
  synchronize do
95
- ::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_SEND, ::Trace.default_endpoint))
96
95
  annotate(env, status, headers, body)
96
+ ::Trace.record(::Trace::Annotation.new(::Trace::Annotation::SERVER_SEND, ::Trace.default_endpoint))
97
97
  ::Trace.pop
98
98
  end
99
+ [status, headers, body]
99
100
  end
100
101
 
101
102
  private
102
103
 
104
+ def add_request_information(env)
105
+ ::Trace.set_rpc_name(env["REQUEST_METHOD"]) # get/post and all that jazz
106
+ ::Trace.record(::Trace::BinaryAnnotation.new("http.uri", env["PATH_INFO"], "STRING", ::Trace.default_endpoint))
107
+ end
108
+
109
+ def called_with_zipkin_headers?(env)
110
+ B3_REQUIRED_HEADERS.all? { |key| env.has_key?(key) }
111
+ end
112
+
103
113
  def synchronize(&block)
104
114
  @lock.synchronize do
105
115
  yield
@@ -111,7 +121,7 @@ module ZipkinTracer extend self
111
121
  end
112
122
 
113
123
  def get_or_create_trace_id(env, whitelisted, default_flags = ::Trace::Flags::EMPTY)
114
- trace_parameters = if B3_REQUIRED_HEADERS.all? { |key| env.has_key?(key) }
124
+ trace_parameters = if called_with_zipkin_headers?(env)
115
125
  env.values_at(*B3_REQUIRED_HEADERS)
116
126
  else
117
127
  new_id = Trace.generate_id
@@ -12,6 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  module ZipkinTracer
15
- VERSION = "0.6.3"
15
+ VERSION = "0.7"
16
16
  end
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipkin-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-20 00:00:00.000000000 Z
13
+ date: 2015-10-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: finagle-thrift
@@ -54,6 +54,20 @@ dependencies:
54
54
  - - ~>
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.3'
57
+ - !ruby/object:Gem::Dependency
58
+ name: sucker_punch
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '1.0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '1.0'
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: rspec
59
73
  requirement: !ruby/object:Gem::Requirement