zipkin-tracer 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzEzZmRjNmE5ZjhhMGRiY2EyOWFiNzIxZjczZjE0MDlkOWJkY2MyNQ==
4
+ MDAzYzIxYWEzM2Y5NTM1OWJiMWQ5ODkwODVjY2U3YmFjMjkxNjY0Nw==
5
5
  data.tar.gz: !binary |-
6
- ZDg5N2IyOGViYTVhODc3OWNlM2FjNGZmOTg3YjI5NjE0OGVlN2IwOA==
6
+ NTJlNzYxMzZiZGJkOGU5Y2FhM2Y4OWMzNjIxNzU4NjBjYWVhMjFkNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjBlMDNiNzE3Y2EzYWZmNjU1MGY5Yzg2N2RjZTA1YmFiZWIzYjEzZDU0MDdh
10
- MjExNGJkZjBiZjU3MjlhYzQwMTc4YWY1YjZhMWI5ZTc0Y2ViYjQxMzgwYWJk
11
- NjIzN2Y0YzQ5ZDQ4MWY3ZjA4OTFlM2M5MzQxYzk5YzdiMzZmNjg=
9
+ NTg1MGVmMTJjM2NlMWE0YTlmZmNjYjEyOWJkOWU0MWYyMjdhNjU3MWEwOTcx
10
+ YzU5N2ZlNzQyOTE4Yjg1MjAzOTJmN2Q2NWY1YTA4OTZmOTZmNzZlNjA5MzRk
11
+ NDgyMjFjNDJhNWFiMDc4ZmM2OWIxNTVhNGRiZDA1NDE5NWJlYTI=
12
12
  data.tar.gz: !binary |-
13
- OTFlZDAwZGZjNDE2ZGM1NmZmOGJlM2ZkNTQ1N2M2YTc5MzIwZjM4MDUxYjgz
14
- YWY1MGZiYjY1OWVjNjcyNWJjNzE2ODM5MjhkNTYwMjhmYjgwNjcxNDI2YjYw
15
- ZmQ4MTQ3MTIxYTMxNTA3Mzg2MzQ5ZTczYWUwMjBmMWRiNWUxZjE=
13
+ OGJjZDQwNmQwOTgwZDJlZDUzMjFmMTdjNDI1ZGIzNWRlYzA4YzE3NTUzZTg5
14
+ ZDE0Y2RmNGFmMjMwYzZkZjBmMzI4M2NlZmIwNGNlM2VmOTNlYWY3MTdkMGZh
15
+ NTIwM2EwMjQwYmU4OTQ1YmZkYjBmYWI5YTkyOTFjNTEwMjBhYmU=
@@ -4,8 +4,8 @@ require 'zipkin-tracer/application'
4
4
  module ZipkinTracer
5
5
  # Configuration of this gem. It reads the configuration and provides default values
6
6
  class Config
7
- attr_reader :service_name, :service_port, :json_api_host, :traces_buffer,
8
- :scribe_server, :zookeeper, :sample_rate, :scribe_max_buffer, :annotate_plugin,
7
+ attr_reader :service_name, :service_port, :json_api_host,
8
+ :scribe_server, :zookeeper, :sample_rate, :annotate_plugin,
9
9
  :filter_plugin, :whitelist_plugin, :logger
10
10
 
11
11
  def initialize(app, config_hash)
@@ -13,11 +13,9 @@ module ZipkinTracer
13
13
  @service_name = config[:service_name]
14
14
  @service_port = config[:service_port] || DEFAULTS[:service_port]
15
15
  @json_api_host = config[:json_api_host]
16
- @traces_buffer = config[:traces_buffer] || DEFAULTS[:traces_buffer]
17
16
  @scribe_server = config[:scribe_server]
18
17
  @zookeeper = config[:zookeeper]
19
18
  @sample_rate = config[:sample_rate] || DEFAULTS[:sample_rate]
20
- @scribe_max_buffer = config[:scribe_max_buffer] || DEFAULTS[:scribe_max_buffer]
21
19
  @annotate_plugin = config[:annotate_plugin] # call for trace annotation
22
20
  @filter_plugin = config[:filter_plugin] # skip tracing if returns false
23
21
  @whitelist_plugin = config[:whitelist_plugin] # force sampling if returns true
@@ -39,8 +37,6 @@ module ZipkinTracer
39
37
  private
40
38
 
41
39
  DEFAULTS = {
42
- traces_buffer: 100,
43
- scribe_max_buffer: 10,
44
40
  sample_rate: 0.1,
45
41
  service_port: 80
46
42
  }
@@ -18,19 +18,28 @@ module Trace
18
18
  # A span may contain many annotations
19
19
  # This class is defined in finagle-thrift. We are adding extra methods here
20
20
  class Span
21
- attr_reader :size
22
- attr_accessor :timestamp, :duration
21
+ def initialize(name, span_id)
22
+ @name = name
23
+ @span_id = span_id
24
+ @annotations = []
25
+ @binary_annotations = []
26
+ @debug = span_id.debug?
27
+ @timestamp = to_microseconds(Time.now)
28
+ @duration = UNKNOWN_DURATION
29
+ end
30
+
31
+ def close
32
+ @duration = to_microseconds(Time.now) - @timestamp
33
+ end
23
34
 
24
35
  # We record information into spans, then we send these spans to zipkin
25
36
  def record(annotation)
26
- @size ||= 0
27
37
  case annotation
28
38
  when BinaryAnnotation
29
39
  binary_annotations << annotation
30
40
  when Annotation
31
41
  annotations << annotation
32
42
  end
33
- @size = @size + 1
34
43
  end
35
44
 
36
45
  def to_h
@@ -41,11 +50,19 @@ module Trace
41
50
  parentId: @span_id.parent_id.nil? ? nil : @span_id.parent_id.to_s,
42
51
  annotations: @annotations.map!(&:to_h),
43
52
  binaryAnnotations: @binary_annotations.map!(&:to_h),
44
- timestamp: timestamp,
45
- duration: duration,
53
+ timestamp: @timestamp,
54
+ duration: @duration,
46
55
  debug: @debug
47
56
  }
48
57
  end
58
+
59
+ private
60
+
61
+ UNKNOWN_DURATION = 0 # mark duration was not set
62
+
63
+ def to_microseconds(time)
64
+ (time.to_f * 1_000_000).to_i
65
+ end
49
66
  end
50
67
 
51
68
  # This class is defined in finagle-thrift. We are adding extra methods here
@@ -4,20 +4,23 @@ module ZipkinTracer
4
4
  STRING_TYPE = 'STRING'.freeze
5
5
 
6
6
  def self.local_component_span(local_component_value, &block)
7
- if block_given?
8
- client = self.new(LOCAL_COMPONENT, &block)
9
- client.record_local_component local_component_value
10
- end
7
+ client = self.new
8
+ client.trace(local_component_value, &block)
11
9
  end
12
10
 
13
- def initialize(name, &block)
11
+ def trace(local_component_value, &block)
12
+ raise ArgumentError, "no block given" unless block
13
+
14
14
  @trace_id = Trace.id.next_id
15
+ result = nil
15
16
  Trace.with_trace_id(@trace_id) do
16
- Trace.tracer.with_new_span(@trace_id, name) do |span|
17
+ Trace.tracer.with_new_span(@trace_id, LOCAL_COMPONENT) do |span|
17
18
  @span = span
18
- block.call(self)
19
+ result = block.call(self)
20
+ record_local_component local_component_value
19
21
  end
20
22
  end
23
+ result
21
24
  end
22
25
 
23
26
  def record(key)
@@ -6,11 +6,11 @@ module ZipkinTracer
6
6
  tracer = case adapter
7
7
  when :json
8
8
  require 'zipkin-tracer/zipkin_json_tracer'
9
- options = { json_api_host: config.json_api_host, traces_buffer: config.traces_buffer, logger: config.logger }
9
+ options = { json_api_host: config.json_api_host, logger: config.logger }
10
10
  Trace::ZipkinJsonTracer.new(options)
11
11
  when :scribe
12
12
  require 'zipkin-tracer/zipkin_scribe_tracer'
13
- Trace::ScribeTracer.new(scribe_server: config.scribe_server, traces_buffer: config.scribe_max_buffer)
13
+ Trace::ScribeTracer.new(scribe_server: config.scribe_server)
14
14
  when :kafka
15
15
  require 'zipkin-tracer/zipkin_kafka_tracer'
16
16
  Trace::ZipkinKafkaTracer.new(zookeepers: config.zookeeper)
@@ -12,5 +12,5 @@
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.12.1"
15
+ VERSION = "0.13.0"
16
16
  end
@@ -12,7 +12,6 @@ module Trace
12
12
  @topic = options[:topic] || DEFAULT_KAFKA_TOPIC
13
13
  broker_ids = Hermann::Discovery::Zookeeper.new(options[:zookeepers]).get_brokers
14
14
  @producer = Hermann::Producer.new(nil, broker_ids)
15
- options[:traces_buffer] ||= 1 # Default in Kafka is sending as soon as possible. No buffer.
16
15
  super(options)
17
16
  end
18
17
 
@@ -11,31 +11,27 @@ module Trace
11
11
 
12
12
  def initialize(options={})
13
13
  @options = options
14
- @traces_buffer = options[:traces_buffer] || raise(ArgumentError, 'A proper buffer must be setup for the Zipkin tracer')
15
14
  reset
16
15
  end
17
16
 
18
17
  def with_new_span(trace_id, name)
19
18
  span = start_span(trace_id, name)
20
- start_time = Time.now
21
- span.timestamp = to_microseconds(start_time)
22
19
  result = yield span
23
- span.duration = to_microseconds(Time.now - start_time)
24
- may_flush(span)
20
+ end_span(span)
25
21
  result
26
22
  end
27
23
 
28
- def may_flush(span)
29
- size = spans.values.map(&:size).map(&:to_i).inject(:+) || 0
30
- if size >= @traces_buffer || span.annotations.any?{ |ann| ann.value == Annotation::SERVER_SEND }
24
+ def end_span(span)
25
+ span.close
26
+ if span.annotations.any?{ |ann| ann.value == Annotation::SERVER_SEND }
31
27
  flush!
32
28
  reset
33
29
  end
34
30
  end
35
31
 
36
32
  def start_span(trace_id, name)
37
- span = get_span_for_id(trace_id)
38
- span.name = name
33
+ span = Span.new(name, trace_id)
34
+ store_span(trace_id, span)
39
35
  span
40
36
  end
41
37
 
@@ -45,21 +41,19 @@ module Trace
45
41
 
46
42
  private
47
43
 
44
+ THREAD_KEY = :zipkin_spans
45
+
48
46
  def spans
49
- Thread.current[:zipkin_spans] ||= {}
47
+ Thread.current[THREAD_KEY] ||= {}
50
48
  end
51
49
 
52
- def get_span_for_id(id)
53
- key = id.span_id.to_s
54
- spans[key] ||= Span.new("", id)
50
+ def store_span(id, span)
51
+ spans[id.span_id.to_s] = span
55
52
  end
56
53
 
57
54
  def reset
58
- Thread.current[:zipkin_spans] = {}
55
+ Thread.current[THREAD_KEY] = {}
59
56
  end
60
57
 
61
- def to_microseconds(time)
62
- (time.to_f * 1_000_000).to_i
63
- end
64
58
  end
65
59
  end
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.12.1
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2016-02-03 00:00:00.000000000 Z
16
+ date: 2016-02-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: faraday