zipkin-tracer 0.35.1 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zipkin-tracer/config.rb +8 -4
- data/lib/zipkin-tracer/trace.rb +1 -1
- data/lib/zipkin-tracer/tracer_factory.rb +14 -11
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer/{zipkin_json_tracer.rb → zipkin_http_sender.rb} +5 -5
- data/lib/zipkin-tracer/{zipkin_kafka_tracer.rb → zipkin_kafka_sender.rb} +2 -2
- data/lib/zipkin-tracer/{zipkin_logger_tracer.rb → zipkin_logger_sender.rb} +2 -2
- data/lib/zipkin-tracer/{zipkin_null_tracer.rb → zipkin_null_sender.rb} +1 -4
- data/lib/zipkin-tracer/{zipkin_tracer_base.rb → zipkin_sender_base.rb} +3 -3
- data/lib/zipkin-tracer/zipkin_sqs_sender.rb +39 -0
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b65eb925752852ca858a99985cd7d9c93927b75a2094e9accddbc50adecf759
|
4
|
+
data.tar.gz: a0f10e2b2798cb7d7c235ee9c6b5165da922e66f01a57c503b8583bbd34965ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb7d829f81ae485aabf96c50f970d0637dd836be7379496d6d6879a7928054dbc0922c77b37702a274734a1b1007a78cb17767fab344b7fc65c382a5af338edc
|
7
|
+
data.tar.gz: 22d4fbc7486aa150fb63a87efa258f38c9a290d1f47ff0ada1949d75f37c90f9294fe69e55cfeb5a29c35522691d8a9051417969f6443b2c2cbcc541992ba603
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -5,11 +5,10 @@ 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, :
|
9
|
-
:zookeeper, :
|
8
|
+
attr_reader :service_name, :sample_rate,
|
9
|
+
:json_api_host, :zookeeper, :kafka_producer, :kafka_topic, :sqs_queue_name, :sqs_region, :log_tracing,
|
10
10
|
:annotate_plugin, :filter_plugin, :whitelist_plugin,
|
11
|
-
:sampled_as_boolean,
|
12
|
-
:kafka_producer, :kafka_topic, :trace_id_128bit
|
11
|
+
:logger, :sampled_as_boolean, :trace_id_128bit
|
13
12
|
|
14
13
|
def initialize(app, config_hash)
|
15
14
|
config = config_hash || Application.config(app)
|
@@ -22,6 +21,9 @@ module ZipkinTracer
|
|
22
21
|
# Kafka producer information
|
23
22
|
@kafka_producer = config[:producer]
|
24
23
|
@kafka_topic = config[:topic] if present?(config[:topic])
|
24
|
+
# Amazon SQS queue information
|
25
|
+
@sqs_queue_name = config[:sqs_queue_name]
|
26
|
+
@sqs_region = config[:sqs_region]
|
25
27
|
# Percentage of traces which by default this service traces (as float, 1.0 means 100%)
|
26
28
|
@sample_rate = config[:sample_rate] || DEFAULTS[:sample_rate]
|
27
29
|
# A block of code which can be called to do extra annotations of traces
|
@@ -61,6 +63,8 @@ module ZipkinTracer
|
|
61
63
|
:kafka
|
62
64
|
elsif @kafka_producer && @kafka_producer.respond_to?(:push)
|
63
65
|
:kafka_producer
|
66
|
+
elsif present?(@sqs_queue_name) && defined?(Aws::SQS)
|
67
|
+
:sqs
|
64
68
|
elsif !!@log_tracing
|
65
69
|
:logger
|
66
70
|
else
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'zipkin-tracer/
|
1
|
+
require 'zipkin-tracer/zipkin_sender_base'
|
2
2
|
require 'zipkin-tracer/trace_container'
|
3
3
|
# Most of this code is copied from Finagle
|
4
4
|
# https://github.com/twitter/finagle/blob/finagle-6.39.0/finagle-thrift/src/main/ruby/lib/finagle-thrift/trace.rb
|
@@ -5,28 +5,31 @@ module ZipkinTracer
|
|
5
5
|
|
6
6
|
tracer = case adapter
|
7
7
|
when :json
|
8
|
-
require 'zipkin-tracer/
|
8
|
+
require 'zipkin-tracer/zipkin_http_sender'
|
9
9
|
options = { json_api_host: config.json_api_host, logger: config.logger }
|
10
|
-
Trace::
|
10
|
+
Trace::ZipkinHttpSender.new(options)
|
11
11
|
when :kafka
|
12
|
-
require 'zipkin-tracer/
|
13
|
-
Trace::
|
12
|
+
require 'zipkin-tracer/zipkin_kafka_sender'
|
13
|
+
Trace::ZipkinKafkaSender.new(zookeepers: config.zookeeper)
|
14
14
|
when :kafka_producer
|
15
|
-
require 'zipkin-tracer/
|
15
|
+
require 'zipkin-tracer/zipkin_kafka_sender'
|
16
16
|
options = { producer: config.kafka_producer }
|
17
17
|
options[:topic] = config.kafka_topic unless config.kafka_topic.nil?
|
18
|
-
Trace::
|
18
|
+
Trace::ZipkinKafkaSender.new(options)
|
19
|
+
when :sqs
|
20
|
+
require 'zipkin-tracer/zipkin_sqs_sender'
|
21
|
+
options = { logger: config.logger, queue_name: config.sqs_queue_name , region: config.sqs_region }
|
22
|
+
Trace::ZipkinSqsSender.new(options)
|
19
23
|
when :logger
|
20
|
-
require 'zipkin-tracer/
|
21
|
-
Trace::
|
24
|
+
require 'zipkin-tracer/zipkin_logger_sender'
|
25
|
+
Trace::ZipkinLoggerSender.new(logger: config.logger)
|
22
26
|
else
|
23
|
-
require 'zipkin-tracer/
|
24
|
-
Trace::
|
27
|
+
require 'zipkin-tracer/zipkin_null_sender'
|
28
|
+
Trace::NullSender.new
|
25
29
|
end
|
26
30
|
Trace.tracer = tracer
|
27
31
|
|
28
32
|
tracer
|
29
33
|
end
|
30
|
-
|
31
34
|
end
|
32
35
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'sucker_punch'
|
3
|
-
require 'zipkin-tracer/
|
3
|
+
require 'zipkin-tracer/zipkin_sender_base'
|
4
4
|
require 'zipkin-tracer/hostname_resolver'
|
5
5
|
|
6
|
-
class
|
6
|
+
class AsyncHttpApiClient
|
7
7
|
include SuckerPunch::Job
|
8
8
|
SPANS_PATH = '/api/v2/spans'
|
9
9
|
|
10
10
|
def perform(json_api_host, spans)
|
11
11
|
spans_with_ips =
|
12
|
-
::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans,
|
12
|
+
::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans, ZipkinHttpSender::IP_FORMAT).map(&:to_h)
|
13
13
|
resp = Faraday.new(json_api_host).post do |req|
|
14
14
|
req.url SPANS_PATH
|
15
15
|
req.headers['Content-Type'] = 'application/json'
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
module Trace
|
28
28
|
# This class sends information to the Zipkin API.
|
29
29
|
# The API accepts a JSON representation of a list of spans
|
30
|
-
class
|
30
|
+
class ZipkinHttpSender < ZipkinSenderBase
|
31
31
|
IP_FORMAT = :string
|
32
32
|
|
33
33
|
def initialize(options)
|
@@ -37,7 +37,7 @@ module Trace
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def flush!
|
40
|
-
|
40
|
+
AsyncHttpApiClient.perform_async(@json_api_host, spans.dup)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -6,13 +6,13 @@ begin
|
|
6
6
|
rescue LoadError => e
|
7
7
|
end
|
8
8
|
|
9
|
-
require 'zipkin-tracer/
|
9
|
+
require 'zipkin-tracer/zipkin_sender_base'
|
10
10
|
require 'zipkin-tracer/hostname_resolver'
|
11
11
|
|
12
12
|
module Trace
|
13
13
|
# This class sends information to Zipkin through Kafka.
|
14
14
|
# Spans are encoded using Thrift
|
15
|
-
class
|
15
|
+
class ZipkinKafkaSender < ZipkinSenderBase
|
16
16
|
DEFAULT_KAFKA_TOPIC = "zipkin".freeze
|
17
17
|
IP_FORMAT = :i32
|
18
18
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'zipkin-tracer/
|
1
|
+
require 'zipkin-tracer/zipkin_sender_base'
|
2
2
|
require 'zipkin-tracer/hostname_resolver'
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module Trace
|
6
|
-
class
|
6
|
+
class ZipkinLoggerSender < ZipkinSenderBase
|
7
7
|
TRACING_KEY = 'Tracing information'
|
8
8
|
IP_FORMAT = :string
|
9
9
|
|
@@ -1,8 +1,5 @@
|
|
1
1
|
module Trace
|
2
|
-
|
3
|
-
# All our tracers have a start_span method, adding it to
|
4
|
-
# the NullTracer also.
|
5
|
-
class NullTracer
|
2
|
+
class NullSender
|
6
3
|
def with_new_span(trace_id, name)
|
7
4
|
span = start_span(trace_id, name)
|
8
5
|
result = yield span
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
3
|
module Trace
|
4
|
-
# This class is a base for
|
4
|
+
# This class is a base for senders sending information to Zipkin.
|
5
5
|
# It knows about zipkin types of annotations and send traces when the server
|
6
6
|
# is done with its request
|
7
|
-
#
|
7
|
+
# Senders dealing with zipkin should inherit from this class and implement the
|
8
8
|
# flush! method which actually sends the information
|
9
|
-
class
|
9
|
+
class ZipkinSenderBase
|
10
10
|
|
11
11
|
def initialize(options={})
|
12
12
|
@options = options
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "aws-sdk-sqs"
|
2
|
+
require "json"
|
3
|
+
require 'sucker_punch'
|
4
|
+
require "zipkin-tracer/zipkin_sender_base"
|
5
|
+
require "zipkin-tracer/hostname_resolver"
|
6
|
+
|
7
|
+
module Trace
|
8
|
+
class AsyncSqsClient
|
9
|
+
include SuckerPunch::Job
|
10
|
+
|
11
|
+
def perform(sqs_options, queue_name, spans)
|
12
|
+
spans_with_ips =
|
13
|
+
::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans, ZipkinSqsSender::IP_FORMAT).map(&:to_h)
|
14
|
+
sqs = Aws::SQS::Client.new(**sqs_options)
|
15
|
+
queue_url = sqs.get_queue_url(queue_name: queue_name).queue_url
|
16
|
+
sqs.send_message(queue_url: queue_url, message_body: JSON.generate(spans_with_ips))
|
17
|
+
rescue Aws::SQS::Errors::NonExistentQueue
|
18
|
+
error_message = "A queue named '#{@queue_name}' does not exist."
|
19
|
+
SuckerPunch.logger.error(error_message)
|
20
|
+
rescue => e
|
21
|
+
SuckerPunch.logger.error(e)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ZipkinSqsSender < ZipkinSenderBase
|
26
|
+
IP_FORMAT = :string
|
27
|
+
|
28
|
+
def initialize(options)
|
29
|
+
@sqs_options = options[:region] ? { region: options[:region] } : {}
|
30
|
+
@queue_name = options[:queue_name]
|
31
|
+
SuckerPunch.logger = options[:logger]
|
32
|
+
super(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def flush!
|
36
|
+
AsyncSqsClient.perform_async(@sqs_options, @queue_name, spans.dup)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.36.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: 2019-04-
|
16
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -57,6 +57,20 @@ dependencies:
|
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '2.0'
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: aws-sdk-sqs
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.0'
|
60
74
|
- !ruby/object:Gem::Dependency
|
61
75
|
name: excon
|
62
76
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,11 +196,12 @@ files:
|
|
182
196
|
- lib/zipkin-tracer/trace_generator.rb
|
183
197
|
- lib/zipkin-tracer/tracer_factory.rb
|
184
198
|
- lib/zipkin-tracer/version.rb
|
185
|
-
- lib/zipkin-tracer/
|
186
|
-
- lib/zipkin-tracer/
|
187
|
-
- lib/zipkin-tracer/
|
188
|
-
- lib/zipkin-tracer/
|
189
|
-
- lib/zipkin-tracer/
|
199
|
+
- lib/zipkin-tracer/zipkin_http_sender.rb
|
200
|
+
- lib/zipkin-tracer/zipkin_kafka_sender.rb
|
201
|
+
- lib/zipkin-tracer/zipkin_logger_sender.rb
|
202
|
+
- lib/zipkin-tracer/zipkin_null_sender.rb
|
203
|
+
- lib/zipkin-tracer/zipkin_sender_base.rb
|
204
|
+
- lib/zipkin-tracer/zipkin_sqs_sender.rb
|
190
205
|
homepage: https://github.com/openzipkin/zipkin-tracer
|
191
206
|
licenses:
|
192
207
|
- Apache-2.0
|