zipkin 1.2.0 → 1.3.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: 253ec789b0311c2a35709b958e1f5fd3e026b043
4
- data.tar.gz: 0367fc35f6be4d5da713bc72bddd425ee0fefca4
3
+ metadata.gz: 4226e47ea8224eeffa7ed8cd4e48e61cc26da790
4
+ data.tar.gz: f7ab917023ea03c1660d3f218b1e6f56147da8be
5
5
  SHA512:
6
- metadata.gz: 3a2a52800b14c3976e9e8ca384fc697fc153d6f1ded256fc698ae22c39d7f2bf991400c518440286c72836743b6db6f42b707e2ba20e364c1a3bb0e7ab7b6da6
7
- data.tar.gz: 5c2afbb1f91211202b65b4be3f0ca5a228a0180669a442d376a527c63d62a008d9a776cdbc085013068331ba6de4fc9425d51bfeaf9efd1d16c6080b4751fea7
6
+ metadata.gz: 7ad6f2ce25802dfd4fca0191a52ef6653887894571f2571663c6ccfa559a9f7241581acd7ceae158040e8056cf95c4016db83883b880077956e45caee9fca109
7
+ data.tar.gz: 5165e5c4d02358d9a8a996baa398450975fb04d542e961464730cb1c58ec287fcf2a66676a1661311f4b4190f50d52f2f0df0dc6b4933fcab0642d79ab777132
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  OpenTracing Tracer implementation for Zipkin in Ruby
4
4
 
5
+ ## Requirements
6
+
7
+ Zipkin version >= 2.0.0
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -18,37 +18,28 @@ module Zipkin
18
18
  finish_ts = Timestamp.create(end_time)
19
19
  start_ts = Timestamp.create(span.start_time)
20
20
  duration = finish_ts - start_ts
21
- is_server = %w[server consumer].include?(span.tags['span.kind'] || 'server')
22
21
 
23
22
  @buffer << {
24
23
  traceId: span.context.trace_id,
25
24
  id: span.context.span_id,
26
25
  parentId: span.context.parent_id,
27
26
  name: span.operation_name,
27
+ kind: (span.tags['span.kind'] || 'SERVER').upcase,
28
28
  timestamp: start_ts,
29
29
  duration: duration,
30
- annotations: LogAnnotations.build(span, @local_endpoint) + [
31
- {
32
- timestamp: start_ts,
33
- value: is_server ? 'sr' : 'cs',
34
- endpoint: @local_endpoint
35
- },
36
- {
37
- timestamp: finish_ts,
38
- value: is_server ? 'ss' : 'cr',
39
- endpoint: @local_endpoint
40
- }
41
- ],
42
- binaryAnnotations: build_binary_annotations(span)
30
+ debug: false,
31
+ shared: false,
32
+ localEndpoint: @local_endpoint,
33
+ remoteEndpoint: Endpoint.remote_endpoint(span),
34
+ annotations: LogAnnotations.build(span),
35
+ tags: build_tags(span)
43
36
  }
44
37
  end
45
38
 
46
39
  private
47
40
 
48
- def build_binary_annotations(span)
49
- span.tags.map do |name, value|
50
- { key: name, value: value.to_s }
51
- end
41
+ def build_tags(span)
42
+ span.tags.map { |key, value| [key.to_s, value.to_s] }.to_h
52
43
  end
53
44
 
54
45
  class Buffer
@@ -1,12 +1,11 @@
1
1
  module Zipkin
2
2
  class Collector
3
3
  module LogAnnotations
4
- def self.build(span, endpoint)
4
+ def self.build(span)
5
5
  span.logs.map do |log|
6
6
  {
7
7
  timestamp: Timestamp.create(log.fetch(:timestamp)),
8
- value: format_log_value(log),
9
- endpoint: endpoint
8
+ value: format_log_value(log)
10
9
  }
11
10
  end
12
11
  end
@@ -7,11 +7,53 @@ module Zipkin
7
7
  Socket.ip_address_list.reverse.detect(&:ipv4?)
8
8
  ).ip_address
9
9
 
10
+ module SpanKind
11
+ SERVER = 'server'.freeze
12
+ CLIENT = 'client'.freeze
13
+ PRODUCER = 'producer'.freeze
14
+ CONSUMER = 'consumer'.freeze
15
+ end
16
+
17
+ module PeerInfo
18
+ SERVICE = 'peer.service'.freeze
19
+ IPV4 = 'peer.ipv4'.freeze
20
+ IPV6 = 'peer.ipv6'.freeze
21
+ PORT = 'peer.port'.freeze
22
+
23
+ def self.keys
24
+ [SERVICE, IPV4, IPV6, PORT]
25
+ end
26
+ end
27
+
10
28
  def self.local_endpoint(service_name)
11
29
  {
12
30
  serviceName: service_name,
13
31
  ipv4: LOCAL_IP
14
32
  }
15
33
  end
34
+
35
+ def self.remote_endpoint(span)
36
+ tags = span.tags
37
+ kind = tags['span.kind'] || SpanKind::SERVER
38
+
39
+ case kind
40
+ when SpanKind::SERVER, SpanKind::CLIENT
41
+ return nil if (tags.keys & PeerInfo.keys).empty?
42
+
43
+ {
44
+ serviceName: tags[PeerInfo::SERVICE],
45
+ ipv4: tags[PeerInfo::IPV4],
46
+ ipv6: tags[PeerInfo::IPV6],
47
+ port: tags[PeerInfo::PORT]
48
+ }
49
+ when SpanKind::PRODUCER, SpanKind::CONSUMER
50
+ {
51
+ serviceName: 'broker'
52
+ }
53
+ else
54
+ warn "Unkown span kind: #{kind}"
55
+ nil
56
+ end
57
+ end
16
58
  end
17
59
  end
@@ -7,7 +7,7 @@ module Zipkin
7
7
  def initialize(url:, collector:, flush_interval:, logger: Logger.new(STDOUT))
8
8
  @collector = collector
9
9
  @flush_interval = flush_interval
10
- @spans_uri = URI.parse("#{url}/api/v1/spans")
10
+ @spans_uri = URI.parse("#{url}/api/v2/spans")
11
11
  @logger = logger
12
12
  end
13
13
 
@@ -28,5 +28,16 @@ module Zipkin
28
28
  def sampled?
29
29
  @sampled
30
30
  end
31
+
32
+ # NOTE: This method is not defined in OpenTracing Ruby spec. Use with
33
+ # caution.
34
+ def to_h
35
+ {
36
+ span_id: @span_id,
37
+ parent_id: @parent_id,
38
+ trace_id: @trace_id,
39
+ sampled: @sampled
40
+ }
41
+ end
31
42
  end
32
43
  end
data/script/create_trace CHANGED
@@ -12,7 +12,9 @@ tracer2 = Zipkin::Tracer.build(url: url, service_name: 'downstream-service')
12
12
 
13
13
  outer_span = tracer1.start_span(
14
14
  'receive request',
15
- tags: { 'span.kind' => 'server' }
15
+ tags: {
16
+ 'span.kind' => 'server'
17
+ }
16
18
  )
17
19
  sleep 1
18
20
 
data/zipkin.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'zipkin'
6
- spec.version = '1.2.0'
6
+ spec.version = '1.3.0'
7
7
  spec.authors = ['SaleMove TechMovers']
8
8
  spec.email = ['techmovers@salemove.com']
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipkin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler