lightstep 0.15.1 → 0.16.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
  SHA256:
3
- metadata.gz: 5e9f8988ff2ee9b867440d0fee9aa30357df0aed33e5daa92c48e338ad386624
4
- data.tar.gz: dea73009fd576d64f80efac982533e8b1291bb8c45cf580430f36bd188eac60f
3
+ metadata.gz: 2fbca3799da8034df47aa8f310c16da459bcf5492500330576c81c4f0df63615
4
+ data.tar.gz: 7711d6bdac49561ab320f9a0f77de98fd9d6b2140daf0506ac3c51f0ec5da0cb
5
5
  SHA512:
6
- metadata.gz: be197fd10bfd6fc23bbc41e1016749ce7bac73149e57830a83ffc81a4bbed964e4dcdbb326cfde1dd2e75335e9ece218e77749536c5cb7ec6f246762013266aa
7
- data.tar.gz: 84d6dcbfbddb2b3fe7bfc4c88bbd43435ca8a50ae818b07752a7961dfa173d492f80ff0b4c0e95e1460cd32a3385a6a41288af0f5e13ce35df838ba3bca6c4fd
6
+ metadata.gz: e7943954fd04df21d5d7cf3fc5153374bf8e1f6d49a836da52b193bd727b3c0d4e085bd4612867f2ca4df259d6bc48e6a315626986298b2911309125e2bc07cd
7
+ data.tar.gz: e6f70b42fd03866cd00b845727a1765e0d04a49e67bd2c1da61cb23402eeda6d0a3443786d51bd3a7523a69eaecdfc875b429cb981f6e01bb541498fd60c7686
@@ -4,9 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## v0.16.0
8
+ ### Added
9
+ - The tracer now supports B3 context propagation. Propagation can be set by using the `propagator` keyword argument to `LightStep.configure`. Valid values are `:lightstep` (default), and `:b3`.
10
+
7
11
  ## v0.15.1
8
12
  ### Fixed
9
- - The tracer now supports B3 context propagation. Propagation can be set by using the `propagator` keyword argument to `LightStep.configure`. Valid values are `:lightstep` (default), and `:b3`.
10
13
  - The tracer now closes the active scope or finishes the active span even if an error is raised from the yielded code.
11
14
 
12
15
  ### Unreleased
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lightstep (0.15.1)
4
+ lightstep (0.16.0)
5
5
  concurrent-ruby (~> 1.0)
6
6
  opentracing (~> 0.5.0)
7
7
 
data/README.md CHANGED
@@ -27,6 +27,9 @@ Or install it yourself as:
27
27
  # Initialize the singleton tracer
28
28
  LightStep.configure(component_name: 'lightstep/ruby/example', access_token: 'your_access_token')
29
29
 
30
+ # Specify a propagation format (options are :lightstep (default) and :b3)
31
+ LightStep.configure(component_name: 'lightstep/ruby/example', access_token: 'your_access_token', propagator: :b3)
32
+
30
33
  # Create a basic span and attach a log to the span
31
34
  span = LightStep.start_span('my_span')
32
35
  span.log(event: 'hello world', count: 42)
@@ -6,14 +6,15 @@ require 'lightstep/propagation/b3_propagator'
6
6
  module LightStep
7
7
  module Propagation
8
8
  PROPAGATOR_MAP = {
9
- lightstep: LightStepPropagator
9
+ lightstep: LightStepPropagator,
10
+ b3: B3Propagator
10
11
  }
11
12
 
12
13
  class << self
13
14
  # Constructs a propagator instance from the given propagator name. If the
14
15
  # name is unknown returns the LightStepPropagator as a default
15
16
  #
16
- # @param [Symbol, String] propagator_name
17
+ # @param [Symbol, String] propagator_name One of :lightstep or :b3
17
18
  # @return [Propagator]
18
19
  def [](propagator_name)
19
20
  klass = PROPAGATOR_MAP[propagator_name.to_sym] || LightStepPropagator
@@ -7,11 +7,14 @@ module LightStep
7
7
  CARRIER_SPAN_ID = 'x-b3-spanid'
8
8
  CARRIER_TRACE_ID = 'x-b3-traceid'
9
9
  CARRIER_SAMPLED = 'x-b3-sampled'
10
+ TRUE_VALUES = %w[1 true].freeze
10
11
 
11
12
  private
12
13
 
14
+ # propagate the full 128-bit trace id if the original id was 128-bit,
15
+ # use the 64 bit id otherwise
13
16
  def trace_id_from_ctx(ctx)
14
- ctx.trace_id16
17
+ ctx.id_truncated? ? ctx.trace_id128 : ctx.trace_id64
15
18
  end
16
19
 
17
20
  def sampled_flag_from_ctx(ctx)
@@ -19,7 +22,7 @@ module LightStep
19
22
  end
20
23
 
21
24
  def sampled_flag_from_carrier(carrier)
22
- carrier[self.class::CARRIER_SAMPLED] == '1' ? true : false
25
+ TRUE_VALUES.include?(carrier[self.class::CARRIER_SAMPLED])
23
26
  end
24
27
  end
25
28
  end
@@ -56,7 +56,11 @@ module LightStep
56
56
  ref = ref.context if (Span === ref)
57
57
 
58
58
  if SpanContext === ref
59
- @context = SpanContext.new(id: LightStep.guid, trace_id: ref.trace_id, sampled: ref.sampled?)
59
+ @context = SpanContext.new(
60
+ id: LightStep.guid,
61
+ trace_id: ref.trace_id,
62
+ trace_id_upper64: ref.trace_id_upper64,
63
+ sampled: ref.sampled?)
60
64
  set_baggage(ref.baggage)
61
65
  set_tag(:parent_span_guid, ref.id)
62
66
  else
@@ -83,6 +87,7 @@ module LightStep
83
87
  @context = SpanContext.new(
84
88
  id: context.id,
85
89
  trace_id: context.trace_id,
90
+ trace_id_upper64: context.trace_id_upper64,
86
91
  sampled: context.sampled?,
87
92
  baggage: context.baggage.merge({key => value})
88
93
  )
@@ -95,6 +100,7 @@ module LightStep
95
100
  @context = SpanContext.new(
96
101
  id: context.id,
97
102
  trace_id: context.trace_id,
103
+ trace_id_upper64: context.trace_id_upper64,
98
104
  sampled: context.sampled?,
99
105
  baggage: baggage
100
106
  )
@@ -3,29 +3,43 @@
3
3
  module LightStep
4
4
  # SpanContext holds the data for a span that gets inherited to child spans
5
5
  class SpanContext
6
- attr_reader :id, :trace_id, :trace_id16, :sampled, :baggage
6
+ attr_reader :id, :trace_id, :trace_id_upper64, :sampled, :baggage
7
+ alias_method :trace_id64, :trace_id
7
8
  alias_method :sampled?, :sampled
8
9
 
9
10
  ZERO_PADDING = '0' * 16
10
11
 
11
- def initialize(id:, trace_id:, sampled: true, baggage: {})
12
+ def initialize(id:, trace_id:, trace_id_upper64: nil, sampled: true, baggage: {})
12
13
  @id = id.freeze
13
- @trace_id16 = pad_id(trace_id).freeze
14
14
  @trace_id = truncate_id(trace_id).freeze
15
+ @trace_id_upper64 = trace_id_upper64 || extended_bits(trace_id).freeze
15
16
  @sampled = sampled
16
17
  @baggage = baggage.freeze
17
18
  end
18
19
 
20
+ # Lazily initializes and returns a 128-bit representation of a 64-bit trace id
21
+ def trace_id128
22
+ @trace_id128 ||= "#{trace_id_upper64 || ZERO_PADDING}#{trace_id}"
23
+ end
24
+
25
+ # Returns true if the original trace_id was 128 bits
26
+ def id_truncated?
27
+ !@trace_id_upper64.nil?
28
+ end
29
+
19
30
  private
20
31
 
32
+ # Truncates an id to 64 bits
21
33
  def truncate_id(id)
22
34
  return id unless id && id.size == 32
23
- id[0...16]
35
+ id[16..-1]
24
36
  end
25
37
 
26
- def pad_id(id)
27
- return id unless id && id.size == 16
28
- "#{id}#{ZERO_PADDING}"
38
+ # Returns the most significant 64 bits of a 128 bit id or nil if the id
39
+ # is 64 bits
40
+ def extended_bits(id)
41
+ return unless id && id.size == 32
42
+ id[0...16]
29
43
  end
30
44
  end
31
45
  end
@@ -28,7 +28,7 @@ module LightStep
28
28
  # @param access_token [String] The project access token when pushing to LightStep
29
29
  # @param transport [LightStep::Transport] How the data should be transported
30
30
  # @param tags [Hash] Tracer-level tags
31
- # @param propagator [Propagator] :lightstep is the only supported option
31
+ # @param propagator [Propagator] Symbol one of :lightstep, :b3 indicating the propagator
32
32
  # to use
33
33
  # @return LightStep::Tracer
34
34
  # @raise LightStep::ConfigurationError if the group name or access token is not a valid string.
@@ -1,3 +1,3 @@
1
1
  module LightStep
2
- VERSION = '0.15.1'.freeze
2
+ VERSION = '0.16.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightstep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lightstep
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby