zipkin 1.5.2 → 1.6.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/README.md +10 -0
- data/lib/zipkin/samplers.rb +4 -0
- data/lib/zipkin/samplers/const.rb +20 -0
- data/lib/zipkin/samplers/probabilistic.rb +21 -0
- data/lib/zipkin/span_context.rb +3 -2
- data/lib/zipkin/tracer.rb +10 -4
- data/zipkin.gemspec +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edcdbbb5c2b3a3c8336007ad27cca00fa18e506c
|
4
|
+
data.tar.gz: e53e657b504bfed502e210cb4ece872f5d719391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8815bc72662edeaed1773112b382134fa7b113290d6d8b1eeb62650ce18f54204048a3bfef69ae674fbbd6278af6bbc2f4603505691805eb0a260f45c9147475
|
7
|
+
data.tar.gz: c28399023b46377b0f3adc267e7b2b242a2e7998302f1ca3739acc8b2411b459af4d6eeef94061640051e4eadd38cb7181e76efe10bf11d2801dab1e93a4d2b7
|
data/README.md
CHANGED
@@ -31,6 +31,16 @@ end
|
|
31
31
|
|
32
32
|
See [opentracing-ruby](https://github.com/opentracing/opentracing-ruby) for more examples.
|
33
33
|
|
34
|
+
### Samplers
|
35
|
+
|
36
|
+
#### Const sampler
|
37
|
+
|
38
|
+
`Const` sampler always makes the same decision for new traces depending on the initialization value. Set `sampler` to: `Zipkin::Samplers::Const.new(true)` to mark all new traces as sampled.
|
39
|
+
|
40
|
+
#### Probabilistic sampler
|
41
|
+
|
42
|
+
`Probabilistic` sampler samples traces with probability equal to `rate` (must be between 0.0 and 1.0). Set `sampler` to `Zipkin::Samplers::Probabilistic.new(rate: 0.1)` to mark 10% of new traces as sampled.
|
43
|
+
|
34
44
|
## Development
|
35
45
|
|
36
46
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zipkin
|
4
|
+
module Samplers
|
5
|
+
# Const sampler
|
6
|
+
#
|
7
|
+
# A sampler that always makes the same decision for new traces depending
|
8
|
+
# on the initialization value. Use `Zipkin::Samplers::Const.new(true)`
|
9
|
+
# to mark all new traces as sampled.
|
10
|
+
class Const
|
11
|
+
def initialize(decision)
|
12
|
+
@decision = decision
|
13
|
+
end
|
14
|
+
|
15
|
+
def sample?(*)
|
16
|
+
@decision
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zipkin
|
4
|
+
module Samplers
|
5
|
+
# Probabilistic sampler
|
6
|
+
#
|
7
|
+
# Sample a portion of traces using trace_id as the random decision
|
8
|
+
class Probabilistic
|
9
|
+
def initialize(rate: 0.001)
|
10
|
+
if rate < 0.0 || rate > 1.0
|
11
|
+
raise "Sampling rate must be between 0.0 and 1.0, got #{rate.inspect}"
|
12
|
+
end
|
13
|
+
@boundary = TraceId::TRACE_ID_UPPER_BOUND * rate
|
14
|
+
end
|
15
|
+
|
16
|
+
def sample?(trace_id:, **)
|
17
|
+
@boundary >= trace_id.to_i(16)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/zipkin/span_context.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
module Zipkin
|
4
4
|
# SpanContext holds the data for a span that gets inherited to child spans
|
5
5
|
class SpanContext
|
6
|
-
def self.create_parent_context
|
6
|
+
def self.create_parent_context(sampler = Samplers::Const.new(true))
|
7
7
|
trace_id = TraceId.generate
|
8
|
-
|
8
|
+
sampled = sampler.sample?(trace_id: trace_id)
|
9
|
+
new(trace_id: trace_id, span_id: trace_id, sampled: sampled)
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.create_from_parent_context(span_context)
|
data/lib/zipkin/tracer.rb
CHANGED
@@ -12,12 +12,17 @@ require_relative 'endpoint'
|
|
12
12
|
require_relative 'collector'
|
13
13
|
require_relative 'scope_manager'
|
14
14
|
require_relative 'scope'
|
15
|
+
require_relative 'samplers'
|
15
16
|
|
16
17
|
module Zipkin
|
17
18
|
class Tracer
|
18
19
|
DEFAULT_FLUSH_INTERVAL = 10
|
19
20
|
|
20
|
-
def self.build(url:,
|
21
|
+
def self.build(url:,
|
22
|
+
service_name:,
|
23
|
+
flush_interval: DEFAULT_FLUSH_INTERVAL,
|
24
|
+
logger: Logger.new(STDOUT),
|
25
|
+
sampler: Samplers::Const.new(true))
|
21
26
|
collector = Collector.new(Endpoint.local_endpoint(service_name))
|
22
27
|
sender = JsonClient.new(
|
23
28
|
url: url,
|
@@ -26,14 +31,15 @@ module Zipkin
|
|
26
31
|
logger: logger
|
27
32
|
)
|
28
33
|
sender.start
|
29
|
-
new(collector, sender, logger: logger)
|
34
|
+
new(collector, sender, logger: logger, sampler: sampler)
|
30
35
|
end
|
31
36
|
|
32
|
-
def initialize(collector, sender, logger: Logger.new(STDOUT))
|
37
|
+
def initialize(collector, sender, logger: Logger.new(STDOUT), sampler:)
|
33
38
|
@collector = collector
|
34
39
|
@sender = sender
|
35
40
|
@logger = logger
|
36
41
|
@scope_manager = ScopeManager.new
|
42
|
+
@sampler = sampler
|
37
43
|
end
|
38
44
|
|
39
45
|
def stop
|
@@ -220,7 +226,7 @@ module Zipkin
|
|
220
226
|
if context
|
221
227
|
SpanContext.create_from_parent_context(context)
|
222
228
|
else
|
223
|
-
SpanContext.create_parent_context
|
229
|
+
SpanContext.create_parent_context(@sampler)
|
224
230
|
end
|
225
231
|
end
|
226
232
|
|
data/zipkin.gemspec
CHANGED
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.
|
4
|
+
version: 1.6.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-07-
|
11
|
+
date: 2018-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -132,6 +132,9 @@ files:
|
|
132
132
|
- lib/zipkin/collector/timestamp.rb
|
133
133
|
- lib/zipkin/endpoint.rb
|
134
134
|
- lib/zipkin/json_client.rb
|
135
|
+
- lib/zipkin/samplers.rb
|
136
|
+
- lib/zipkin/samplers/const.rb
|
137
|
+
- lib/zipkin/samplers/probabilistic.rb
|
135
138
|
- lib/zipkin/scope.rb
|
136
139
|
- lib/zipkin/scope_manager.rb
|
137
140
|
- lib/zipkin/scope_manager/scope_identifier.rb
|