jaeger-client 0.5.0 → 0.6.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: 180ed5153f692c630fd0e0006b3d6265c5839875
4
- data.tar.gz: 98dea74437333796b07bf81afba0558652b51623
3
+ metadata.gz: 6c3b896f0a1516378cf00ee5a08bc86b9766842a
4
+ data.tar.gz: e7f411f2dd0850fd1d4267616c6e6cdda7766847
5
5
  SHA512:
6
- metadata.gz: ef49bfeb6aee4d16534c256580efe859d6468f7f68c748db31166c10ba700416a8035d18c51d26d5b863dccae71c036f6e7a3645eb49c323d2a1ed80a9507f0f
7
- data.tar.gz: 1965becd08d299d65067e503e64d926dfffe95b216b306334c562c3a9db703eba2bc4171e53586c4b180e262a3fda7bb9ceed38ec9b021ba475b680e5728ebe9
6
+ metadata.gz: 2f1d3b40879729e56de34b71bab0881d9c3d3afab4f11b523392a21392bfeb992e3a602c3cc7907d5f905eafd4f5130d27e4383602b8cc98e1053c2a49f12e5c
7
+ data.tar.gz: e757205635c33ff2e40630c07746f0993fd234c00742ac1257ab5a914659394b45d24f3d5896f72ab7b3c2a3840383fdeb8d6790a53eff1b67506e2577175bf5
@@ -20,7 +20,7 @@ module Jaeger
20
20
  'spanId' => context.span_id,
21
21
  'parentSpanId' => context.parent_id,
22
22
  'operationName' => span.operation_name,
23
- 'references' => [],
23
+ 'references' => build_references(span.references || []),
24
24
  'flags' => context.flags,
25
25
  'startTime' => start_ts,
26
26
  'duration' => duration,
@@ -35,6 +35,17 @@ module Jaeger
35
35
 
36
36
  private
37
37
 
38
+ def build_references(references)
39
+ references.map do |ref|
40
+ Jaeger::Thrift::SpanRef.new(
41
+ 'refType' => span_ref_type(ref.type),
42
+ 'traceIdLow' => ref.context.trace_id,
43
+ 'traceIdHigh' => 0,
44
+ 'spanId' => ref.context.span_id
45
+ )
46
+ end
47
+ end
48
+
38
49
  def build_timestamps(span, end_time)
39
50
  start_ts = (span.start_time.to_f * 1_000_000).to_i
40
51
  end_ts = (end_time.to_f * 1_000_000).to_i
@@ -42,6 +53,18 @@ module Jaeger
42
53
  [start_ts, duration]
43
54
  end
44
55
 
56
+ def span_ref_type(type)
57
+ case type
58
+ when OpenTracing::Reference::CHILD_OF
59
+ Jaeger::Thrift::SpanRefType::CHILD_OF
60
+ when OpenTracing::Reference::FOLLOWS_FROM
61
+ Jaeger::Thrift::SpanRefType::FOLLOWS_FROM
62
+ else
63
+ warn "Jaeger::Client with format #{type} is not supported yet"
64
+ nil
65
+ end
66
+ end
67
+
45
68
  class Buffer
46
69
  def initialize
47
70
  @buffer = []
@@ -8,20 +8,21 @@ module Jaeger
8
8
  class Span
9
9
  attr_accessor :operation_name
10
10
 
11
- attr_reader :context, :start_time, :tags, :logs
11
+ attr_reader :context, :start_time, :references, :tags, :logs
12
12
 
13
13
  # Creates a new {Span}
14
14
  #
15
15
  # @param context [SpanContext] the context of the span
16
- # @param context [String] the operation name
16
+ # @param operation_name [String] the operation name
17
17
  # @param collector [Collector] span collector
18
18
  #
19
19
  # @return [Span] a new Span
20
- def initialize(context, operation_name, collector, start_time: Time.now, tags: {})
20
+ def initialize(context, operation_name, collector, start_time: Time.now, references: [], tags: {})
21
21
  @context = context
22
22
  @operation_name = operation_name
23
23
  @collector = collector
24
24
  @start_time = start_time
25
+ @references = references
25
26
  @tags = tags.map { |key, value| ThriftTagBuilder.build(key, value) }
26
27
  @logs = []
27
28
  end
@@ -34,7 +34,10 @@ module Jaeger
34
34
  # @param operation_name [String] The operation name for the Span
35
35
  # @param child_of [SpanContext, Span] SpanContext that acts as a parent to
36
36
  # the newly-started Span. If a Span instance is provided, its
37
- # context is automatically substituted.
37
+ # context is automatically substituted. See [Reference] for more
38
+ # information.
39
+ #
40
+ # If specified, the `references` parameter must be omitted.
38
41
  # @param references [Array<Reference>] An array of reference
39
42
  # objects that identify one or more parent SpanContexts.
40
43
  # @param start_time [Time] When the Span started, if not now
@@ -52,6 +55,7 @@ module Jaeger
52
55
  **)
53
56
  context = prepare_span_context(
54
57
  child_of: child_of,
58
+ references: references,
55
59
  ignore_active_scope: ignore_active_scope
56
60
  )
57
61
  Span.new(
@@ -59,6 +63,7 @@ module Jaeger
59
63
  operation_name,
60
64
  @collector,
61
65
  start_time: start_time,
66
+ references: references,
62
67
  tags: tags.merge(
63
68
  :'sampler.type' => @sampler.type,
64
69
  :'sampler.param' => @sampler.param
@@ -182,20 +187,39 @@ module Jaeger
182
187
  (num & ~mask) - (num & mask)
183
188
  end
184
189
 
185
- def prepare_span_context(child_of:, ignore_active_scope:)
186
- if child_of
187
- parent_context = child_of.respond_to?(:context) ? child_of.context : child_of
188
- return SpanContext.create_from_parent_context(parent_context)
190
+ def prepare_span_context(child_of:, references:, ignore_active_scope:)
191
+ context =
192
+ context_from_child_of(child_of) ||
193
+ context_from_references(references) ||
194
+ context_from_active_scope(ignore_active_scope)
195
+
196
+ if context
197
+ SpanContext.create_from_parent_context(context)
198
+ else
199
+ SpanContext.create_parent_context(@sampler)
189
200
  end
201
+ end
190
202
 
191
- unless ignore_active_scope
192
- active_scope = @scope_manager.active
193
- if active_scope
194
- return SpanContext.create_from_parent_context(active_scope.span.context)
195
- end
203
+ def context_from_child_of(child_of)
204
+ return nil unless child_of
205
+ child_of.respond_to?(:context) ? child_of.context : child_of
206
+ end
207
+
208
+ def context_from_references(references)
209
+ return nil if !references || references.none?
210
+
211
+ # Prefer CHILD_OF reference if present
212
+ ref = references.detect do |reference|
213
+ reference.type == OpenTracing::Reference::CHILD_OF
196
214
  end
215
+ (ref || references[0]).context
216
+ end
217
+
218
+ def context_from_active_scope(ignore_active_scope)
219
+ return if ignore_active_scope
197
220
 
198
- SpanContext.create_parent_context(@sampler)
221
+ active_scope = @scope_manager.active
222
+ active_scope.span.context if active_scope
199
223
  end
200
224
  end
201
225
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jaeger
4
4
  module Client
5
- VERSION = '0.5.0'.freeze
5
+ VERSION = '0.6.0'.freeze
6
6
  end
7
7
  end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler'
4
+ Bundler.setup
5
+
6
+ require 'jaeger/client'
7
+
8
+ host = ENV['JAEGER_HOST'] || '127.0.0.1'
9
+ port = ENV['JAEGER_HOST'] || 6831
10
+
11
+ tracer1 = Jaeger::Client.build(host: host, port: port.to_i, service_name: 'test-service', flush_interval: 1)
12
+ tracer2 = Jaeger::Client.build(host: host, port: port.to_i, service_name: 'downstream-service', flush_interval: 1)
13
+
14
+ rpc_span = tracer1.start_span(
15
+ 'receive request',
16
+ tags: { 'span.kind' => 'server' }
17
+ )
18
+ sleep 0.1
19
+ rpc_span.log_kv(event: 'woop di doop', count: 5)
20
+ sleep 1
21
+
22
+ async_request_span = tracer1.start_span(
23
+ 'request async action',
24
+ references: [
25
+ OpenTracing::Reference.child_of(rpc_span.context)
26
+ ],
27
+ tags: { 'span.kind' => 'producer' }
28
+ )
29
+ sleep 0.1
30
+
31
+ async_request_span.finish
32
+ rpc_span.finish
33
+
34
+ sleep 0.5
35
+
36
+ async_span = tracer2.start_span(
37
+ 'async span started after rpc span',
38
+ references: [
39
+ OpenTracing::Reference.follows_from(async_request_span.context)
40
+ ],
41
+ tags: {
42
+ 'span.kind' => 'consumer',
43
+ 'peer.service' => 'downstream-service'
44
+ }
45
+ )
46
+ sleep 0.3 # emulate network delay
47
+ async_span.finish
48
+
49
+ tracer1.stop
50
+ tracer2.stop
51
+
52
+ puts 'Finished'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jaeger-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
@@ -145,6 +145,7 @@ files:
145
145
  - lib/jaeger/client/udp_sender.rb
146
146
  - lib/jaeger/client/udp_sender/transport.rb
147
147
  - lib/jaeger/client/version.rb
148
+ - script/create_follows_from_trace
148
149
  - script/create_trace
149
150
  - thrift/agent.thrift
150
151
  - thrift/gen-rb/jaeger/thrift/agent.rb