lightstep 0.15.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +21 -20
- data/CHANGELOG.md +9 -1
- data/Gemfile.lock +1 -1
- data/lib/lightstep/propagation.rb +24 -0
- data/lib/lightstep/propagation/b3_propagator.rb +26 -0
- data/lib/lightstep/propagation/lightstep_propagator.rb +127 -0
- data/lib/lightstep/span.rb +3 -1
- data/lib/lightstep/span_context.rb +22 -3
- data/lib/lightstep/tracer.rb +34 -97
- data/lib/lightstep/version.rb +1 -1
- metadata +6 -5
- data/circle.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e9f8988ff2ee9b867440d0fee9aa30357df0aed33e5daa92c48e338ad386624
|
4
|
+
data.tar.gz: dea73009fd576d64f80efac982533e8b1291bb8c45cf580430f36bd188eac60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be197fd10bfd6fc23bbc41e1016749ce7bac73149e57830a83ffc81a4bbed964e4dcdbb326cfde1dd2e75335e9ece218e77749536c5cb7ec6f246762013266aa
|
7
|
+
data.tar.gz: 84d6dcbfbddb2b3fe7bfc4c88bbd43435ca8a50ae818b07752a7961dfa173d492f80ff0b4c0e95e1460cd32a3385a6a41288af0f5e13ce35df838ba3bca6c4fd
|
data/.circleci/config.yml
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
version: 2
|
2
2
|
|
3
3
|
jobs:
|
4
|
-
test:
|
4
|
+
test-ruby-24:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.4-stretch
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- run: gem install --no-document bundler && bundle install --jobs=3 --retry=3
|
10
|
+
- run: bundle exec rake
|
11
|
+
test-ruby-25:
|
5
12
|
docker:
|
6
|
-
- image: circleci/ruby:2
|
13
|
+
- image: circleci/ruby:2.5-stretch
|
7
14
|
steps:
|
8
15
|
- checkout
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
source $BASH_ENV
|
19
|
-
- run: bundle
|
20
|
-
- save_cache:
|
21
|
-
paths:
|
22
|
-
- ~/project/.bundler_cache
|
23
|
-
key: gem-cache-v2-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
24
|
-
- run: make test
|
16
|
+
- run: gem install --no-document bundler && bundle install --jobs=3 --retry=3
|
17
|
+
- run: bundle exec rake
|
18
|
+
test-ruby-26:
|
19
|
+
docker:
|
20
|
+
- image: circleci/ruby:2.6-stretch
|
21
|
+
steps:
|
22
|
+
- checkout
|
23
|
+
- run: gem install --no-document bundler && bundle install --jobs=3 --retry=3
|
24
|
+
- run: bundle exec rake
|
25
25
|
|
26
26
|
workflows:
|
27
27
|
version: 2
|
28
28
|
test:
|
29
29
|
jobs:
|
30
|
-
- test
|
31
|
-
|
30
|
+
- test-ruby-24
|
31
|
+
- test-ruby-25
|
32
|
+
- test-ruby-26
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,15 @@ 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
|
-
##
|
7
|
+
## v0.15.1
|
8
|
+
### 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
|
+
- The tracer now closes the active scope or finishes the active span even if an error is raised from the yielded code.
|
11
|
+
|
12
|
+
### Unreleased
|
13
|
+
- In-progress B3 support
|
14
|
+
|
15
|
+
## v0.15.0
|
8
16
|
### Added
|
9
17
|
- A Changelog
|
10
18
|
- Now supports Span#log_kv
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lightstep/propagation/lightstep_propagator'
|
4
|
+
require 'lightstep/propagation/b3_propagator'
|
5
|
+
|
6
|
+
module LightStep
|
7
|
+
module Propagation
|
8
|
+
PROPAGATOR_MAP = {
|
9
|
+
lightstep: LightStepPropagator
|
10
|
+
}
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Constructs a propagator instance from the given propagator name. If the
|
14
|
+
# name is unknown returns the LightStepPropagator as a default
|
15
|
+
#
|
16
|
+
# @param [Symbol, String] propagator_name
|
17
|
+
# @return [Propagator]
|
18
|
+
def [](propagator_name)
|
19
|
+
klass = PROPAGATOR_MAP[propagator_name.to_sym] || LightStepPropagator
|
20
|
+
klass.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
module LightStep
|
4
|
+
module Propagation
|
5
|
+
class B3Propagator < LightStepPropagator
|
6
|
+
CARRIER_TRACER_STATE_PREFIX = 'x-b3-'
|
7
|
+
CARRIER_SPAN_ID = 'x-b3-spanid'
|
8
|
+
CARRIER_TRACE_ID = 'x-b3-traceid'
|
9
|
+
CARRIER_SAMPLED = 'x-b3-sampled'
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def trace_id_from_ctx(ctx)
|
14
|
+
ctx.trace_id16
|
15
|
+
end
|
16
|
+
|
17
|
+
def sampled_flag_from_ctx(ctx)
|
18
|
+
ctx.sampled? ? '1' : '0'
|
19
|
+
end
|
20
|
+
|
21
|
+
def sampled_flag_from_carrier(carrier)
|
22
|
+
carrier[self.class::CARRIER_SAMPLED] == '1' ? true : false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
module LightStep
|
4
|
+
module Propagation
|
5
|
+
class LightStepPropagator
|
6
|
+
CARRIER_TRACER_STATE_PREFIX = 'ot-tracer-'
|
7
|
+
CARRIER_SPAN_ID = 'ot-tracer-spanid'
|
8
|
+
CARRIER_TRACE_ID = 'ot-tracer-traceid'
|
9
|
+
CARRIER_SAMPLED = 'ot-tracer-sampled'
|
10
|
+
CARRIER_BAGGAGE_PREFIX = 'ot-baggage-'
|
11
|
+
|
12
|
+
# Inject a SpanContext into the given carrier
|
13
|
+
#
|
14
|
+
# @param spancontext [SpanContext]
|
15
|
+
# @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY]
|
16
|
+
# @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
|
17
|
+
def inject(span_context, format, carrier)
|
18
|
+
case format
|
19
|
+
when OpenTracing::FORMAT_TEXT_MAP
|
20
|
+
inject_to_text_map(span_context, carrier)
|
21
|
+
when OpenTracing::FORMAT_BINARY
|
22
|
+
warn 'Binary inject format not yet implemented'
|
23
|
+
when OpenTracing::FORMAT_RACK
|
24
|
+
inject_to_rack(span_context, carrier)
|
25
|
+
else
|
26
|
+
warn 'Unknown inject format'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Extract a SpanContext from a carrier
|
31
|
+
# @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK]
|
32
|
+
# @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
|
33
|
+
# @return [SpanContext] the extracted SpanContext or nil if none could be found
|
34
|
+
def extract(format, carrier)
|
35
|
+
case format
|
36
|
+
when OpenTracing::FORMAT_TEXT_MAP
|
37
|
+
extract_from_text_map(carrier)
|
38
|
+
when OpenTracing::FORMAT_BINARY
|
39
|
+
warn 'Binary join format not yet implemented'
|
40
|
+
nil
|
41
|
+
when OpenTracing::FORMAT_RACK
|
42
|
+
extract_from_rack(carrier)
|
43
|
+
else
|
44
|
+
warn 'Unknown join format'
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def inject_to_text_map(span_context, carrier)
|
52
|
+
if trace_id = trace_id_from_ctx(span_context)
|
53
|
+
carrier[self.class::CARRIER_TRACE_ID] = trace_id
|
54
|
+
end
|
55
|
+
carrier[self.class::CARRIER_SPAN_ID] = span_context.id
|
56
|
+
carrier[self.class::CARRIER_SAMPLED] = sampled_flag_from_ctx(span_context)
|
57
|
+
|
58
|
+
span_context.baggage.each do |key, value|
|
59
|
+
carrier[self.class::CARRIER_BAGGAGE_PREFIX + key] = value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def extract_from_text_map(carrier)
|
64
|
+
# If the carrier does not have both the span_id and trace_id key
|
65
|
+
# skip the processing and just return a normal span
|
66
|
+
if !carrier.has_key?(self.class::CARRIER_SPAN_ID) || !carrier.has_key?(self.class::CARRIER_TRACE_ID)
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
|
70
|
+
baggage = carrier.reduce({}) do |baggage, (key, value)|
|
71
|
+
if key.start_with?(self.class::CARRIER_BAGGAGE_PREFIX)
|
72
|
+
plain_key = key.to_s[self.class::CARRIER_BAGGAGE_PREFIX.length..key.to_s.length]
|
73
|
+
baggage[plain_key] = value
|
74
|
+
end
|
75
|
+
baggage
|
76
|
+
end
|
77
|
+
|
78
|
+
SpanContext.new(
|
79
|
+
id: carrier[self.class::CARRIER_SPAN_ID],
|
80
|
+
trace_id: carrier[self.class::CARRIER_TRACE_ID],
|
81
|
+
sampled: sampled_flag_from_carrier(carrier),
|
82
|
+
baggage: baggage,
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def inject_to_rack(span_context, carrier)
|
87
|
+
if trace_id = trace_id_from_ctx(span_context)
|
88
|
+
carrier[self.class::CARRIER_TRACE_ID] = trace_id
|
89
|
+
end
|
90
|
+
carrier[self.class::CARRIER_SPAN_ID] = span_context.id
|
91
|
+
carrier[self.class::CARRIER_SAMPLED] = sampled_flag_from_ctx(span_context)
|
92
|
+
|
93
|
+
span_context.baggage.each do |key, value|
|
94
|
+
if key =~ /[^A-Za-z0-9\-_]/
|
95
|
+
# TODO: log the error internally
|
96
|
+
next
|
97
|
+
end
|
98
|
+
carrier[self.class::CARRIER_BAGGAGE_PREFIX + key] = value
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def extract_from_rack(env)
|
103
|
+
extract_from_text_map(env.reduce({}){|memo, (raw_header, value)|
|
104
|
+
header = raw_header.to_s.gsub(/^HTTP_/, '')
|
105
|
+
header.tr!('_', '-')
|
106
|
+
header.downcase!
|
107
|
+
|
108
|
+
memo[header] = value if header.start_with?(self.class::CARRIER_TRACER_STATE_PREFIX,
|
109
|
+
self.class::CARRIER_BAGGAGE_PREFIX)
|
110
|
+
memo
|
111
|
+
})
|
112
|
+
end
|
113
|
+
|
114
|
+
def trace_id_from_ctx(ctx)
|
115
|
+
ctx.trace_id
|
116
|
+
end
|
117
|
+
|
118
|
+
def sampled_flag_from_ctx(_)
|
119
|
+
'true'
|
120
|
+
end
|
121
|
+
|
122
|
+
def sampled_flag_from_carrier(_)
|
123
|
+
true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/lightstep/span.rb
CHANGED
@@ -56,7 +56,7 @@ 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)
|
59
|
+
@context = SpanContext.new(id: LightStep.guid, trace_id: ref.trace_id, sampled: ref.sampled?)
|
60
60
|
set_baggage(ref.baggage)
|
61
61
|
set_tag(:parent_span_guid, ref.id)
|
62
62
|
else
|
@@ -83,6 +83,7 @@ module LightStep
|
|
83
83
|
@context = SpanContext.new(
|
84
84
|
id: context.id,
|
85
85
|
trace_id: context.trace_id,
|
86
|
+
sampled: context.sampled?,
|
86
87
|
baggage: context.baggage.merge({key => value})
|
87
88
|
)
|
88
89
|
self
|
@@ -94,6 +95,7 @@ module LightStep
|
|
94
95
|
@context = SpanContext.new(
|
95
96
|
id: context.id,
|
96
97
|
trace_id: context.trace_id,
|
98
|
+
sampled: context.sampled?,
|
97
99
|
baggage: baggage
|
98
100
|
)
|
99
101
|
end
|
@@ -1,12 +1,31 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
1
3
|
module LightStep
|
2
4
|
# SpanContext holds the data for a span that gets inherited to child spans
|
3
5
|
class SpanContext
|
4
|
-
attr_reader :id, :trace_id, :baggage
|
6
|
+
attr_reader :id, :trace_id, :trace_id16, :sampled, :baggage
|
7
|
+
alias_method :sampled?, :sampled
|
8
|
+
|
9
|
+
ZERO_PADDING = '0' * 16
|
5
10
|
|
6
|
-
def initialize(id:, trace_id:, baggage: {})
|
11
|
+
def initialize(id:, trace_id:, sampled: true, baggage: {})
|
7
12
|
@id = id.freeze
|
8
|
-
@
|
13
|
+
@trace_id16 = pad_id(trace_id).freeze
|
14
|
+
@trace_id = truncate_id(trace_id).freeze
|
15
|
+
@sampled = sampled
|
9
16
|
@baggage = baggage.freeze
|
10
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def truncate_id(id)
|
22
|
+
return id unless id && id.size == 32
|
23
|
+
id[0...16]
|
24
|
+
end
|
25
|
+
|
26
|
+
def pad_id(id)
|
27
|
+
return id unless id && id.size == 16
|
28
|
+
"#{id}#{ZERO_PADDING}"
|
29
|
+
end
|
11
30
|
end
|
12
31
|
end
|
data/lib/lightstep/tracer.rb
CHANGED
@@ -5,6 +5,7 @@ require 'opentracing'
|
|
5
5
|
|
6
6
|
require 'lightstep/span'
|
7
7
|
require 'lightstep/reporter'
|
8
|
+
require 'lightstep/propagation'
|
8
9
|
require 'lightstep/transport/http_json'
|
9
10
|
require 'lightstep/transport/nil'
|
10
11
|
require 'lightstep/transport/callback'
|
@@ -14,6 +15,11 @@ module LightStep
|
|
14
15
|
class Error < LightStep::Error; end
|
15
16
|
class ConfigurationError < LightStep::Tracer::Error; end
|
16
17
|
|
18
|
+
DEFAULT_MAX_LOG_RECORDS = 1000
|
19
|
+
MIN_MAX_LOG_RECORDS = 1
|
20
|
+
DEFAULT_MAX_SPAN_RECORDS = 1000
|
21
|
+
MIN_MAX_SPAN_RECORDS = 1
|
22
|
+
|
17
23
|
attr_reader :access_token, :guid
|
18
24
|
|
19
25
|
# Initialize a new tracer. Either an access_token or a transport must be
|
@@ -22,10 +28,20 @@ module LightStep
|
|
22
28
|
# @param access_token [String] The project access token when pushing to LightStep
|
23
29
|
# @param transport [LightStep::Transport] How the data should be transported
|
24
30
|
# @param tags [Hash] Tracer-level tags
|
31
|
+
# @param propagator [Propagator] :lightstep is the only supported option
|
32
|
+
# to use
|
25
33
|
# @return LightStep::Tracer
|
26
34
|
# @raise LightStep::ConfigurationError if the group name or access token is not a valid string.
|
27
|
-
def initialize(component_name:,
|
28
|
-
|
35
|
+
def initialize(component_name:,
|
36
|
+
access_token: nil,
|
37
|
+
transport: nil,
|
38
|
+
tags: {},
|
39
|
+
propagator: :lightstep)
|
40
|
+
configure(component_name: component_name,
|
41
|
+
access_token: access_token,
|
42
|
+
transport: transport,
|
43
|
+
tags: tags,
|
44
|
+
propagator: propagator)
|
29
45
|
end
|
30
46
|
|
31
47
|
def max_log_records
|
@@ -111,7 +127,9 @@ module LightStep
|
|
111
127
|
|
112
128
|
scope_manager.activate(span: span, finish_on_close: finish_on_close).tap do |scope|
|
113
129
|
if block_given?
|
114
|
-
|
130
|
+
begin
|
131
|
+
return yield scope
|
132
|
+
ensure
|
115
133
|
scope.close
|
116
134
|
end
|
117
135
|
end
|
@@ -165,29 +183,23 @@ module LightStep
|
|
165
183
|
|
166
184
|
Span.new(span_options).tap do |span|
|
167
185
|
if block_given?
|
168
|
-
|
186
|
+
begin
|
187
|
+
return yield span
|
188
|
+
ensure
|
169
189
|
span.finish
|
170
190
|
end
|
171
191
|
end
|
172
192
|
end
|
173
193
|
end
|
174
194
|
|
195
|
+
|
175
196
|
# Inject a SpanContext into the given carrier
|
176
197
|
#
|
177
198
|
# @param spancontext [SpanContext]
|
178
199
|
# @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY]
|
179
200
|
# @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
|
180
201
|
def inject(span_context, format, carrier)
|
181
|
-
|
182
|
-
when OpenTracing::FORMAT_TEXT_MAP
|
183
|
-
inject_to_text_map(span_context, carrier)
|
184
|
-
when OpenTracing::FORMAT_BINARY
|
185
|
-
warn 'Binary inject format not yet implemented'
|
186
|
-
when OpenTracing::FORMAT_RACK
|
187
|
-
inject_to_rack(span_context, carrier)
|
188
|
-
else
|
189
|
-
warn 'Unknown inject format'
|
190
|
-
end
|
202
|
+
@propagator.inject(span_context, format, carrier)
|
191
203
|
end
|
192
204
|
|
193
205
|
# Extract a SpanContext from a carrier
|
@@ -195,18 +207,7 @@ module LightStep
|
|
195
207
|
# @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
|
196
208
|
# @return [SpanContext] the extracted SpanContext or nil if none could be found
|
197
209
|
def extract(format, carrier)
|
198
|
-
|
199
|
-
when OpenTracing::FORMAT_TEXT_MAP
|
200
|
-
extract_from_text_map(carrier)
|
201
|
-
when OpenTracing::FORMAT_BINARY
|
202
|
-
warn 'Binary join format not yet implemented'
|
203
|
-
nil
|
204
|
-
when OpenTracing::FORMAT_RACK
|
205
|
-
extract_from_rack(carrier)
|
206
|
-
else
|
207
|
-
warn 'Unknown join format'
|
208
|
-
nil
|
209
|
-
end
|
210
|
+
@propagator.extract(format, carrier)
|
210
211
|
end
|
211
212
|
|
212
213
|
# @return true if the tracer is enabled
|
@@ -243,7 +244,11 @@ module LightStep
|
|
243
244
|
|
244
245
|
protected
|
245
246
|
|
246
|
-
def configure(component_name:,
|
247
|
+
def configure(component_name:,
|
248
|
+
access_token: nil,
|
249
|
+
transport: nil, tags: {},
|
250
|
+
propagator: :lightstep)
|
251
|
+
|
247
252
|
raise ConfigurationError, "component_name must be a string" unless component_name.is_a?(String)
|
248
253
|
raise ConfigurationError, "component_name cannot be blank" if component_name.empty?
|
249
254
|
|
@@ -254,6 +259,8 @@ module LightStep
|
|
254
259
|
raise ConfigurationError, "you must provide an access token or a transport" if transport.nil?
|
255
260
|
raise ConfigurationError, "#{transport} is not a LightStep transport class" if !(LightStep::Transport::Base === transport)
|
256
261
|
|
262
|
+
@propagator = Propagation[propagator]
|
263
|
+
|
257
264
|
@guid = LightStep.guid
|
258
265
|
|
259
266
|
@reporter = LightStep::Reporter.new(
|
@@ -264,75 +271,5 @@ module LightStep
|
|
264
271
|
tags: tags
|
265
272
|
)
|
266
273
|
end
|
267
|
-
|
268
|
-
private
|
269
|
-
|
270
|
-
CARRIER_TRACER_STATE_PREFIX = 'ot-tracer-'.freeze
|
271
|
-
CARRIER_BAGGAGE_PREFIX = 'ot-baggage-'.freeze
|
272
|
-
|
273
|
-
CARRIER_SPAN_ID = (CARRIER_TRACER_STATE_PREFIX + 'spanid').freeze
|
274
|
-
CARRIER_TRACE_ID = (CARRIER_TRACER_STATE_PREFIX + 'traceid').freeze
|
275
|
-
CARRIER_SAMPLED = (CARRIER_TRACER_STATE_PREFIX + 'sampled').freeze
|
276
|
-
|
277
|
-
DEFAULT_MAX_LOG_RECORDS = 1000
|
278
|
-
MIN_MAX_LOG_RECORDS = 1
|
279
|
-
DEFAULT_MAX_SPAN_RECORDS = 1000
|
280
|
-
MIN_MAX_SPAN_RECORDS = 1
|
281
|
-
|
282
|
-
def inject_to_text_map(span_context, carrier)
|
283
|
-
carrier[CARRIER_SPAN_ID] = span_context.id
|
284
|
-
carrier[CARRIER_TRACE_ID] = span_context.trace_id unless span_context.trace_id.nil?
|
285
|
-
carrier[CARRIER_SAMPLED] = 'true'
|
286
|
-
|
287
|
-
span_context.baggage.each do |key, value|
|
288
|
-
carrier[CARRIER_BAGGAGE_PREFIX + key] = value
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
def extract_from_text_map(carrier)
|
293
|
-
# If the carrier does not have both the span_id and trace_id key
|
294
|
-
# skip the processing and just return a normal span
|
295
|
-
if !carrier.has_key?(CARRIER_SPAN_ID) || !carrier.has_key?(CARRIER_TRACE_ID)
|
296
|
-
return nil
|
297
|
-
end
|
298
|
-
|
299
|
-
baggage = carrier.reduce({}) do |baggage, tuple|
|
300
|
-
key, value = tuple
|
301
|
-
if key.start_with?(CARRIER_BAGGAGE_PREFIX)
|
302
|
-
plain_key = key.to_s[CARRIER_BAGGAGE_PREFIX.length..key.to_s.length]
|
303
|
-
baggage[plain_key] = value
|
304
|
-
end
|
305
|
-
baggage
|
306
|
-
end
|
307
|
-
SpanContext.new(
|
308
|
-
id: carrier[CARRIER_SPAN_ID],
|
309
|
-
trace_id: carrier[CARRIER_TRACE_ID],
|
310
|
-
baggage: baggage,
|
311
|
-
)
|
312
|
-
end
|
313
|
-
|
314
|
-
def inject_to_rack(span_context, carrier)
|
315
|
-
carrier[CARRIER_SPAN_ID] = span_context.id
|
316
|
-
carrier[CARRIER_TRACE_ID] = span_context.trace_id unless span_context.trace_id.nil?
|
317
|
-
carrier[CARRIER_SAMPLED] = 'true'
|
318
|
-
|
319
|
-
span_context.baggage.each do |key, value|
|
320
|
-
if key =~ /[^A-Za-z0-9\-_]/
|
321
|
-
# TODO: log the error internally
|
322
|
-
next
|
323
|
-
end
|
324
|
-
carrier[CARRIER_BAGGAGE_PREFIX + key] = value
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def extract_from_rack(env)
|
329
|
-
extract_from_text_map(env.reduce({}){|memo, tuple|
|
330
|
-
raw_header, value = tuple
|
331
|
-
header = raw_header.to_s.gsub(/^HTTP_/, '').tr('_', '-').downcase
|
332
|
-
|
333
|
-
memo[header] = value if header.start_with?(CARRIER_TRACER_STATE_PREFIX, CARRIER_BAGGAGE_PREFIX)
|
334
|
-
memo
|
335
|
-
})
|
336
|
-
end
|
337
274
|
end
|
338
275
|
end
|
data/lib/lightstep/version.rb
CHANGED
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.
|
4
|
+
version: 0.15.1
|
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
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -145,13 +145,15 @@ files:
|
|
145
145
|
- benchmark/threading/thread_test.rb
|
146
146
|
- bin/console
|
147
147
|
- bin/setup
|
148
|
-
- circle.yml
|
149
148
|
- example.rb
|
150
149
|
- examples/fork_children/main.rb
|
151
150
|
- examples/rack/hello.rb
|
152
151
|
- examples/rack/inject_extract.rb
|
153
152
|
- lib/lightstep.rb
|
154
153
|
- lib/lightstep/global_tracer.rb
|
154
|
+
- lib/lightstep/propagation.rb
|
155
|
+
- lib/lightstep/propagation/b3_propagator.rb
|
156
|
+
- lib/lightstep/propagation/lightstep_propagator.rb
|
155
157
|
- lib/lightstep/reporter.rb
|
156
158
|
- lib/lightstep/scope.rb
|
157
159
|
- lib/lightstep/scope_manager.rb
|
@@ -185,8 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
187
|
- !ruby/object:Gem::Version
|
186
188
|
version: '0'
|
187
189
|
requirements: []
|
188
|
-
|
189
|
-
rubygems_version: 2.5.2.3
|
190
|
+
rubygems_version: 3.0.3
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
193
|
summary: LightStep OpenTracing Ruby bindings
|
data/circle.yml
DELETED