zipkin-tracer 0.40.1 → 0.41.0
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -0
- data/lib/zipkin-tracer.rb +1 -0
- data/lib/zipkin-tracer/config.rb +7 -2
- data/lib/zipkin-tracer/excon/zipkin-tracer.rb +3 -14
- data/lib/zipkin-tracer/faraday/zipkin-tracer.rb +3 -13
- data/lib/zipkin-tracer/trace.rb +1 -1
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer/zipkin_b3_header_helper.rb +30 -0
- data/lib/zipkin-tracer/zipkin_b3_single_header_format.rb +12 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe7fb284e2e5c8aef9203ab72d41403481835e5def3b07d847e80d21ed88a653
|
4
|
+
data.tar.gz: d4e8dedf195a458910af20a913f9c29256df653056cd848e6a00140be212a5ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8212bd6eec326a0066b5a9074a0567efd92f7ad5bbad9f88a5d7ecc0d5a607f25aaa96f9fba829fdc574c5fefb9e726763fd4a838f8551d35e744620c07e50a
|
7
|
+
data.tar.gz: b7f334ab931fdc97d379ed46d199d54860dfbaf7413afa5ade8c99a9c048552338f6d3655849e6855783b54d08ef6231804368271fd79672d63e654c88371ee5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,7 @@ use ZipkinTracer::RackHandler, config
|
|
24
24
|
* `:trace_id_128bit` - When set to true, high 8-bytes will be prepended to trace_id. The upper 4-bytes are epoch seconds and the lower 4-bytes are random. This makes it convertible to Amazon X-Ray trace ID format v1. (See http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html)
|
25
25
|
* `:async` - By default senders will flush traces asynchronously. Set to `false` to make that process synchronous. Only supported by the HTTP, RabbitMQ, and SQS senders.
|
26
26
|
* `:logger` - The default logger for Rails apps is `Rails.logger`, else it is `STDOUT`. Use this option to pass a custom logger.
|
27
|
+
* `:write_b3_single_format` - When set to true, only writes a single b3 header for outbound propagation.
|
27
28
|
|
28
29
|
#### Sender specific
|
29
30
|
* `:json_api_host` - Hostname with protocol of a zipkin api instance (e.g. `https://zipkin.example.com`) to use the HTTP sender
|
data/lib/zipkin-tracer.rb
CHANGED
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -8,7 +8,7 @@ module ZipkinTracer
|
|
8
8
|
attr_reader :service_name, :sample_rate, :sampled_as_boolean, :trace_id_128bit, :async, :logger,
|
9
9
|
:json_api_host, :zookeeper, :kafka_producer, :kafka_topic, :sqs_queue_name, :sqs_region, :log_tracing,
|
10
10
|
:annotate_plugin, :filter_plugin, :whitelist_plugin, :rabbit_mq_connection, :rabbit_mq_exchange,
|
11
|
-
:rabbit_mq_routing_key
|
11
|
+
:rabbit_mq_routing_key, :write_b3_single_format
|
12
12
|
|
13
13
|
def initialize(app, config_hash)
|
14
14
|
config = config_hash || Application.config(app)
|
@@ -53,9 +53,13 @@ module ZipkinTracer
|
|
53
53
|
# This makes it convertible to Amazon X-Ray trace ID format v1.
|
54
54
|
# (See http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html)
|
55
55
|
@trace_id_128bit = config[:trace_id_128bit].nil? ? DEFAULTS[:trace_id_128bit] : config[:trace_id_128bit]
|
56
|
+
# When set to true, only writes a single b3 header for outbound propagation.
|
57
|
+
@write_b3_single_format =
|
58
|
+
config[:write_b3_single_format].nil? ? DEFAULTS[:write_b3_single_format] : config[:write_b3_single_format]
|
56
59
|
|
57
60
|
Trace.sample_rate = @sample_rate
|
58
61
|
Trace.trace_id_128bit = @trace_id_128bit
|
62
|
+
Trace.write_b3_single_format = @write_b3_single_format
|
59
63
|
|
60
64
|
Trace.default_endpoint = Trace::Endpoint.local_endpoint(
|
61
65
|
domain_service_name(@service_name)
|
@@ -91,7 +95,8 @@ module ZipkinTracer
|
|
91
95
|
DEFAULTS = {
|
92
96
|
sample_rate: 0.1,
|
93
97
|
sampled_as_boolean: true,
|
94
|
-
trace_id_128bit: false
|
98
|
+
trace_id_128bit: false,
|
99
|
+
write_b3_single_format: false
|
95
100
|
}
|
96
101
|
|
97
102
|
def present?(str)
|
@@ -3,6 +3,8 @@ require 'excon'
|
|
3
3
|
|
4
4
|
module ZipkinTracer
|
5
5
|
class ExconHandler < Excon::Middleware::Base
|
6
|
+
include B3HeaderHelper
|
7
|
+
|
6
8
|
def initialize(_)
|
7
9
|
super
|
8
10
|
end
|
@@ -15,10 +17,7 @@ module ZipkinTracer
|
|
15
17
|
trace_id = TraceGenerator.new.next_trace_id
|
16
18
|
|
17
19
|
TraceContainer.with_trace_id(trace_id) do
|
18
|
-
|
19
|
-
datum[:headers][header] = trace_id.send(method).to_s
|
20
|
-
end
|
21
|
-
|
20
|
+
set_b3_header(datum[:headers], trace_id)
|
22
21
|
trace!(datum, trace_id) if Trace.tracer && trace_id.sampled?
|
23
22
|
end
|
24
23
|
|
@@ -36,16 +35,6 @@ module ZipkinTracer
|
|
36
35
|
|
37
36
|
private
|
38
37
|
|
39
|
-
def b3_headers
|
40
|
-
{
|
41
|
-
trace_id: 'X-B3-TraceId',
|
42
|
-
parent_id: 'X-B3-ParentSpanId',
|
43
|
-
span_id: 'X-B3-SpanId',
|
44
|
-
sampled: 'X-B3-Sampled',
|
45
|
-
flags: 'X-B3-Flags'
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
38
|
def remote_endpoint(url, service_name)
|
50
39
|
Trace::Endpoint.remote_endpoint(url, service_name) # The endpoint we are calling.
|
51
40
|
end
|
@@ -4,6 +4,8 @@ require 'uri'
|
|
4
4
|
module ZipkinTracer
|
5
5
|
# Faraday middleware. It will add CR/CS annotations to outgoing connections done by Faraday
|
6
6
|
class FaradayHandler < ::Faraday::Middleware
|
7
|
+
include B3HeaderHelper
|
8
|
+
|
7
9
|
def initialize(app, service_name = nil)
|
8
10
|
@app = app
|
9
11
|
@service_name = service_name
|
@@ -12,9 +14,7 @@ module ZipkinTracer
|
|
12
14
|
def call(env)
|
13
15
|
trace_id = TraceGenerator.new.next_trace_id
|
14
16
|
TraceContainer.with_trace_id(trace_id) do
|
15
|
-
|
16
|
-
env[:request_headers][header] = trace_id.send(method).to_s
|
17
|
-
end
|
17
|
+
set_b3_header(env[:request_headers], trace_id)
|
18
18
|
if Trace.tracer && trace_id.sampled?
|
19
19
|
trace!(env, trace_id)
|
20
20
|
else
|
@@ -25,16 +25,6 @@ module ZipkinTracer
|
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
def b3_headers
|
29
|
-
{
|
30
|
-
trace_id: 'X-B3-TraceId',
|
31
|
-
parent_id: 'X-B3-ParentSpanId',
|
32
|
-
span_id: 'X-B3-SpanId',
|
33
|
-
sampled: 'X-B3-Sampled',
|
34
|
-
flags: 'X-B3-Flags'
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
28
|
def trace!(env, trace_id)
|
39
29
|
response = nil
|
40
30
|
# handle either a URI object (passed by Faraday v0.8.x in testing), or something string-izable
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -8,7 +8,7 @@ module Trace
|
|
8
8
|
# Most of these are set by the config class and then used around.
|
9
9
|
# TODO: Move this out of the Trace module , take out that extend self and be happier
|
10
10
|
extend self
|
11
|
-
attr_accessor :trace_id_128bit
|
11
|
+
attr_accessor :trace_id_128bit, :write_b3_single_format
|
12
12
|
|
13
13
|
# This method is deprecated, please use TraceGenerator.current
|
14
14
|
# Note that this method will always return a trace, it will
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ZipkinTracer
|
4
|
+
module B3HeaderHelper
|
5
|
+
private
|
6
|
+
|
7
|
+
B3_SINGLE_HEADER = 'b3'
|
8
|
+
|
9
|
+
def set_b3_header(headers, trace_id)
|
10
|
+
if Trace.write_b3_single_format
|
11
|
+
headers[B3_SINGLE_HEADER] = B3SingleHeaderFormat.create_header(trace_id)
|
12
|
+
else
|
13
|
+
b3_headers.each do |method, header|
|
14
|
+
header_value = trace_id.send(method).to_s
|
15
|
+
headers[header] = header_value unless header_value.empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def b3_headers
|
21
|
+
{
|
22
|
+
trace_id: 'X-B3-TraceId',
|
23
|
+
parent_id: 'X-B3-ParentSpanId',
|
24
|
+
span_id: 'X-B3-SpanId',
|
25
|
+
sampled: 'X-B3-Sampled',
|
26
|
+
flags: 'X-B3-Flags'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -5,6 +5,10 @@ module ZipkinTracer
|
|
5
5
|
# b3: {x-b3-traceid}-{x-b3-spanid}-{if x-b3-flags 'd' else x-b3-sampled}-{x-b3-parentspanid}
|
6
6
|
# For details, see: https://github.com/openzipkin/b3-propagation
|
7
7
|
class B3SingleHeaderFormat
|
8
|
+
SAMPLED = '1'
|
9
|
+
NOT_SAMPLED = '0'
|
10
|
+
DEBUG = 'd'
|
11
|
+
|
8
12
|
def self.parse_from_header(b3_single_header)
|
9
13
|
if b3_single_header.size == 1
|
10
14
|
flag = b3_single_header
|
@@ -16,13 +20,19 @@ module ZipkinTracer
|
|
16
20
|
|
17
21
|
def self.parse_sampled(flag)
|
18
22
|
case flag
|
19
|
-
when
|
23
|
+
when SAMPLED, NOT_SAMPLED
|
20
24
|
flag
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
def self.parse_flags(flag)
|
25
|
-
flag ==
|
29
|
+
flag == DEBUG ? Trace::Flags::DEBUG : Trace::Flags::EMPTY
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.create_header(trace_id)
|
33
|
+
flag = trace_id.debug? ? DEBUG : (trace_id.sampled? ? SAMPLED : NOT_SAMPLED)
|
34
|
+
parent_id_with_hyphen = "-#{trace_id.parent_id}" unless trace_id.parent_id.nil?
|
35
|
+
"#{trace_id.trace_id}-#{trace_id.span_id}-#{flag}#{parent_id_with_hyphen}"
|
26
36
|
end
|
27
37
|
end
|
28
38
|
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.
|
4
|
+
version: 0.41.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franklin Hu
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- lib/zipkin-tracer/trace_wrapper.rb
|
226
226
|
- lib/zipkin-tracer/tracer_factory.rb
|
227
227
|
- lib/zipkin-tracer/version.rb
|
228
|
+
- lib/zipkin-tracer/zipkin_b3_header_helper.rb
|
228
229
|
- lib/zipkin-tracer/zipkin_b3_single_header_format.rb
|
229
230
|
- lib/zipkin-tracer/zipkin_http_sender.rb
|
230
231
|
- lib/zipkin-tracer/zipkin_kafka_sender.rb
|