zipkin 1.0.0 → 1.1.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: aeadc7212236b56f7c043a9843f9d2aababefd59
4
- data.tar.gz: d9dd7f5f7f360c45b14f3005c7df7b400ae165e4
3
+ metadata.gz: f7dab2beecf1b862caceca696f39c800ed9a337a
4
+ data.tar.gz: d5047d7b504e42a2d4357f991e651e9dc70fd9f3
5
5
  SHA512:
6
- metadata.gz: c1cb34590a8188c6a604e2fc82f62fd74f7e4858adb7b6d4077e0903dced0d1b273f820a9027884195ede22224cbf001b77769207489e86a95ce516d3168a1bd
7
- data.tar.gz: f015323bcb10ee83346c7a09384bd560f301c3453ff0b70d4ce604bdea47d84dad7167a2e9c4b452b733d601899952cad1504fdebc51000fe3538409d3a3d0f0
6
+ metadata.gz: 42534373a551f427b6be03b32ca2709e7fae389b36a9d93c224ab7e3b4b1db04459a2ad5046a12dcf5e1cf7d3a3e0dbb8c2fbc8d61d72d9d2181cf61a7011e16
7
+ data.tar.gz: cd4a6a54266e0972a6ab0af9314bb929de8624bb9af13db6f2a25d433ad4cb89d1c282c0aed41378fa89b6a27c763508c3b49763376302df5d8792ce3203cedd
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ require: rubocop-rspec
2
+
3
+ Style/Documentation:
4
+ Enabled: no
5
+
6
+ Style/IfUnlessModifier:
7
+ Enabled: no
8
+
9
+ RSpec/NestedGroups:
10
+ Max: 4
11
+
12
+ Metrics/BlockLength:
13
+ Enabled: no
14
+
15
+ Metrics/MethodLength:
16
+ Enabled: no
17
+
18
+ Metrics/AbcSize:
19
+ Enabled: no
20
+
21
+ Lint/UnusedMethodArgument:
22
+ Enabled: no
23
+
24
+ Metrics/LineLength:
25
+ Max: 120
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task :default => :spec
7
+ RuboCop::RakeTask.new(:rubocop)
8
+
9
+ task default: %i[rubocop spec]
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "zipkin"
3
+ require 'bundler/setup'
4
+ require 'zipkin'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -6,20 +6,17 @@ module Zipkin
6
6
  # [] retrieves a value by the given key
7
7
  # @param key [String] key to retrieve the value
8
8
  # @return [String] the desired value
9
- def [](key)
10
- end
9
+ def [](key); end
11
10
 
12
11
  # []= sets the value for the given key
13
12
  # @param key [String] key to set
14
13
  # @param value [String] value to set
15
- def []=(key, value)
16
- end
14
+ def []=(key, value); end
17
15
 
18
16
  # each iterates over every key-value pair in the carrier
19
17
  # @yield [key, value]
20
18
  # @yieldparam key [String] the key of the tuple
21
19
  # @yieldparam value [String] the value of the tuple
22
- def each(&block)
23
- end
20
+ def each(&block); end
24
21
  end
25
22
  end
@@ -15,7 +15,7 @@ module Zipkin
15
15
  finish_ts = (end_time.to_f * 1_000_000).to_i
16
16
  start_ts = (span.start_time.to_f * 1_000_000).to_i
17
17
  duration = finish_ts - start_ts
18
- is_server = ['server', 'consumer'].include?(span.tags['span.kind'] || 'server')
18
+ is_server = %w[server consumer].include?(span.tags['span.kind'] || 'server')
19
19
 
20
20
  @buffer << {
21
21
  traceId: span.context.trace_id,
@@ -32,7 +32,7 @@ module Zipkin
32
32
  },
33
33
  {
34
34
  timestamp: finish_ts,
35
- value: is_server ? 'ss': 'cr',
35
+ value: is_server ? 'ss' : 'cr',
36
36
  endpoint: @local_endpoint
37
37
  }
38
38
  ],
@@ -44,7 +44,7 @@ module Zipkin
44
44
 
45
45
  def build_binary_annotations(span)
46
46
  span.tags.map do |name, value|
47
- {key: name, value: value.to_s}
47
+ { key: name, value: value.to_s }
48
48
  end
49
49
  end
50
50
 
@@ -4,10 +4,11 @@ require 'json'
4
4
 
5
5
  module Zipkin
6
6
  class JsonClient
7
- def initialize(url:, collector:, flush_interval:)
7
+ def initialize(url:, collector:, flush_interval:, logger: Logger.new(STDOUT))
8
8
  @collector = collector
9
9
  @flush_interval = flush_interval
10
10
  @spans_uri = URI.parse("#{url}/api/v1/spans")
11
+ @logger = logger
11
12
  end
12
13
 
13
14
  def start
@@ -31,17 +32,18 @@ module Zipkin
31
32
 
32
33
  http = Net::HTTP.new(@spans_uri.host, @spans_uri.port)
33
34
  http.use_ssl = @spans_uri.scheme == 'https'
34
- request = Net::HTTP::Post.new(@spans_uri.request_uri, {
35
+ request = Net::HTTP::Post.new(
36
+ @spans_uri.request_uri,
35
37
  'Content-Type' => 'application/json'
36
- })
38
+ )
37
39
  request.body = JSON.dump(spans)
38
40
  response = http.request(request)
39
41
 
40
- if response.code != 202
41
- STDERR.puts(response.body)
42
+ if response.code != '202'
43
+ @logger.error("Received bad response from Zipkin. status: #{response.code}, body: #{response.body.inspect}")
42
44
  end
43
- rescue => e
44
- STDERR.puts("Error emitting spans batch: #{e.message}\n#{e.backtrace.join("\n")}")
45
+ rescue StandardError => e
46
+ @logger.error("Error emitting spans batch: #{e.message}\n#{e.backtrace.join("\n")}")
45
47
  end
46
48
  end
47
49
  end
data/lib/zipkin/span.rb CHANGED
@@ -50,7 +50,18 @@ module Zipkin
50
50
  # @param event [String] event name for the log
51
51
  # @param timestamp [Time] time of the log
52
52
  # @param fields [Hash] Additional information to log
53
+ #
54
+ # @deprecated Use {#log_kv} instead.
53
55
  def log(event: nil, timestamp: Time.now, **fields)
56
+ warn 'Span#log is deprecated. Please use Span#log_kv instead.'
57
+ nil
58
+ end
59
+
60
+ # Add a log entry to this span
61
+ #
62
+ # @param timestamp [Time] time of the log
63
+ # @param fields [Hash] Additional information to log
64
+ def log_kv(timestamp: Time.now, **fields)
54
65
  nil
55
66
  end
56
67
 
@@ -1,6 +1,6 @@
1
1
  module Zipkin
2
2
  module TraceId
3
- TRACE_ID_UPPER_BOUND = 2 ** 64
3
+ TRACE_ID_UPPER_BOUND = 2**64
4
4
 
5
5
  def self.generate
6
6
  rand(TRACE_ID_UPPER_BOUND).to_s(16)
data/lib/zipkin/tracer.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'opentracing'
2
+ require 'logger'
2
3
 
3
4
  require_relative 'span'
4
5
  require_relative 'span_context'
@@ -12,20 +13,22 @@ module Zipkin
12
13
  class Tracer
13
14
  DEFAULT_FLUSH_INTERVAL = 10
14
15
 
15
- def self.build(url:, service_name:, flush_interval: DEFAULT_FLUSH_INTERVAL)
16
+ def self.build(url:, service_name:, flush_interval: DEFAULT_FLUSH_INTERVAL, logger: Logger.new(STDOUT))
16
17
  collector = Collector.new(Endpoint.local_endpoint(service_name))
17
18
  sender = JsonClient.new(
18
19
  url: url,
19
20
  collector: collector,
20
- flush_interval: flush_interval
21
+ flush_interval: flush_interval,
22
+ logger: logger
21
23
  )
22
24
  sender.start
23
- new(collector, sender)
25
+ new(collector, sender, logger: logger)
24
26
  end
25
27
 
26
- def initialize(collector, sender)
28
+ def initialize(collector, sender, logger: Logger.new(STDOUT))
27
29
  @collector = collector
28
30
  @sender = sender
31
+ @logger = logger
29
32
  end
30
33
 
31
34
  def stop
@@ -50,10 +53,13 @@ module Zipkin
50
53
  else
51
54
  SpanContext.create_parent_context
52
55
  end
53
- Span.new(context, operation_name, @collector, {
56
+ Span.new(
57
+ context,
58
+ operation_name,
59
+ @collector,
54
60
  start_time: start_time,
55
61
  tags: tags
56
- })
62
+ )
57
63
  end
58
64
 
59
65
  # Inject a SpanContext into the given carrier
@@ -74,7 +80,7 @@ module Zipkin
74
80
  carrier['X-B3-SpanId'] = span_context.span_id
75
81
  carrier['X-B3-Sampled'] = span_context.sampled? ? '1' : '0'
76
82
  else
77
- STDERR.puts "Logasm::Tracer with format #{format} is not supported yet"
83
+ @logger.error "Logasm::Tracer with format #{format} is not supported yet"
78
84
  end
79
85
  end
80
86
 
@@ -100,23 +106,22 @@ module Zipkin
100
106
 
101
107
  create_span_context(trace_id, span_id, parent_id, sampled)
102
108
  else
103
- STDERR.puts "Logasm::Tracer with format #{format} is not supported yet"
109
+ @logger.error "Logasm::Tracer with format #{format} is not supported yet"
104
110
  nil
105
111
  end
106
112
  end
107
113
 
108
114
  private
115
+
109
116
  def create_span_context(trace_id, span_id, parent_id, sampled)
110
- if trace_id && span_id
111
- SpanContext.new(
112
- trace_id: trace_id,
113
- parent_id: parent_id,
114
- span_id: span_id,
115
- sampled: sampled
116
- )
117
- else
118
- nil
119
- end
117
+ return nil if !trace_id || !span_id
118
+
119
+ SpanContext.new(
120
+ trace_id: trace_id,
121
+ parent_id: parent_id,
122
+ span_id: span_id,
123
+ sampled: sampled
124
+ )
120
125
  end
121
126
  end
122
127
  end
data/script/create_trace CHANGED
@@ -10,22 +10,29 @@ url = ENV['ZIPKIN_URL'] || 'http://localhost:9411'
10
10
  tracer1 = Zipkin::Tracer.build(url: url, service_name: 'test-service')
11
11
  tracer2 = Zipkin::Tracer.build(url: url, service_name: 'downstream-service')
12
12
 
13
- outer_span = tracer1.start_span('receive request', tags: {
14
- 'span.kind' => 'server'
15
- })
13
+ outer_span = tracer1.start_span(
14
+ 'receive request',
15
+ tags: { 'span.kind' => 'server' }
16
+ )
16
17
  sleep 1
17
18
 
18
- inner_span = tracer1.start_span('fetch info from downstream', child_of: outer_span, tags: {
19
- 'span.kind' => 'client',
20
- 'peer.service' => 'downstream-service',
21
- 'peer.ipv4' => '6.6.6.6',
22
- 'peer.port' => 443
23
- })
19
+ inner_span = tracer1.start_span(
20
+ 'fetch info from downstream',
21
+ child_of: outer_span,
22
+ tags: {
23
+ 'span.kind' => 'client',
24
+ 'peer.service' => 'downstream-service',
25
+ 'peer.ipv4' => '6.6.6.6',
26
+ 'peer.port' => 443
27
+ }
28
+ )
24
29
  sleep 0.3 # emulate network delay
25
30
 
26
- downstream_span = tracer2.start_span('downstream operation', child_of: inner_span, tags: {
27
- 'span.kind' => 'server'
28
- })
31
+ downstream_span = tracer2.start_span(
32
+ 'downstream operation',
33
+ child_of: inner_span,
34
+ tags: { 'span.kind' => 'server' }
35
+ )
29
36
  sleep 0.5
30
37
  downstream_span.finish
31
38
 
@@ -36,10 +43,10 @@ inner_span.finish
36
43
  sleep 0.1 # doing something with fetched info
37
44
  outer_span.finish
38
45
 
39
- puts "Finishing..."
46
+ puts 'Finishing...'
40
47
  sleep 3
41
48
 
42
49
  tracer1.stop
43
50
  tracer2.stop
44
51
 
45
- puts "Finished"
52
+ puts 'Finished'
data/zipkin.gemspec CHANGED
@@ -1,15 +1,14 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
 
5
4
  Gem::Specification.new do |spec|
6
5
  spec.name = 'zipkin'
7
- spec.version = '1.0.0'
6
+ spec.version = '1.1.0'
8
7
  spec.authors = ['SaleMove TechMovers']
9
8
  spec.email = ['techmovers@salemove.com']
10
9
 
11
- spec.summary = %q{OpenTracing Tracer implementation for Zipkin in Ruby}
12
- spec.description = %q{}
10
+ spec.summary = 'OpenTracing Tracer implementation for Zipkin in Ruby'
11
+ spec.description = ''
13
12
  spec.homepage = ''
14
13
  spec.license = 'MIT'
15
14
 
@@ -22,7 +21,9 @@ Gem::Specification.new do |spec|
22
21
  spec.add_development_dependency 'bundler', '~> 1.14'
23
22
  spec.add_development_dependency 'rake', '~> 10.0'
24
23
  spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'rubocop', '~> 0.54.0'
25
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.24.0'
25
26
 
26
- spec.add_dependency 'opentracing', '~> 0.3'
27
27
  spec.add_dependency 'json'
28
+ spec.add_dependency 'opentracing', '~> 0.3'
28
29
  end
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.0.0
4
+ version: 1.1.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: 2017-12-20 00:00:00.000000000 Z
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: opentracing
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.3'
62
- type: :runtime
61
+ version: 0.54.0
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.3'
68
+ version: 0.54.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.24.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.24.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: json
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: opentracing
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.3'
83
111
  description: ''
84
112
  email:
85
113
  - techmovers@salemove.com
@@ -89,6 +117,7 @@ extra_rdoc_files: []
89
117
  files:
90
118
  - ".gitignore"
91
119
  - ".rspec"
120
+ - ".rubocop.yml"
92
121
  - ".travis.yml"
93
122
  - Gemfile
94
123
  - LICENSE.txt