zipkin-tracer 0.21.2 → 0.22.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: fc6bb6d03809b2c58f53130d3471bc875cc8b99b
4
- data.tar.gz: 952bcafa2c2ebdce4d26f49664e6b8cee9af4ce6
3
+ metadata.gz: 9e370dd751832be287e591eb227b01384f939a87
4
+ data.tar.gz: 1c14cb00ffa226c6f301130e543ac6bd4e4b81a4
5
5
  SHA512:
6
- metadata.gz: 38cbbe277215a92f7c1c01b0f727e20ae1d765e00c3c3364d7da898294725e2dd3fd7f23fe3f31743ed46fa910619e1dc082d96b4afbc0b5ba0eb212ca4f3365
7
- data.tar.gz: 4913f1f54e4eea4f079c5bb4bd6002c838fd5ab439ed9ecb8de5cbb7a424916c28a24ea1cefdec0a2630bf9b359ee3e42b859f19d00a7f96a73b6598ec76e596
6
+ metadata.gz: 5403b8f35d8ae2c2b63e84b8b205bd89f54790c2ccada5e60e83c6d5f64cdd3315b28a765149d47269327f9bca1d07229dfb59c248b7959032fc5e6d4bad47c2
7
+ data.tar.gz: bc38a24c9a4dcc616f662bf9009009abd437e967d519e93b68d9a015a3a1fb08627755d7a396d710726d96b4c185c03d69cb4b6917e58ae6b0a0cfd3a81e6a80
@@ -1,5 +1,6 @@
1
1
  require 'logger'
2
2
  require 'zipkin-tracer/application'
3
+ require 'zipkin-tracer/rack/zipkin-tracer'
3
4
 
4
5
  module ZipkinTracer
5
6
  # Configuration of this gem. It reads the configuration and provides default values
@@ -7,7 +8,7 @@ module ZipkinTracer
7
8
  attr_reader :service_name, :service_port, :json_api_host,
8
9
  :zookeeper, :sample_rate, :logger, :log_tracing,
9
10
  :annotate_plugin, :filter_plugin, :whitelist_plugin,
10
- :sampled_as_boolean
11
+ :sampled_as_boolean, :record_on_server_receive
11
12
 
12
13
  def initialize(app, config_hash)
13
14
  config = config_hash || Application.config(app)
@@ -30,7 +31,6 @@ module ZipkinTracer
30
31
  # A block of code which can be called to force sampling. Forces sampling if returns true
31
32
  @whitelist_plugin = config[:whitelist_plugin]
32
33
  @logger = Application.logger
33
- @log_tracing = config[:log_tracing] # Was the logger in fact setup by the client?
34
34
  # Was the logger in fact setup by the client?
35
35
  @log_tracing = config[:log_tracing]
36
36
  # When set to false, it uses 1/0 in the 'X-B3-Sampled' header, else uses true/false
@@ -39,6 +39,9 @@ module ZipkinTracer
39
39
  if @sampled_as_boolean
40
40
  @logger && @logger.warn("Using a boolean in the Sampled header is deprecated. Consider setting sampled_as_boolean to false")
41
41
  end
42
+ # Record the given tags on server receive, even if the zipkin headers were present in the incoming request?
43
+ @record_on_server_receive = parse_tags(config[:record_on_server_receive])
44
+
42
45
  Trace.sample_rate = @sample_rate
43
46
  end
44
47
 
@@ -62,10 +65,17 @@ module ZipkinTracer
62
65
  sampled_as_boolean: true
63
66
  }
64
67
 
68
+ def parse_tags(tag_names)
69
+ return {} unless present?(tag_names)
70
+ names = tag_names.split(",").map(&:strip)
71
+ (ZipkinTracer::RackHandler::DEFAULT_SERVER_RECV_TAGS.keys & names).each_with_object({}) do |name, tags|
72
+ tags[name] = ZipkinTracer::RackHandler::DEFAULT_SERVER_RECV_TAGS[name]
73
+ end
74
+ end
75
+
65
76
  def present?(str)
66
77
  return false if str.nil?
67
78
  !!(/\A[[:space:]]*\z/ !~ str)
68
79
  end
69
-
70
80
  end
71
81
  end
@@ -1,3 +1,4 @@
1
+ require 'rack'
1
2
  require 'finagle-thrift/trace'
2
3
  require 'finagle-thrift/tracer'
3
4
  require 'zipkin-tracer/config'
@@ -8,6 +9,14 @@ module ZipkinTracer
8
9
  # This middleware reads Zipkin headers from the request and sets/creates a Trace.id usable by the rest of the app
9
10
  # It will also send the trace to the Zipkin service using one of the methods configured.
10
11
  class RackHandler
12
+ # the following constants are defined only from rack 1.6
13
+ PATH_INFO = Rack::PATH_INFO rescue 'PATH_INFO'.freeze
14
+ REQUEST_METHOD = Rack::REQUEST_METHOD rescue 'REQUEST_METHOD'.freeze
15
+
16
+ DEFAULT_SERVER_RECV_TAGS = {
17
+ Trace::BinaryAnnotation::PATH => PATH_INFO
18
+ }.freeze
19
+
11
20
  def initialize(app, config = nil)
12
21
  @app = app
13
22
  @config = Config.new(app, config).freeze
@@ -21,7 +30,7 @@ module ZipkinTracer
21
30
  if !trace_id.sampled? || !routable_request?(env)
22
31
  @app.call(env)
23
32
  else
24
- @tracer.with_new_span(trace_id, env['REQUEST_METHOD'].to_s.downcase) do |span|
33
+ @tracer.with_new_span(trace_id, env[REQUEST_METHOD].to_s.downcase) do |span|
25
34
  trace!(span, zipkin_env) { @app.call(env) }
26
35
  end
27
36
  end
@@ -31,7 +40,7 @@ module ZipkinTracer
31
40
  private
32
41
 
33
42
  def routable_request?(env)
34
- Application.routable_request?(env['PATH_INFO'], env['REQUEST_METHOD'])
43
+ Application.routable_request?(env[PATH_INFO], env[REQUEST_METHOD])
35
44
  end
36
45
 
37
46
  def annotate_plugin(env, status, response_headers, response_body)
@@ -39,8 +48,7 @@ module ZipkinTracer
39
48
  end
40
49
 
41
50
  def trace!(span, zipkin_env, &block)
42
- # if called by a service, the caller already added the information
43
- trace_request_information(span, zipkin_env.env) unless zipkin_env.called_with_zipkin_headers?
51
+ trace_request_information(span, zipkin_env)
44
52
  span.record(Trace::Annotation::SERVER_RECV)
45
53
  span.record('whitelisted') if zipkin_env.force_sample?
46
54
  status, headers, body = yield
@@ -49,8 +57,16 @@ module ZipkinTracer
49
57
  span.record(Trace::Annotation::SERVER_SEND)
50
58
  end
51
59
 
52
- def trace_request_information(span, env)
53
- span.record_tag(Trace::BinaryAnnotation::PATH, env['PATH_INFO'])
60
+ def trace_request_information(span, zipkin_env)
61
+ tags = if !@config.record_on_server_receive.empty?
62
+ # if the user specified tags to record on server receive, use these no matter what
63
+ @config.record_on_server_receive
64
+ elsif !zipkin_env.called_with_zipkin_headers?
65
+ # if the request comes from a non zipkin-enabled source record the default tags
66
+ DEFAULT_SERVER_RECV_TAGS
67
+ end
68
+ return if tags.nil?
69
+ tags.each { |annotation_key, env_key| span.record_tag(annotation_key, zipkin_env.env[env_key]) }
54
70
  end
55
71
  end
56
72
  end
@@ -1,3 +1,3 @@
1
1
  module ZipkinTracer
2
- VERSION = '0.21.2'.freeze
2
+ VERSION = '0.22.0'.freeze
3
3
  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.21.2
4
+ version: 0.22.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-03-30 00:00:00.000000000 Z
16
+ date: 2017-04-26 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: faraday
@@ -147,14 +147,14 @@ dependencies:
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '1.22'
150
+ version: '3.0'
151
151
  type: :development
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
154
154
  requirements:
155
155
  - - "~>"
156
156
  - !ruby/object:Gem::Version
157
- version: '1.22'
157
+ version: '3.0'
158
158
  description: Adds tracing instrumentation for ruby applications
159
159
  email:
160
160
  - franklin@twitter.com