opentelemetry-sdk 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/opentelemetry/sdk.rb +2 -2
- data/lib/opentelemetry/sdk/configurator.rb +12 -27
- data/lib/opentelemetry/sdk/internal.rb +1 -1
- data/lib/opentelemetry/sdk/trace/config/trace_config.rb +7 -1
- data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +1 -0
- data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +13 -4
- data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +2 -0
- data/lib/opentelemetry/sdk/trace/span.rb +10 -1
- data/lib/opentelemetry/sdk/version.rb +1 -1
- metadata +25 -14
- data/lib/opentelemetry/sdk/baggage.rb +0 -16
- data/lib/opentelemetry/sdk/baggage/builder.rb +0 -40
- data/lib/opentelemetry/sdk/baggage/manager.rb +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be88dba1f3a925ceb97494267f2d27cfb24f5f89e417236d5cca698c0388b9b
|
4
|
+
data.tar.gz: 8e43a87d87dc739c1323acecaa18e93dac8a911fc28a119c016e5e834ca74615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 672426fc31d0c6cce4f363509085b40bddf66d6c6516048e40ae1661fefaf2a6a3482acfe9a6dcff8db328675fb2e5ec02c9fe89d91486f551bf029bcb390f6b
|
7
|
+
data.tar.gz: 42b693687ddfdf1221c972d902e9249fcec6a947bb48416b4627fbd805859ac8bc5fcdb18ac44e4fb628bfd56f67bf42d028465f6e34c4c679844a7c1027515d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Release History: opentelemetry-sdk
|
2
2
|
|
3
|
+
### v0.17.0 / 2021-04-22
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
|
6
|
+
|
7
|
+
[Check the propagator documentation](https://open-telemetry.github.io/opentelemetry-ruby/) for the new usage.
|
8
|
+
|
9
|
+
* ADDED: Add zipkin exporter
|
10
|
+
* ADDED: Processors validate exporters on init.
|
11
|
+
* ADDED: Add configurable truncation of span and event attribute values
|
12
|
+
* ADDED: Add simple 'recording' attr_accessor to InMemorySpanExporter
|
13
|
+
* FIXED: Typo in error message
|
14
|
+
* FIXED: Improve configuration error reporting
|
15
|
+
* FIXED: Refactor propagators to add #fields
|
16
|
+
|
3
17
|
### v0.16.0 / 2021-03-17
|
4
18
|
|
5
19
|
* BREAKING CHANGE: Update SDK BaggageManager to match API
|
data/lib/opentelemetry/sdk.rb
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'opentelemetry'
|
8
8
|
require 'opentelemetry/common'
|
9
|
+
require 'opentelemetry-instrumentation-base'
|
9
10
|
|
10
11
|
# OpenTelemetry is an open source observability framework, providing a
|
11
12
|
# general-purpose API, SDK, and related tools required for the instrumentation
|
@@ -66,14 +67,13 @@ module OpenTelemetry
|
|
66
67
|
begin
|
67
68
|
raise ConfigurationError
|
68
69
|
rescue ConfigurationError => e
|
69
|
-
OpenTelemetry.handle_error(exception: e, message:
|
70
|
+
OpenTelemetry.handle_error(exception: e, message: "unexpected configuration error due to #{e.cause}")
|
70
71
|
end
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
76
|
require 'opentelemetry/sdk/configurator'
|
76
|
-
require 'opentelemetry/sdk/baggage'
|
77
77
|
require 'opentelemetry/sdk/internal'
|
78
78
|
require 'opentelemetry/sdk/instrumentation_library'
|
79
79
|
require 'opentelemetry/sdk/resources'
|
@@ -15,14 +15,12 @@ module OpenTelemetry
|
|
15
15
|
|
16
16
|
private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL
|
17
17
|
|
18
|
-
attr_writer :logger, :
|
19
|
-
:id_generator
|
18
|
+
attr_writer :logger, :propagators, :error_handler, :id_generator
|
20
19
|
|
21
20
|
def initialize
|
22
21
|
@instrumentation_names = []
|
23
22
|
@instrumentation_config_map = {}
|
24
|
-
@
|
25
|
-
@extractors = nil
|
23
|
+
@propagators = nil
|
26
24
|
@span_processors = []
|
27
25
|
@use_mode = USE_MODE_UNSPECIFIED
|
28
26
|
@resource = Resources::Resource.default
|
@@ -136,9 +134,9 @@ module OpenTelemetry
|
|
136
134
|
def install_instrumentation
|
137
135
|
case @use_mode
|
138
136
|
when USE_MODE_ONE
|
139
|
-
OpenTelemetry.
|
137
|
+
OpenTelemetry::Instrumentation.registry.install(@instrumentation_names, @instrumentation_config_map)
|
140
138
|
when USE_MODE_ALL
|
141
|
-
OpenTelemetry.
|
139
|
+
OpenTelemetry::Instrumentation.registry.install_all(@instrumentation_config_map)
|
142
140
|
end
|
143
141
|
end
|
144
142
|
|
@@ -161,14 +159,11 @@ module OpenTelemetry
|
|
161
159
|
end
|
162
160
|
end
|
163
161
|
|
164
|
-
def configure_propagation # rubocop:disable Metrics/
|
165
|
-
propagators = ENV.fetch('OTEL_PROPAGATORS', 'tracecontext,baggage').split(',')
|
166
|
-
injectors, extractors = propagators.uniq.collect do |propagator|
|
162
|
+
def configure_propagation # rubocop:disable Metrics/CyclomaticComplexity
|
163
|
+
propagators = ENV.fetch('OTEL_PROPAGATORS', 'tracecontext,baggage').split(',').uniq.collect do |propagator|
|
167
164
|
case propagator
|
168
|
-
when 'tracecontext'
|
169
|
-
|
170
|
-
when 'baggage'
|
171
|
-
[OpenTelemetry::Baggage::Propagation.text_map_injector, OpenTelemetry::Baggage::Propagation.text_map_extractor]
|
165
|
+
when 'tracecontext' then OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator
|
166
|
+
when 'baggage' then OpenTelemetry::Baggage::Propagation.text_map_propagator
|
172
167
|
when 'b3' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::B3::Single')
|
173
168
|
when 'b3multi' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::B3::Multi', 'b3')
|
174
169
|
when 'jaeger' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::Jaeger')
|
@@ -176,27 +171,17 @@ module OpenTelemetry
|
|
176
171
|
when 'ottrace' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::OTTrace')
|
177
172
|
else
|
178
173
|
OpenTelemetry.logger.warn "The #{propagator} propagator is unknown and cannot be configured"
|
179
|
-
|
174
|
+
Context::Propagation::NoopTextMapPropagator.new
|
180
175
|
end
|
181
|
-
end.transpose
|
182
|
-
OpenTelemetry.propagation = create_propagator(@injectors || injectors.compact,
|
183
|
-
@extractors || extractors.compact)
|
184
|
-
end
|
185
|
-
|
186
|
-
def create_propagator(injectors, extractors)
|
187
|
-
if injectors.size > 1 || extractors.size > 1
|
188
|
-
Context::Propagation::CompositePropagator.new(injectors, extractors)
|
189
|
-
else
|
190
|
-
Context::Propagation::Propagator.new(injectors.first, extractors.first)
|
191
176
|
end
|
177
|
+
OpenTelemetry.propagation = Context::Propagation::CompositeTextMapPropagator.compose_propagators((@propagators || propagators).compact)
|
192
178
|
end
|
193
179
|
|
194
180
|
def fetch_propagator(name, class_name, gem_suffix = name)
|
195
|
-
|
196
|
-
[propagator_class.text_map_injector, propagator_class.text_map_extractor]
|
181
|
+
Kernel.const_get(class_name).text_map_propagator
|
197
182
|
rescue NameError
|
198
183
|
OpenTelemetry.logger.warn "The #{name} propagator cannot be configured - please add opentelemetry-propagator-#{gem_suffix} to your Gemfile"
|
199
|
-
|
184
|
+
nil
|
200
185
|
end
|
201
186
|
|
202
187
|
def fetch_exporter(name, class_name)
|
@@ -47,7 +47,7 @@ module OpenTelemetry
|
|
47
47
|
def valid_attributes?(attrs)
|
48
48
|
attrs.nil? || attrs.all? do |k, v|
|
49
49
|
if !valid_key?(k)
|
50
|
-
OpenTelemetry.handle_error(message: "invalid attribute key type #{
|
50
|
+
OpenTelemetry.handle_error(message: "invalid attribute key type #{k.class}")
|
51
51
|
false
|
52
52
|
elsif !valid_value?(v)
|
53
53
|
OpenTelemetry.handle_error(message: "invalid attribute value type #{v.class}")
|
@@ -16,6 +16,9 @@ module OpenTelemetry
|
|
16
16
|
# The global default max number of attributes per {Span}.
|
17
17
|
attr_reader :max_attributes_count
|
18
18
|
|
19
|
+
# The global default max length of attribute value per {Span}.
|
20
|
+
attr_reader :max_attributes_length
|
21
|
+
|
19
22
|
# The global default max number of {OpenTelemetry::SDK::Trace::Event}s per {Span}.
|
20
23
|
attr_reader :max_events_count
|
21
24
|
|
@@ -32,13 +35,15 @@ module OpenTelemetry
|
|
32
35
|
#
|
33
36
|
# @return [TraceConfig] with the desired values.
|
34
37
|
# @raise [ArgumentError] if any of the max numbers are not positive.
|
35
|
-
def initialize(sampler: sampler_from_environment(Samplers.parent_based(root: Samplers::ALWAYS_ON)),
|
38
|
+
def initialize(sampler: sampler_from_environment(Samplers.parent_based(root: Samplers::ALWAYS_ON)), # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
36
39
|
max_attributes_count: Integer(ENV.fetch('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 128)),
|
40
|
+
max_attributes_length: ENV['OTEL_RUBY_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT'],
|
37
41
|
max_events_count: Integer(ENV.fetch('OTEL_SPAN_EVENT_COUNT_LIMIT', 128)),
|
38
42
|
max_links_count: Integer(ENV.fetch('OTEL_SPAN_LINK_COUNT_LIMIT', 128)),
|
39
43
|
max_attributes_per_event: max_attributes_count,
|
40
44
|
max_attributes_per_link: max_attributes_count)
|
41
45
|
raise ArgumentError, 'max_attributes_count must be positive' unless max_attributes_count.positive?
|
46
|
+
raise ArgumentError, 'max_attributes_length must not be less than 32' unless max_attributes_length.nil? || Integer(max_attributes_length) >= 32
|
42
47
|
raise ArgumentError, 'max_events_count must be positive' unless max_events_count.positive?
|
43
48
|
raise ArgumentError, 'max_links_count must be positive' unless max_links_count.positive?
|
44
49
|
raise ArgumentError, 'max_attributes_per_event must be positive' unless max_attributes_per_event.positive?
|
@@ -46,6 +51,7 @@ module OpenTelemetry
|
|
46
51
|
|
47
52
|
@sampler = sampler
|
48
53
|
@max_attributes_count = max_attributes_count
|
54
|
+
@max_attributes_length = max_attributes_length.nil? ? nil : Integer(max_attributes_length)
|
49
55
|
@max_events_count = max_events_count
|
50
56
|
@max_links_count = max_links_count
|
51
57
|
@max_attributes_per_event = max_attributes_per_event
|
@@ -52,6 +52,7 @@ module OpenTelemetry
|
|
52
52
|
start_thread_on_boot: String(ENV['OTEL_RUBY_BSP_START_THREAD_ON_BOOT']) !~ /false/i,
|
53
53
|
metrics_reporter: nil)
|
54
54
|
raise ArgumentError if max_export_batch_size > max_queue_size
|
55
|
+
raise ArgumentError, "exporter #{exporter.inspect} does not appear to be a valid exporter" unless Common::Utilities.valid_exporter?(exporter)
|
55
56
|
|
56
57
|
@exporter = exporter
|
57
58
|
@exporter_timeout_seconds = exporter_timeout / 1000.0
|
@@ -10,30 +10,39 @@ module OpenTelemetry
|
|
10
10
|
module Export
|
11
11
|
# A SpanExporter implementation that can be used to test OpenTelemetry integration.
|
12
12
|
#
|
13
|
-
# Example usage:
|
13
|
+
# Example usage in a test suite:
|
14
14
|
#
|
15
15
|
# class MyClassTest
|
16
16
|
# def setup
|
17
17
|
# @tracer_provider = TracerProvider.new
|
18
|
-
#
|
18
|
+
# # The default is `recording: true`, which is appropriate in non-test environments.
|
19
|
+
# @exporter = InMemorySpanExporter.new(recording: false)
|
19
20
|
# @tracer_provider.add_span_processor(SimpleSampledSpansProcessor.new(@exporter))
|
20
21
|
# end
|
21
22
|
#
|
22
23
|
# def test_finished_spans
|
24
|
+
# @exporter.recording = true
|
23
25
|
# @tracer_provider.tracer.in_span("span") {}
|
24
26
|
#
|
25
27
|
# spans = @exporter.finished_spans
|
26
28
|
# spans.wont_be_nil
|
27
29
|
# spans.size.must_equal(1)
|
28
30
|
# spans[0].name.must_equal("span")
|
31
|
+
#
|
32
|
+
# @exporter.recording = false
|
29
33
|
# end
|
30
34
|
class InMemorySpanExporter
|
35
|
+
# Controls whether or not the exporter will record spans, or discard them.
|
36
|
+
# @return [Boolean] when true, the exporter is recording. By default, this is true.
|
37
|
+
attr_accessor :recording
|
38
|
+
|
31
39
|
# Returns a new instance of the {InMemorySpanExporter}.
|
32
40
|
#
|
33
41
|
# @return a new instance of the {InMemorySpanExporter}.
|
34
|
-
def initialize
|
42
|
+
def initialize(recording: true)
|
35
43
|
@finished_spans = []
|
36
44
|
@stopped = false
|
45
|
+
@recording = recording
|
37
46
|
@mutex = Mutex.new
|
38
47
|
end
|
39
48
|
|
@@ -67,7 +76,7 @@ module OpenTelemetry
|
|
67
76
|
@mutex.synchronize do
|
68
77
|
return FAILURE if @stopped
|
69
78
|
|
70
|
-
@finished_spans.concat(span_datas.to_a)
|
79
|
+
@finished_spans.concat(span_datas.to_a) if @recording
|
71
80
|
end
|
72
81
|
SUCCESS
|
73
82
|
end
|
@@ -29,6 +29,8 @@ module OpenTelemetry
|
|
29
29
|
# @return [SimpleSpanProcessor]
|
30
30
|
# @raise ArgumentError if the span_exporter is nil.
|
31
31
|
def initialize(span_exporter)
|
32
|
+
raise ArgumentError, "exporter #{span_exporter.inspect} does not appear to be a valid exporter" unless Common::Utilities.valid_exporter?(span_exporter)
|
33
|
+
|
32
34
|
@span_exporter = span_exporter
|
33
35
|
end
|
34
36
|
|
@@ -133,7 +133,7 @@ module OpenTelemetry
|
|
133
133
|
# @return [self] returns itself
|
134
134
|
def add_event(name, attributes: nil, timestamp: nil)
|
135
135
|
super
|
136
|
-
event = Event.new(name: name, attributes: attributes, timestamp: timestamp || Time.now)
|
136
|
+
event = Event.new(name: name, attributes: truncate_attribute_values(attributes), timestamp: timestamp || Time.now)
|
137
137
|
|
138
138
|
@mutex.synchronize do
|
139
139
|
if @ended
|
@@ -316,9 +316,18 @@ module OpenTelemetry
|
|
316
316
|
|
317
317
|
excess = attrs.size - @trace_config.max_attributes_count
|
318
318
|
excess.times { attrs.shift } if excess.positive?
|
319
|
+
truncate_attribute_values(attrs)
|
319
320
|
nil
|
320
321
|
end
|
321
322
|
|
323
|
+
def truncate_attribute_values(attrs)
|
324
|
+
return if attrs.nil?
|
325
|
+
|
326
|
+
max_attributes_length = @trace_config.max_attributes_length
|
327
|
+
attrs.each { |key, value| attrs[key] = OpenTelemetry::Common::Utilities.truncate(value, max_attributes_length) } if max_attributes_length
|
328
|
+
attrs
|
329
|
+
end
|
330
|
+
|
322
331
|
def trim_links(links, max_links_count, max_attributes_per_link) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
323
332
|
# Fast path (likely) common cases.
|
324
333
|
return nil if links.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -16,28 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.17.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.17.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: opentelemetry-common
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.17.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.17.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opentelemetry-instrumentation-base
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.17.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.17.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +100,14 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
103
|
+
version: 0.17.0
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
110
|
+
version: 0.17.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rake
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,9 +191,6 @@ files:
|
|
177
191
|
- README.md
|
178
192
|
- lib/opentelemetry-sdk.rb
|
179
193
|
- lib/opentelemetry/sdk.rb
|
180
|
-
- lib/opentelemetry/sdk/baggage.rb
|
181
|
-
- lib/opentelemetry/sdk/baggage/builder.rb
|
182
|
-
- lib/opentelemetry/sdk/baggage/manager.rb
|
183
194
|
- lib/opentelemetry/sdk/configurator.rb
|
184
195
|
- lib/opentelemetry/sdk/instrumentation_library.rb
|
185
196
|
- lib/opentelemetry/sdk/internal.rb
|
@@ -215,10 +226,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
215
226
|
licenses:
|
216
227
|
- Apache-2.0
|
217
228
|
metadata:
|
218
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.
|
229
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.17.0/file.CHANGELOG.html
|
219
230
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/sdk
|
220
231
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
221
|
-
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.
|
232
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.17.0
|
222
233
|
post_install_message:
|
223
234
|
rdoc_options: []
|
224
235
|
require_paths:
|
@@ -234,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
245
|
- !ruby/object:Gem::Version
|
235
246
|
version: '0'
|
236
247
|
requirements: []
|
237
|
-
rubygems_version: 3.1.
|
248
|
+
rubygems_version: 3.1.6
|
238
249
|
signing_key:
|
239
250
|
specification_version: 4
|
240
251
|
summary: A stats collection and distributed tracing framework
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
require 'opentelemetry/sdk/baggage/builder'
|
8
|
-
require 'opentelemetry/sdk/baggage/manager'
|
9
|
-
|
10
|
-
module OpenTelemetry
|
11
|
-
module SDK
|
12
|
-
# Contains operational implementations of the Baggage::Manager
|
13
|
-
module Baggage
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
module OpenTelemetry
|
8
|
-
module SDK
|
9
|
-
module Baggage
|
10
|
-
# SDK implementation of Baggage::Builder
|
11
|
-
class Builder
|
12
|
-
attr_reader :entries
|
13
|
-
|
14
|
-
def initialize(entries)
|
15
|
-
@entries = entries
|
16
|
-
end
|
17
|
-
|
18
|
-
# Set key-value in the to-be-created baggage
|
19
|
-
#
|
20
|
-
# @param [String] key The key to store this value under
|
21
|
-
# @param [String] value String value to be stored under key
|
22
|
-
def set_value(key, value)
|
23
|
-
@entries[key] = value.to_s
|
24
|
-
end
|
25
|
-
|
26
|
-
# Removes key from the to-be-created baggage
|
27
|
-
#
|
28
|
-
# @param [String] key The key to remove
|
29
|
-
def remove_value(key)
|
30
|
-
@entries.delete(key)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Clears all baggage from the to-be-created baggage
|
34
|
-
def clear
|
35
|
-
@entries.clear
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
module OpenTelemetry
|
8
|
-
module SDK
|
9
|
-
module Baggage
|
10
|
-
# Manages baggage
|
11
|
-
class Manager
|
12
|
-
BAGGAGE_KEY = OpenTelemetry::Baggage::Propagation::ContextKeys.baggage_key
|
13
|
-
EMPTY_BAGGAGE = {}.freeze
|
14
|
-
private_constant(:BAGGAGE_KEY, :EMPTY_BAGGAGE)
|
15
|
-
|
16
|
-
# Used to chain modifications to baggage. The result is a
|
17
|
-
# context with an updated baggage. If only a single
|
18
|
-
# modification is being made to baggage, use the other
|
19
|
-
# methods on +Manager+, if multiple modifications are being made, use
|
20
|
-
# this one.
|
21
|
-
#
|
22
|
-
# @param [optional Context] context The context to update with with new
|
23
|
-
# modified baggage. Defaults to +Context.current+
|
24
|
-
# @return [Context]
|
25
|
-
def build(context: Context.current)
|
26
|
-
builder = Builder.new(baggage_for(context).dup)
|
27
|
-
yield builder
|
28
|
-
context.set_value(BAGGAGE_KEY, builder.entries)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Returns a new context with empty baggage
|
32
|
-
#
|
33
|
-
# @param [optional Context] context Context to clear baggage from. Defaults
|
34
|
-
# to +Context.current+
|
35
|
-
# @return [Context]
|
36
|
-
def clear(context: Context.current)
|
37
|
-
context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns the corresponding baggage value (or nil) for key
|
41
|
-
#
|
42
|
-
# @param [String] key The lookup key
|
43
|
-
# @param [optional Context] context The context from which to retrieve
|
44
|
-
# the key.
|
45
|
-
# Defaults to +Context.current+
|
46
|
-
# @return [String]
|
47
|
-
def value(key, context: Context.current)
|
48
|
-
baggage_for(context)[key]
|
49
|
-
end
|
50
|
-
|
51
|
-
# Returns the baggage
|
52
|
-
#
|
53
|
-
# @param [optional Context] context The context from which to retrieve
|
54
|
-
# the baggage.
|
55
|
-
# Defaults to +Context.current+
|
56
|
-
# @return [Hash]
|
57
|
-
def values(context: Context.current)
|
58
|
-
baggage_for(context).dup.freeze
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns a new context with new key-value pair
|
62
|
-
#
|
63
|
-
# @param [String] key The key to store this value under
|
64
|
-
# @param [String] value String value to be stored under key
|
65
|
-
# @param [optional Context] context The context to update with new
|
66
|
-
# value. Defaults to +Context.current+
|
67
|
-
# @return [Context]
|
68
|
-
def set_value(key, value, context: Context.current)
|
69
|
-
new_baggage = baggage_for(context).dup
|
70
|
-
new_baggage[key] = value
|
71
|
-
context.set_value(BAGGAGE_KEY, new_baggage)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Returns a new context with value at key removed
|
75
|
-
#
|
76
|
-
# @param [String] key The key to remove
|
77
|
-
# @param [optional Context] context The context to remove baggage
|
78
|
-
# from. Defaults to +Context.current+
|
79
|
-
# @return [Context]
|
80
|
-
def remove_value(key, context: Context.current)
|
81
|
-
baggage = baggage_for(context)
|
82
|
-
return context unless baggage.key?(key)
|
83
|
-
|
84
|
-
new_baggage = baggage.dup
|
85
|
-
new_baggage.delete(key)
|
86
|
-
context.set_value(BAGGAGE_KEY, new_baggage)
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def baggage_for(context)
|
92
|
-
context.value(BAGGAGE_KEY) || EMPTY_BAGGAGE
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|