zipkin 1.4.0 → 1.5.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/lib/zipkin/span.rb +10 -2
- data/lib/zipkin/tracer.rb +38 -11
- data/script/create_follows_from_trace +51 -0
- data/zipkin.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08c97e0494e2aada96486d717d1cd8b645da89c2'
|
4
|
+
data.tar.gz: dc7681e5f0a7c4efe293f22ad496f9c352675137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f80229eec38c0f34c83276264b90073195b80e74f5389569ff5458957e9f90e85a02856684a169a116239cb5c804a9eef69161b32851ac38222545090a26306
|
7
|
+
data.tar.gz: b2ee56339a6e2eb7aa615becf7fd163fd86d66e165fb065a3f50e9cc89fd217a3be3628f7484491f90c866b8460b4f4eea0c487575de29693da928895307d059
|
data/lib/zipkin/span.rb
CHANGED
@@ -4,7 +4,7 @@ module Zipkin
|
|
4
4
|
class Span
|
5
5
|
attr_accessor :operation_name
|
6
6
|
|
7
|
-
attr_reader :context, :start_time, :tags, :logs
|
7
|
+
attr_reader :context, :start_time, :tags, :logs, :references
|
8
8
|
|
9
9
|
# Creates a new {Span}
|
10
10
|
#
|
@@ -13,13 +13,21 @@ module Zipkin
|
|
13
13
|
# @param collector [Collector] the span collector
|
14
14
|
#
|
15
15
|
# @return [Span] a new Span
|
16
|
-
def initialize(
|
16
|
+
def initialize(
|
17
|
+
context,
|
18
|
+
operation_name,
|
19
|
+
collector,
|
20
|
+
start_time: Time.now,
|
21
|
+
tags: {},
|
22
|
+
references: nil
|
23
|
+
)
|
17
24
|
@context = context
|
18
25
|
@operation_name = operation_name
|
19
26
|
@collector = collector
|
20
27
|
@start_time = start_time
|
21
28
|
@tags = tags
|
22
29
|
@logs = []
|
30
|
+
@references = references
|
23
31
|
end
|
24
32
|
|
25
33
|
# Set a tag value on this span
|
data/lib/zipkin/tracer.rb
CHANGED
@@ -60,7 +60,12 @@ module Zipkin
|
|
60
60
|
# @param operation_name [String] The operation name for the Span
|
61
61
|
# @param child_of [SpanContext, Span] SpanContext that acts as a parent to
|
62
62
|
# the newly-started Span. If a Span instance is provided, its
|
63
|
-
# context is automatically substituted.
|
63
|
+
# context is automatically substituted. See [Reference] for more
|
64
|
+
# information.
|
65
|
+
#
|
66
|
+
# If specified, the `references` parameter must be omitted.
|
67
|
+
# @param references [Array<Reference>] An array of reference
|
68
|
+
# objects that identify one or more parent SpanContexts.<Paste>
|
64
69
|
# @param start_time [Time] When the Span started, if not now
|
65
70
|
# @param tags [Hash] Tags to assign to the Span at start time
|
66
71
|
# @param ignore_active_scope [Boolean] whether to create an implicit
|
@@ -71,10 +76,12 @@ module Zipkin
|
|
71
76
|
child_of: nil,
|
72
77
|
start_time: Time.now,
|
73
78
|
tags: {},
|
79
|
+
references: nil,
|
74
80
|
ignore_active_scope: false,
|
75
81
|
**)
|
76
82
|
context = prepare_span_context(
|
77
83
|
child_of: child_of,
|
84
|
+
references: references,
|
78
85
|
ignore_active_scope: ignore_active_scope
|
79
86
|
)
|
80
87
|
Span.new(
|
@@ -82,6 +89,7 @@ module Zipkin
|
|
82
89
|
operation_name,
|
83
90
|
@collector,
|
84
91
|
start_time: start_time,
|
92
|
+
references: references,
|
85
93
|
tags: tags
|
86
94
|
)
|
87
95
|
end
|
@@ -203,20 +211,39 @@ module Zipkin
|
|
203
211
|
)
|
204
212
|
end
|
205
213
|
|
206
|
-
def prepare_span_context(child_of:, ignore_active_scope:)
|
207
|
-
|
208
|
-
|
209
|
-
|
214
|
+
def prepare_span_context(child_of:, references:, ignore_active_scope:)
|
215
|
+
context =
|
216
|
+
context_from_child_of(child_of) ||
|
217
|
+
context_from_references(references) ||
|
218
|
+
context_from_active_scope(ignore_active_scope)
|
219
|
+
|
220
|
+
if context
|
221
|
+
SpanContext.create_from_parent_context(context)
|
222
|
+
else
|
223
|
+
SpanContext.create_parent_context
|
210
224
|
end
|
225
|
+
end
|
211
226
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
227
|
+
def context_from_child_of(child_of)
|
228
|
+
return nil unless child_of
|
229
|
+
child_of.respond_to?(:context) ? child_of.context : child_of
|
230
|
+
end
|
231
|
+
|
232
|
+
def context_from_references(references)
|
233
|
+
return nil if !references || references.none?
|
234
|
+
|
235
|
+
# Prefer CHILD_OF reference if present
|
236
|
+
ref = references.detect do |reference|
|
237
|
+
reference.type == OpenTracing::Reference::CHILD_OF
|
217
238
|
end
|
239
|
+
(ref || references[0]).context
|
240
|
+
end
|
241
|
+
|
242
|
+
def context_from_active_scope(ignore_active_scope)
|
243
|
+
return if ignore_active_scope
|
218
244
|
|
219
|
-
|
245
|
+
active_scope = @scope_manager.active
|
246
|
+
active_scope.span.context if active_scope
|
220
247
|
end
|
221
248
|
end
|
222
249
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
require 'zipkin/tracer'
|
7
|
+
|
8
|
+
url = ENV['ZIPKIN_URL'] || 'http://localhost:9411'
|
9
|
+
|
10
|
+
tracer1 = Zipkin::Tracer.build(url: url, service_name: 'test-service')
|
11
|
+
tracer2 = Zipkin::Tracer.build(url: url, service_name: 'downstream-service')
|
12
|
+
|
13
|
+
rpc_span = tracer1.start_span(
|
14
|
+
'receive request',
|
15
|
+
tags: { 'span.kind' => 'server' }
|
16
|
+
)
|
17
|
+
sleep 0.1
|
18
|
+
rpc_span.log_kv(event: 'woop di doop', count: 5)
|
19
|
+
sleep 1
|
20
|
+
|
21
|
+
async_request_span = tracer1.start_span(
|
22
|
+
'request async action',
|
23
|
+
references: [
|
24
|
+
OpenTracing::Reference.child_of(rpc_span.context)
|
25
|
+
],
|
26
|
+
tags: { 'span.kind' => 'producer' }
|
27
|
+
)
|
28
|
+
sleep 0.1
|
29
|
+
|
30
|
+
async_request_span.finish
|
31
|
+
rpc_span.finish
|
32
|
+
|
33
|
+
sleep 0.5
|
34
|
+
|
35
|
+
async_span = tracer2.start_span(
|
36
|
+
'async span started after rpc span',
|
37
|
+
references: [
|
38
|
+
OpenTracing::Reference.follows_from(async_request_span.context)
|
39
|
+
],
|
40
|
+
tags: {
|
41
|
+
'span.kind' => 'consumer',
|
42
|
+
'peer.service' => 'downstream-service'
|
43
|
+
}
|
44
|
+
)
|
45
|
+
sleep 0.3 # emulate network delay
|
46
|
+
async_span.finish
|
47
|
+
|
48
|
+
tracer1.stop
|
49
|
+
tracer2.stop
|
50
|
+
|
51
|
+
puts 'Finished'
|
data/zipkin.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SaleMove TechMovers
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/zipkin/span_context.rb
|
141
141
|
- lib/zipkin/trace_id.rb
|
142
142
|
- lib/zipkin/tracer.rb
|
143
|
+
- script/create_follows_from_trace
|
143
144
|
- script/create_trace
|
144
145
|
- zipkin.gemspec
|
145
146
|
homepage: ''
|