zipkin-tracer 0.25.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 056a3c8673074ba57da8f43ba8c894bfc64a8c60
4
- data.tar.gz: 1c460f925e75c449a4453336a7a3fca17fd04068
3
+ metadata.gz: 5f3c839257069386e2ee919af9359519db3d601d
4
+ data.tar.gz: c3a5348a47ffcf3823ef079e7bf59f83bd73cf7a
5
5
  SHA512:
6
- metadata.gz: e3b25784f7ef65ab5cce860776558e493ae15da118be7c5c9dcc8c271953d986290cd750427eab6595ce19df3c06f21e7fd3aa8b063f3b3a5604090144223b39
7
- data.tar.gz: 8a41195765ba46d1a8218a7d75f2f6acc7488470110134a489f628a4f8602cd791ef44d42e7a21afcfc9d7191597d8fb2a478e2f5da6e02fff1a905a34796815
6
+ metadata.gz: 7a1bd29f82318ff6391b9575701ac7a65831147b87dc7c434e7930ad77fb569e87f8485480ff1f6400cdd55ac1320a2a055179001a3d9aa0a5ac27e5a7b743f6
7
+ data.tar.gz: fd4800c057745f5ae23bae36dcb34655fc612cb7aa34d7cbd5cf77718c74c09f2debd1745f3c2e158ddd09ec5f219eba8f37ae5f2464af7ddf25dd06353fb1ae
data/lib/zipkin-tracer.rb CHANGED
@@ -2,6 +2,7 @@ require 'finagle-thrift'
2
2
  require 'base64' #Bug in finagle. They should be requiring this: finagle-thrift-1.4.1/lib/finagle-thrift/tracer.rb:115
3
3
  require 'zipkin-tracer/trace'
4
4
  require 'zipkin-tracer/rack/zipkin-tracer'
5
+ require 'zipkin-tracer/sidekiq/middleware'
5
6
  require 'zipkin-tracer/trace_client'
6
7
  require 'zipkin-tracer/trace_container'
7
8
  require 'zipkin-tracer/trace_generator'
@@ -0,0 +1,47 @@
1
+ module ZipkinTracer
2
+ module Sidekiq
3
+ class Middleware
4
+ attr_reader :config, :tracer, :traceable_workers
5
+
6
+ def initialize(config)
7
+ @config = Config.new(nil, config).freeze
8
+ @tracer = TracerFactory.new.tracer(@config)
9
+ @traceable_workers = config.fetch(:traceable_workers, [])
10
+ end
11
+
12
+ def call(worker, job, queue, &block)
13
+ return block.call unless traceable_worker?(worker)
14
+
15
+ trace(worker, job, queue, &block)
16
+ end
17
+
18
+ private
19
+
20
+ def traceable_worker?(worker)
21
+ traceable_workers.include?(:all) || traceable_workers.include?(worker_name(worker))
22
+ end
23
+
24
+ def trace(worker, job, queue, &block)
25
+ trace_id = TraceGenerator.new.next_trace_id
26
+ span_name = worker_name(worker)
27
+
28
+ result = TraceContainer.with_trace_id(trace_id) do
29
+ if trace_id.sampled?
30
+ tracer.with_new_span(trace_id, span_name) do
31
+ result = block.call
32
+ end
33
+ else
34
+ result = block.call
35
+ end
36
+ end
37
+
38
+ tracer.flush!
39
+ result
40
+ end
41
+
42
+ def worker_name(worker)
43
+ worker.class.to_s.to_sym
44
+ end
45
+ end
46
+ end
47
+ end
@@ -89,6 +89,10 @@ module Trace
89
89
  record_tag(BinaryAnnotation::LOCAL_COMPONENT, value)
90
90
  end
91
91
 
92
+ def has_parent_span?
93
+ !@span_id.parent_id.nil?
94
+ end
95
+
92
96
  private
93
97
 
94
98
  UNKNOWN_DURATION = 0 # mark duration was not set
@@ -1,3 +1,3 @@
1
1
  module ZipkinTracer
2
- VERSION = '0.25.0'.freeze
2
+ VERSION = '0.26.0'.freeze
3
3
  end
@@ -23,7 +23,12 @@ module Trace
23
23
 
24
24
  def end_span(span)
25
25
  span.close
26
- if span.annotations.any?{ |ann| ann.value == Annotation::SERVER_SEND }
26
+ # If in a thread not handling incoming http requests, it will not have Annotation::SERVER_SEND, so the span
27
+ # will never be flushed and will cause memory leak.
28
+ # It will have CLIENT_SEND and CLIENT_RECV if the thread sends out http requests, so use CLIENT_RECV as the sign
29
+ # to flush the span.
30
+ # If no parent span, then current span needs to flush when it ends.
31
+ if !span.has_parent_span? || span.annotations.any? { |ann| ann.value == Annotation::SERVER_SEND }
27
32
  flush!
28
33
  reset
29
34
  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.25.0
4
+ version: 0.26.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: 2017-06-29 00:00:00.000000000 Z
16
+ date: 2017-08-07 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: faraday
@@ -175,6 +175,7 @@ files:
175
175
  - lib/zipkin-tracer/hostname_resolver.rb
176
176
  - lib/zipkin-tracer/rack/zipkin-tracer.rb
177
177
  - lib/zipkin-tracer/rack/zipkin_env.rb
178
+ - lib/zipkin-tracer/sidekiq/middleware.rb
178
179
  - lib/zipkin-tracer/trace.rb
179
180
  - lib/zipkin-tracer/trace_client.rb
180
181
  - lib/zipkin-tracer/trace_container.rb