zipkin-tracer 0.43.1 → 0.47.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -2
- data/.travis.yml +15 -8
- data/Appraisals +7 -0
- data/CHANGELOG.md +15 -0
- data/README.md +46 -8
- data/gemfiles/faraday_0.x.gemfile +18 -0
- data/gemfiles/faraday_1.x.gemfile +18 -0
- data/lib/zipkin-tracer/config.rb +4 -1
- data/lib/zipkin-tracer/hostname_resolver.rb +8 -7
- data/lib/zipkin-tracer/rack/zipkin-tracer.rb +1 -1
- data/lib/zipkin-tracer/rack/zipkin_env.rb +4 -3
- data/lib/zipkin-tracer/sqs/adapter.rb +4 -0
- data/lib/zipkin-tracer/sqs/zipkin-tracer.rb +57 -0
- data/lib/zipkin-tracer/trace.rb +7 -7
- data/lib/zipkin-tracer/trace_wrapper.rb +13 -2
- data/lib/zipkin-tracer/version.rb +3 -1
- data/lib/zipkin-tracer/zipkin_sender_base.rb +5 -4
- data/zipkin-tracer.gemspec +3 -2
- metadata +31 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3094b9f74dd042c34745150a69644c87e61acb21b973c0aac0eae21e4b1a94
|
4
|
+
data.tar.gz: bf11f2ddb0503cf448cf2e0595418bce982cb1c4f1fd7594fbce0db5e3422a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea9e6b556a501c882b06c22261e65d44e917d695f0624b677f261751e2bfd6054b6152dde01773c2b92e016226b40242252ae9d3a1b1d1dd734b420f22bc397
|
7
|
+
data.tar.gz: 5dd88683e1f4b1727acbd41ca2ae0457cae8ff100853beaee5cb578e87a55fa1ebd733951b915a1047c4c3328005337f59df8bb40840cc5d386fd53525fd5f22
|
data/.gitignore
CHANGED
@@ -9,16 +9,20 @@
|
|
9
9
|
/test/version_tmp/
|
10
10
|
/tmp/
|
11
11
|
|
12
|
-
|
12
|
+
# Documentation cache and generated files:
|
13
13
|
/.yardoc/
|
14
14
|
/_yardoc/
|
15
15
|
/doc/
|
16
16
|
/rdoc/
|
17
17
|
|
18
|
-
|
18
|
+
# Environment normalisation:
|
19
19
|
/.bundle/
|
20
20
|
/lib/bundler/man/
|
21
21
|
|
22
|
+
# Appraisal related files
|
23
|
+
/gemfiles/.bundle/
|
24
|
+
/gemfiles/*.gemfile.lock
|
25
|
+
|
22
26
|
# for a library or gem, you might want to ignore these files since the code is
|
23
27
|
# intended to run in multiple environments; otherwise, check them in:
|
24
28
|
# Gemfile.lock
|
data/.travis.yml
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
language: ruby
|
2
2
|
dist: bionic
|
3
|
-
jdk:
|
4
|
-
|
3
|
+
jdk: openjdk11
|
4
|
+
|
5
5
|
rvm:
|
6
|
-
- 2.7
|
7
|
-
- 2.6
|
8
|
-
- 2.5
|
9
|
-
- 2.4
|
10
6
|
- 2.3
|
7
|
+
- 2.4
|
8
|
+
- 2.5
|
9
|
+
- 2.6
|
10
|
+
- 2.7
|
11
11
|
- jruby-9.1
|
12
12
|
- jruby-9.2
|
13
|
+
|
14
|
+
gemfile:
|
15
|
+
- gemfiles/faraday_0.x.gemfile
|
16
|
+
- gemfiles/faraday_1.x.gemfile
|
17
|
+
|
18
|
+
script: bundle exec rspec
|
19
|
+
|
13
20
|
deploy:
|
14
21
|
provider: rubygems
|
15
22
|
api_key:
|
@@ -18,7 +25,8 @@ deploy:
|
|
18
25
|
on:
|
19
26
|
tags: true
|
20
27
|
repo: openzipkin/zipkin-ruby
|
21
|
-
condition:
|
28
|
+
condition: $TRAVIS_RUBY_VERSION == 2.7 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
|
29
|
+
|
22
30
|
notifications:
|
23
31
|
webhooks:
|
24
32
|
urls:
|
@@ -26,4 +34,3 @@ notifications:
|
|
26
34
|
- https://webhooks.gitter.im/e/e57478303f87ecd7bffc
|
27
35
|
on_success: change
|
28
36
|
on_failure: always
|
29
|
-
script: "bundle exec rspec"
|
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# 0.47.1
|
2
|
+
* Fix to set `SERVER` span kind at the beginning to avoid being flushed before closing.
|
3
|
+
|
4
|
+
# 0.47.0
|
5
|
+
* Add a `check_routes` option to make the routable request check optional.
|
6
|
+
|
7
|
+
# 0.46.0
|
8
|
+
* Add Amazon SQS tracer.
|
9
|
+
|
10
|
+
# 0.45.0
|
11
|
+
* Add a `trace_context` option to the TraceWrapper utility class to retrieve trace data.
|
12
|
+
|
13
|
+
# 0.44.0
|
14
|
+
* Allow Faraday 1.x.
|
15
|
+
|
1
16
|
# 0.43.1
|
2
17
|
* Fix to not flush `PRODUCER` span when a server span is in the stack.
|
3
18
|
|
data/README.md
CHANGED
@@ -21,6 +21,7 @@ use ZipkinTracer::RackHandler, config
|
|
21
21
|
* `:service_name` **REQUIRED** - the name of the service being traced. There are two ways to configure this value. Either write the service name in the config file or set the "DOMAIN" environment variable (e.g. 'test-service.example.com' or 'test-service'). The environment variable takes precedence over the config file value.
|
22
22
|
* `:sample_rate` (default: 0.1) - the ratio of requests to sample, from 0 to 1
|
23
23
|
* `:sampled_as_boolean` - When set to true (default but deprecrated), it uses true/false for the `X-B3-Sampled` header. When set to false uses 1/0 which is preferred.
|
24
|
+
* `:check_routes` - When set to `true`, only routable requests are sampled. Defaults to `false`.
|
24
25
|
* `: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
26
|
* `: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
27
|
* `:logger` - The default logger for Rails apps is `Rails.logger`, else it is `STDOUT`. Use this option to pass a custom logger.
|
@@ -43,11 +44,6 @@ use ZipkinTracer::RackHandler, config
|
|
43
44
|
|
44
45
|
### Sending traces on outgoing requests with Faraday
|
45
46
|
|
46
|
-
First, Faraday has to be part of your Gemfile:
|
47
|
-
```
|
48
|
-
gem 'faraday', '~> 0.8'
|
49
|
-
```
|
50
|
-
|
51
47
|
For the Faraday middleware to have the correct trace ID, the rack middleware should be used in your application as explained above.
|
52
48
|
|
53
49
|
Then include `ZipkinTracer::FaradayHandler` as a Faraday middleware:
|
@@ -56,10 +52,8 @@ Then include `ZipkinTracer::FaradayHandler` as a Faraday middleware:
|
|
56
52
|
require 'faraday'
|
57
53
|
require 'zipkin-tracer'
|
58
54
|
|
59
|
-
conn = Faraday.new(:
|
55
|
+
conn = Faraday.new(url: 'http://localhost:9292/') do |faraday|
|
60
56
|
faraday.use ZipkinTracer::FaradayHandler, 'service_name' # 'service_name' is optional (but recommended)
|
61
|
-
# default Faraday stack
|
62
|
-
faraday.request :url_encoded
|
63
57
|
faraday.adapter Faraday.default_adapter
|
64
58
|
end
|
65
59
|
```
|
@@ -88,6 +82,38 @@ end
|
|
88
82
|
|
89
83
|
By default workers aren't traced. You can specify the workers that you want to trace with traceable_workers config option. If you want all your workers to be traced pass [:all] to traceable_workers option (traceable_workers: [:all]).
|
90
84
|
|
85
|
+
### Tracing Amazon SQS messages
|
86
|
+
|
87
|
+
Amazon SQS tracing can be turned on by requiring [zipkin-tracer/sqs/adapter](lib/zipkin-tracer/sqs/adapter.rb):
|
88
|
+
```ruby
|
89
|
+
require 'zipkin-tracer/sqs/adapter'
|
90
|
+
```
|
91
|
+
|
92
|
+
This SQS adapter overrides the `send_message` and `send_message_batch` methods to add trace data as message attributes and to generate a producer span when the methods are called. Since all SQS messages are affected, it is not recommended to use this feature with the [SQS sender](lib/zipkin-tracer/zipkin_sqs_sender.rb).
|
93
|
+
|
94
|
+
When receiving messages, you need to pass the `message_attribute_names: ['All']` option to retrive message attributes:
|
95
|
+
```ruby
|
96
|
+
resp = sqs.receive_message(
|
97
|
+
queue_url: queue_url,
|
98
|
+
message_attribute_names: ['All']
|
99
|
+
)
|
100
|
+
```
|
101
|
+
|
102
|
+
Then you can utilize the [TraceWrapper](#tracewrapper) class to generate a consumer span:
|
103
|
+
```ruby
|
104
|
+
msg = resp.messages.first
|
105
|
+
trace_context = msg.message_attributes.each_with_object({}) { |(key, value), hsh| hsh[key.to_sym] = value.string_value }
|
106
|
+
|
107
|
+
TraceWrapper.wrap_in_custom_span(config, 'receive_message',
|
108
|
+
span_kind: Trace::Span::Kind::CONSUMER,
|
109
|
+
trace_context: trace_context
|
110
|
+
) do |span|
|
111
|
+
span.remote_endpoint = Trace::Endpoint.remote_endpoint(nil, 'amazon-sqs')
|
112
|
+
span.record_tag('queue.url', queue_url)
|
113
|
+
:
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
91
117
|
### Local tracing
|
92
118
|
|
93
119
|
`ZipkinTracer::TraceClient` provides an API to record local traces in your application.
|
@@ -249,6 +275,18 @@ TraceWrapper.wrap_in_custom_span(config, "custom span") do |span|
|
|
249
275
|
end
|
250
276
|
```
|
251
277
|
|
278
|
+
The `trace_context:` keyword argument can be used to retrieve trace data:
|
279
|
+
```ruby
|
280
|
+
trace_context = {
|
281
|
+
trace_id: '234555b04cf7e099',
|
282
|
+
span_id: '234555b04cf7e099',
|
283
|
+
sampled: 'true'
|
284
|
+
}
|
285
|
+
|
286
|
+
TraceWrapper.wrap_in_custom_span(config, "custom span", trace_context: trace_context) do |span|
|
287
|
+
:
|
288
|
+
end
|
289
|
+
```
|
252
290
|
|
253
291
|
## Development
|
254
292
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "faraday", "~> 0.13"
|
6
|
+
|
7
|
+
platforms :ruby do
|
8
|
+
gem "benchmark-ips"
|
9
|
+
gem "rbtrace"
|
10
|
+
gem "byebug"
|
11
|
+
gem "simplecov", require: false
|
12
|
+
end
|
13
|
+
|
14
|
+
platforms :jruby do
|
15
|
+
gem "hermann", "~> 0.27.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "faraday", "~> 1.0"
|
6
|
+
|
7
|
+
platforms :ruby do
|
8
|
+
gem "benchmark-ips"
|
9
|
+
gem "rbtrace"
|
10
|
+
gem "byebug"
|
11
|
+
gem "simplecov", require: false
|
12
|
+
end
|
13
|
+
|
14
|
+
platforms :jruby do
|
15
|
+
gem "hermann", "~> 0.27.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec path: "../"
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -5,7 +5,7 @@ require 'zipkin-tracer/rack/zipkin-tracer'
|
|
5
5
|
module ZipkinTracer
|
6
6
|
# Configuration of this gem. It reads the configuration and provides default values
|
7
7
|
class Config
|
8
|
-
attr_reader :service_name, :sample_rate, :sampled_as_boolean, :trace_id_128bit, :async, :logger,
|
8
|
+
attr_reader :service_name, :sample_rate, :sampled_as_boolean, :check_routes, :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
11
|
:rabbit_mq_routing_key, :write_b3_single_format
|
@@ -47,6 +47,8 @@ module ZipkinTracer
|
|
47
47
|
if @sampled_as_boolean
|
48
48
|
@logger && @logger.warn("Using a boolean in the Sampled header is deprecated. Consider setting sampled_as_boolean to false")
|
49
49
|
end
|
50
|
+
# When set to true, only routable requests are sampled
|
51
|
+
@check_routes = config[:check_routes].nil? ? DEFAULTS[:check_routes] : config[:check_routes]
|
50
52
|
|
51
53
|
# When set to true, high 8-bytes will be prepended to trace_id.
|
52
54
|
# The upper 4-bytes are epoch seconds and the lower 4-bytes are random.
|
@@ -95,6 +97,7 @@ module ZipkinTracer
|
|
95
97
|
DEFAULTS = {
|
96
98
|
sample_rate: 0.1,
|
97
99
|
sampled_as_boolean: true,
|
100
|
+
check_routes: false,
|
98
101
|
trace_id_128bit: false,
|
99
102
|
write_b3_single_format: false
|
100
103
|
}
|
@@ -11,15 +11,17 @@ module ZipkinTracer
|
|
11
11
|
|
12
12
|
each_endpoint(spans) do |endpoint|
|
13
13
|
hostname = endpoint.ipv4
|
14
|
-
unless
|
15
|
-
|
16
|
-
|
14
|
+
next unless hostname
|
15
|
+
next if resolved_ip_address?(hostname.to_s)
|
16
|
+
|
17
|
+
endpoint.ipv4 = resolved_hosts[hostname]
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
22
|
+
|
21
23
|
LOCALHOST = '127.0.0.1'.freeze
|
22
|
-
LOCALHOST_I32 = 0x7f000001
|
24
|
+
LOCALHOST_I32 = 0x7f000001
|
23
25
|
MAX_I32 = ((2 ** 31) - 1)
|
24
26
|
MASK = (2 ** 32) - 1
|
25
27
|
IP_FIELD = 3
|
@@ -49,10 +51,9 @@ module ZipkinTracer
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def resolve(hosts, ip_format)
|
52
|
-
hosts.
|
54
|
+
hosts.each_with_object({}) do |host, host_map|
|
53
55
|
hostname = host.ipv4 # This field has been temporarly used to store the hostname.
|
54
|
-
host_map[hostname]
|
55
|
-
host_map
|
56
|
+
host_map[hostname] = host_to_format(hostname, ip_format) if hostname
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -25,6 +25,7 @@ module ZipkinTracer
|
|
25
25
|
@app.call(env)
|
26
26
|
else
|
27
27
|
@tracer.with_new_span(trace_id, span_name(env)) do |span|
|
28
|
+
span.kind = Trace::Span::Kind::SERVER
|
28
29
|
trace!(span, zipkin_env) { @app.call(env) }
|
29
30
|
end
|
30
31
|
end
|
@@ -55,7 +56,6 @@ module ZipkinTracer
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def trace_server_information(span, zipkin_env, status)
|
58
|
-
span.kind = Trace::Span::Kind::SERVER
|
59
59
|
span.record_status(status)
|
60
60
|
SERVER_RECV_TAGS.each { |annotation_key, env_key| span.record_tag(annotation_key, zipkin_env.env[env_key]) }
|
61
61
|
end
|
@@ -71,7 +71,7 @@ module ZipkinTracer
|
|
71
71
|
if parent_trace_sampled # A service upstream decided this goes in all the way
|
72
72
|
parent_trace_sampled
|
73
73
|
else
|
74
|
-
new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered? &&
|
74
|
+
new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered? && traceable_request?)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -83,9 +83,10 @@ module ZipkinTracer
|
|
83
83
|
@config.filter_plugin && !@config.filter_plugin.call(@env)
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
86
|
+
def traceable_request?
|
87
|
+
return true unless @config.check_routes
|
88
|
+
|
87
89
|
Application.routable_request?(@env)
|
88
90
|
end
|
89
|
-
|
90
91
|
end
|
91
92
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ZipkinTracer
|
2
|
+
# This module is designed to prepend to the SQS client to add trace data as message attributes.
|
3
|
+
# https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-sqs/lib/aws-sdk-sqs/client.rb
|
4
|
+
module SqsHandler
|
5
|
+
def send_message(params = {}, options = {})
|
6
|
+
zipkin_sqs_trace_wrapper(params, __method__) { |params_with_trace| super(params_with_trace, options) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def send_message_batch(params = {}, options = {})
|
10
|
+
zipkin_sqs_trace_wrapper(params, __method__) { |params_with_trace| super(params_with_trace, options) }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
ZIPKIN_KEYS = %i[trace_id parent_id span_id sampled].freeze
|
16
|
+
ZIPKIN_REMOTE_ENDPOINT_SQS = Trace::Endpoint.remote_endpoint(nil, 'amazon-sqs')
|
17
|
+
|
18
|
+
def zipkin_sqs_trace_wrapper(params, method_name)
|
19
|
+
trace_id = TraceGenerator.new.next_trace_id
|
20
|
+
zipkin_set_message_attributes(params, method_name, trace_id)
|
21
|
+
|
22
|
+
TraceContainer.with_trace_id(trace_id) do
|
23
|
+
if Trace.tracer && trace_id.sampled?
|
24
|
+
Trace.tracer.with_new_span(trace_id, method_name) do |span|
|
25
|
+
span.kind = Trace::Span::Kind::PRODUCER
|
26
|
+
span.remote_endpoint = ZIPKIN_REMOTE_ENDPOINT_SQS
|
27
|
+
span.record_tag('queue.url', params[:queue_url])
|
28
|
+
yield(params)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
yield(params)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def zipkin_set_message_attributes(params, method_name, trace_id)
|
37
|
+
attributes = zipkin_message_attributes(trace_id)
|
38
|
+
case method_name
|
39
|
+
when :send_message
|
40
|
+
params[:message_attributes] = attributes.merge(params[:message_attributes] || {})
|
41
|
+
when :send_message_batch
|
42
|
+
params[:entries].each do |entry|
|
43
|
+
entry[:message_attributes] = attributes.merge(entry[:message_attributes] || {})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def zipkin_message_attributes(trace_id)
|
49
|
+
ZIPKIN_KEYS.each_with_object({}) do |zipkin_key, message_attributes|
|
50
|
+
zipkin_value = trace_id.send(zipkin_key)
|
51
|
+
next unless zipkin_value
|
52
|
+
|
53
|
+
message_attributes[zipkin_key] = { string_value: zipkin_value.to_s, data_type: 'String' }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -115,21 +115,21 @@ module Trace
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def next_id
|
118
|
-
TraceId.new(
|
118
|
+
TraceId.new(trace_id, span_id, ZipkinTracer::TraceGenerator.new.generate_id, sampled, flags)
|
119
119
|
end
|
120
120
|
|
121
121
|
# the debug flag is used to ensure the trace passes ALL samplers
|
122
122
|
def debug?
|
123
|
-
|
123
|
+
flags & Flags::DEBUG == Flags::DEBUG
|
124
124
|
end
|
125
125
|
|
126
126
|
def sampled?
|
127
|
-
debug? || [
|
127
|
+
debug? || %w[1 true].include?(sampled)
|
128
128
|
end
|
129
129
|
|
130
130
|
def to_s
|
131
|
-
"TraceId(trace_id = #{
|
132
|
-
" sampled = #{
|
131
|
+
"TraceId(trace_id = #{trace_id}, parent_id = #{parent_id}, span_id = #{span_id}," \
|
132
|
+
" sampled = #{sampled}, flags = #{flags}, shared = #{shared})"
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
@@ -277,8 +277,8 @@ module Trace
|
|
277
277
|
end
|
278
278
|
|
279
279
|
def self.remote_endpoint(url, remote_service_name)
|
280
|
-
service_name = remote_service_name || url
|
281
|
-
Endpoint.new(url
|
280
|
+
service_name = remote_service_name || url&.host&.split('.')&.first || UNKNOWN_URL # default to url-derived service name
|
281
|
+
Endpoint.new(url&.host, url&.port, service_name)
|
282
282
|
end
|
283
283
|
|
284
284
|
def to_h
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module ZipkinTracer
|
2
2
|
class TraceWrapper
|
3
|
-
|
3
|
+
REQUIRED_KEYS = %i[trace_id span_id].freeze
|
4
|
+
KEYS = %i[trace_id parent_id span_id sampled].freeze
|
5
|
+
|
6
|
+
def self.wrap_in_custom_span(config, span_name, span_kind: Trace::Span::Kind::SERVER, app: nil, trace_context: nil)
|
4
7
|
raise ArgumentError, "you must provide a block" unless block_given?
|
5
8
|
|
6
9
|
initialize_tracer(app, config)
|
7
|
-
trace_id =
|
10
|
+
trace_id = next_trace_id(trace_context)
|
8
11
|
|
9
12
|
ZipkinTracer::TraceContainer.with_trace_id(trace_id) do
|
10
13
|
if trace_id.sampled?
|
@@ -24,5 +27,13 @@ module ZipkinTracer
|
|
24
27
|
zipkin_config = ZipkinTracer::Config.new(app, config).freeze
|
25
28
|
ZipkinTracer::TracerFactory.new.tracer(zipkin_config)
|
26
29
|
end
|
30
|
+
|
31
|
+
def self.next_trace_id(trace_context)
|
32
|
+
if trace_context.is_a?(Hash) && REQUIRED_KEYS.all? { |key| trace_context.key?(key) }
|
33
|
+
Trace::TraceId.new(*trace_context.values_at(*KEYS), Trace::Flags::EMPTY).next_id
|
34
|
+
else
|
35
|
+
ZipkinTracer::TraceGenerator.new.next_trace_id
|
36
|
+
end
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
@@ -7,8 +7,7 @@ module Trace
|
|
7
7
|
# Senders dealing with zipkin should inherit from this class and implement the
|
8
8
|
# flush! method which actually sends the information
|
9
9
|
class ZipkinSenderBase
|
10
|
-
|
11
|
-
def initialize(options={})
|
10
|
+
def initialize(options = {})
|
12
11
|
@options = options
|
13
12
|
reset
|
14
13
|
end
|
@@ -40,7 +39,10 @@ module Trace
|
|
40
39
|
|
41
40
|
def skip_flush?(span)
|
42
41
|
return true if span.kind == Trace::Span::Kind::CLIENT && span.has_parent_span?
|
43
|
-
|
42
|
+
|
43
|
+
if span.kind == Trace::Span::Kind::PRODUCER
|
44
|
+
return true if spans.any? { |s| s.kind == Trace::Span::Kind::SERVER || s.kind == Trace::Span::Kind::CONSUMER }
|
45
|
+
end
|
44
46
|
end
|
45
47
|
|
46
48
|
def flush!
|
@@ -62,6 +64,5 @@ module Trace
|
|
62
64
|
def reset
|
63
65
|
Thread.current[THREAD_KEY] = []
|
64
66
|
end
|
65
|
-
|
66
67
|
end
|
67
68
|
end
|
data/zipkin-tracer.gemspec
CHANGED
@@ -24,16 +24,17 @@ Gem::Specification.new do |s|
|
|
24
24
|
end
|
25
25
|
s.require_paths = ['lib']
|
26
26
|
|
27
|
-
s.add_dependency 'faraday', '
|
27
|
+
s.add_dependency 'faraday', '>= 0.13', '< 2.0'
|
28
28
|
s.add_dependency 'rack', '>= 1.0'
|
29
29
|
s.add_dependency 'sucker_punch', '~> 2.0'
|
30
30
|
|
31
|
+
s.add_development_dependency 'appraisal'
|
31
32
|
s.add_development_dependency 'aws-sdk-sqs', '~> 1.0'
|
32
33
|
s.add_development_dependency 'excon', '~> 0.53'
|
33
34
|
s.add_development_dependency 'rspec', '~> 3.8'
|
34
35
|
s.add_development_dependency 'rspec-json_expectations', '~> 2.2'
|
35
36
|
s.add_development_dependency 'rack-test', '~> 1.1'
|
36
|
-
s.add_development_dependency 'rake', '~>
|
37
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
37
38
|
s.add_development_dependency 'timecop', '~> 0.8'
|
38
39
|
s.add_development_dependency 'webmock', '~> 3.0'
|
39
40
|
s.add_development_dependency 'simplecov', '~> 0.16'
|
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.47.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franklin Hu
|
@@ -14,22 +14,28 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2020-
|
17
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: faraday
|
21
21
|
requirement: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
|
-
- - "
|
23
|
+
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '0.13'
|
26
|
+
- - "<"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '2.0'
|
26
29
|
type: :runtime
|
27
30
|
prerelease: false
|
28
31
|
version_requirements: !ruby/object:Gem::Requirement
|
29
32
|
requirements:
|
30
|
-
- - "
|
33
|
+
- - ">="
|
31
34
|
- !ruby/object:Gem::Version
|
32
35
|
version: '0.13'
|
36
|
+
- - "<"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '2.0'
|
33
39
|
- !ruby/object:Gem::Dependency
|
34
40
|
name: rack
|
35
41
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +64,20 @@ dependencies:
|
|
58
64
|
- - "~>"
|
59
65
|
- !ruby/object:Gem::Version
|
60
66
|
version: '2.0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: appraisal
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
61
81
|
- !ruby/object:Gem::Dependency
|
62
82
|
name: aws-sdk-sqs
|
63
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,14 +154,14 @@ dependencies:
|
|
134
154
|
requirements:
|
135
155
|
- - "~>"
|
136
156
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
157
|
+
version: '13.0'
|
138
158
|
type: :development
|
139
159
|
prerelease: false
|
140
160
|
version_requirements: !ruby/object:Gem::Requirement
|
141
161
|
requirements:
|
142
162
|
- - "~>"
|
143
163
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
164
|
+
version: '13.0'
|
145
165
|
- !ruby/object:Gem::Dependency
|
146
166
|
name: timecop
|
147
167
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,6 +220,7 @@ files:
|
|
200
220
|
- ".gitignore"
|
201
221
|
- ".rspec"
|
202
222
|
- ".travis.yml"
|
223
|
+
- Appraisals
|
203
224
|
- CHANGELOG.md
|
204
225
|
- Gemfile
|
205
226
|
- LICENSE
|
@@ -209,6 +230,8 @@ files:
|
|
209
230
|
- Rakefile
|
210
231
|
- bin/console
|
211
232
|
- bin/setup
|
233
|
+
- gemfiles/faraday_0.x.gemfile
|
234
|
+
- gemfiles/faraday_1.x.gemfile
|
212
235
|
- lib/zipkin-tracer.rb
|
213
236
|
- lib/zipkin-tracer/application.rb
|
214
237
|
- lib/zipkin-tracer/config.rb
|
@@ -218,6 +241,8 @@ files:
|
|
218
241
|
- lib/zipkin-tracer/rack/zipkin-tracer.rb
|
219
242
|
- lib/zipkin-tracer/rack/zipkin_env.rb
|
220
243
|
- lib/zipkin-tracer/sidekiq/middleware.rb
|
244
|
+
- lib/zipkin-tracer/sqs/adapter.rb
|
245
|
+
- lib/zipkin-tracer/sqs/zipkin-tracer.rb
|
221
246
|
- lib/zipkin-tracer/trace.rb
|
222
247
|
- lib/zipkin-tracer/trace_client.rb
|
223
248
|
- lib/zipkin-tracer/trace_container.rb
|