Skip to content

Commit bcef5f9

Browse files
ahayworthfbogsany
andauthored
feat: Make API's NoopTextMapPropagator private (#841)
* feat: Make API's NoopTextMapPropagator private To do so, we wholesale duplicate it into the SDK. * Shroud our private APIs in mystery * Move SDK private NoopTextMapPropagator directly into Configurator Co-authored-by: Francis Bogsanyi <[email protected]>
1 parent d5810e3 commit bcef5f9

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

api/lib/opentelemetry/context/propagation/noop_text_map_propagator.rb

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,17 @@
77
module OpenTelemetry
88
class Context
99
module Propagation
10-
# A no-op text map propagator implementation
10+
# @api private
1111
class NoopTextMapPropagator
1212
EMPTY_LIST = [].freeze
1313
private_constant(:EMPTY_LIST)
1414

15-
# Injects the provided context into a carrier.
16-
#
17-
# @param [Object] carrier A mutable carrier to inject context into.
18-
# @param [optional Context] context Context to be injected into carrier. Defaults
19-
# to +Context.current+.
20-
# @param [optional Setter] setter If the optional setter is provided, it
21-
# will be used to write context into the carrier, otherwise the default
22-
# setter will be used.
2315
def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter); end
2416

25-
# Extracts and returns context from a carrier. Returns the provided
26-
# context and logs a warning if an error if extraction fails.
27-
#
28-
# @param [Object] carrier The carrier to extract context from.
29-
# @param [optional Context] context Context to be updated with the state
30-
# extracted from the carrier. Defaults to +Context.current+.
31-
# @param [optional Getter] getter If the optional getter is provided, it
32-
# will be used to read the header from the carrier, otherwise the default
33-
# getter will be used.
34-
#
35-
# @return [Context] a new context updated with state extracted from the
36-
# carrier
3717
def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
3818
context
3919
end
4020

41-
# Returns the predefined propagation fields. If your carrier is reused, you
42-
# should delete the fields returned by this method before calling +inject+.
43-
#
44-
# @return [Array<String>] a list of fields that will be used by this propagator.
4521
def fields
4622
EMPTY_LIST
4723
end

sdk/lib/opentelemetry/sdk/configurator.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ module SDK
99
# The configurator provides defaults and facilitates configuring the
1010
# SDK for use.
1111
class Configurator # rubocop:disable Metrics/ClassLength
12+
# @api private
13+
class NoopTextMapPropagator
14+
EMPTY_LIST = [].freeze
15+
private_constant(:EMPTY_LIST)
16+
17+
def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter); end
18+
19+
def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
20+
context
21+
end
22+
23+
def fields
24+
EMPTY_LIST
25+
end
26+
end
27+
1228
USE_MODE_UNSPECIFIED = 0
1329
USE_MODE_ONE = 1
1430
USE_MODE_ALL = 2
@@ -179,7 +195,7 @@ def configure_propagation # rubocop:disable Metrics/CyclomaticComplexity
179195
when 'ottrace' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::OTTrace')
180196
else
181197
OpenTelemetry.logger.warn "The #{propagator} propagator is unknown and cannot be configured"
182-
Context::Propagation::NoopTextMapPropagator.new
198+
NoopTextMapPropagator.new
183199
end
184200
end
185201
OpenTelemetry.propagation = Context::Propagation::CompositeTextMapPropagator.compose_propagators((@propagators || propagators).compact)

sdk/test/opentelemetry/sdk/configurator_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
end
147147

148148
it 'is user settable' do
149-
propagator = OpenTelemetry::Context::Propagation::NoopTextMapPropagator.new
149+
propagator = OpenTelemetry::SDK::Configurator::NoopTextMapPropagator.new
150150
configurator.propagators = [propagator]
151151
configurator.configure
152152

@@ -167,7 +167,7 @@
167167
end
168168

169169
_(OpenTelemetry.propagation).must_be_instance_of(
170-
Context::Propagation::NoopTextMapPropagator
170+
OpenTelemetry::SDK::Configurator::NoopTextMapPropagator
171171
)
172172
end
173173
end

0 commit comments

Comments
 (0)