opentelemetry-api 0.13.0 → 0.14.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: 42c8e52feabfa3bfc793e0699cbd50b72a1df552be7cffd96d2d80237b34e3e9
4
- data.tar.gz: 3e18f329dff954d7b5edeb79a5b7f18f1c24f57af5df9c51cf5d3da2c5d45a63
3
+ metadata.gz: 23c4a8602afe2513fff72ec29784b696ae41eccee8c3b25eb4cf48081856b22b
4
+ data.tar.gz: 17507ad2d0dbb697e6f1bb8cbf133d0baa01234d7383d9bb726b0d5fb11c4cb3
5
5
  SHA512:
6
- metadata.gz: 0c7f5a046e769ea40092101de2638a418aec4904ea6fec4af72f59e4d4f6f15e23899d31cfbc5c74eb0ca3e63e36b765930e377756f131bccaad5fb20c644fa5
7
- data.tar.gz: 8fc31b5c431446a9534b0cf9cee191b0737ff95a2e824c0d1b68947aa1f53f7f4fa58ab145fc7624cbf2d5cf0840ed3f60885e7fcb10b825b332ad8fc73f2724
6
+ metadata.gz: 5c37bb2d8a469bda44a121bfca1218380553cbc66d24e8001df4c2e67d93f9b474335962095b77a28e6de3c53f34af98ea18b12a3335cdd45d0b04d50510b2be
7
+ data.tar.gz: 3980934cdfdb34e96eb8215a9ebb26eb0b3d096be3e545837ee9d6595ff5e114ea680e692ccc7d0af2d89d8a4550e180671e4d92c5266b6a445c45fc991e0602
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History: opentelemetry-api
2
2
 
3
+ ### v0.14.0 / 2021-02-03
4
+
5
+ * BREAKING CHANGE: Replace getter and setter callables and remove rack specific propagators
6
+
7
+ * ADDED: Replace getter and setter callables and remove rack specific propagators
8
+
3
9
  ### v0.13.0 / 2021-01-29
4
10
 
5
11
  * ADDED: Add optional attributes to record_exception
data/lib/opentelemetry.rb CHANGED
@@ -22,7 +22,8 @@ require 'opentelemetry/version'
22
22
  module OpenTelemetry
23
23
  extend self
24
24
 
25
- attr_writer :tracer_provider, :meter_provider, :baggage, :logger, :error_handler
25
+ attr_writer :tracer_provider, :meter_provider, :propagation, :baggage,
26
+ :logger, :error_handler
26
27
 
27
28
  # @return [Object, Logger] configured Logger or a default STDOUT Logger.
28
29
  def logger
@@ -68,8 +69,11 @@ module OpenTelemetry
68
69
  @baggage ||= Baggage::Manager.new
69
70
  end
70
71
 
71
- # @return [Context::Propagation::Propagation] an instance of the propagation API
72
+ # @return [Context::Propagation::Propagator] a propagator instance
72
73
  def propagation
73
- @propagation ||= Context::Propagation::Propagation.new
74
+ @propagation ||= Context::Propagation::Propagator.new(
75
+ Context::Propagation::NoopInjector.new,
76
+ Context::Propagation::NoopExtractor.new
77
+ )
74
78
  end
75
79
  end
@@ -15,17 +15,11 @@ module OpenTelemetry
15
15
  module Propagation
16
16
  extend self
17
17
 
18
+ BAGGAGE_KEY = 'baggage'
18
19
  TEXT_MAP_EXTRACTOR = TextMapExtractor.new
19
20
  TEXT_MAP_INJECTOR = TextMapInjector.new
20
- RACK_EXTRACTOR = TextMapExtractor.new(
21
- baggage_key: 'HTTP_BAGGAGE'
22
- )
23
- RACK_INJECTOR = TextMapInjector.new(
24
- baggage_key: 'HTTP_BAGGAGE'
25
- )
26
21
 
27
- private_constant :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR, :RACK_INJECTOR,
28
- :RACK_EXTRACTOR
22
+ private_constant :BAGGAGE_KEY, :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR
29
23
 
30
24
  # Returns an extractor that extracts context using the W3C Baggage
31
25
  # format
@@ -38,20 +32,6 @@ module OpenTelemetry
38
32
  def text_map_extractor
39
33
  TEXT_MAP_EXTRACTOR
40
34
  end
41
-
42
- # Returns an extractor that extracts context using the W3C Baggage
43
- # format with Rack normalized keys (upcased and prefixed with
44
- # HTTP_)
45
- def rack_injector
46
- RACK_INJECTOR
47
- end
48
-
49
- # Returns an injector that injects context using the W3C Baggage
50
- # format with Rack normalized keys (upcased and prefixed with
51
- # HTTP_)
52
- def rack_extractor
53
- RACK_EXTRACTOR
54
- end
55
35
  end
56
36
  end
57
37
  end
@@ -11,16 +11,15 @@ module OpenTelemetry
11
11
  module Propagation
12
12
  # Extracts baggage from carriers in the W3C Baggage format
13
13
  class TextMapExtractor
14
- include Context::Propagation::DefaultGetter
15
-
16
14
  # Returns a new TextMapExtractor that extracts context using the specified
17
- # header key
15
+ # getter
18
16
  #
19
- # @param [String] baggage_key The baggage header
20
- # key used in the carrier
17
+ # @param [optional Getter] default_getter The default getter used to read
18
+ # headers from a carrier during extract. Defaults to a
19
+ # {OpenTelemetry::Context::Propagation::TextMapGetter} instance.
21
20
  # @return [TextMapExtractor]
22
- def initialize(baggage_key: 'baggage')
23
- @baggage_key = baggage_key
21
+ def initialize(default_getter = Context::Propagation.text_map_getter)
22
+ @default_getter = default_getter
24
23
  end
25
24
 
26
25
  # Extract remote baggage from the supplied carrier.
@@ -28,16 +27,14 @@ module OpenTelemetry
28
27
  #
29
28
  # @param [Carrier] carrier The carrier to get the header from
30
29
  # @param [Context] context The context to be updated with extracted baggage
31
- # @param [optional Callable] getter An optional callable that takes a carrier and a key and
32
- # returns the value associated with the key. If omitted the default getter will be used
33
- # which expects the carrier to respond to [] and []=.
34
- # @yield [Carrier, String] if an optional getter is provided, extract will yield the carrier
35
- # and the header key to the getter.
30
+ # @param [optional Getter] getter If the optional getter is provided, it
31
+ # will be used to read the header from the carrier, otherwise the default
32
+ # getter will be used.
36
33
  # @return [Context] context updated with extracted baggage, or the original context
37
34
  # if extraction fails
38
- def extract(carrier, context, &getter)
39
- getter ||= default_getter
40
- header = getter.call(carrier, @baggage_key)
35
+ def extract(carrier, context, getter = nil)
36
+ getter ||= @default_getter
37
+ header = getter.get(carrier, BAGGAGE_KEY)
41
38
 
42
39
  entries = header.gsub(/\s/, '').split(',')
43
40
 
@@ -11,33 +11,30 @@ module OpenTelemetry
11
11
  module Propagation
12
12
  # Injects baggage using the W3C Baggage format
13
13
  class TextMapInjector
14
- include Context::Propagation::DefaultSetter
15
-
16
14
  # Returns a new TextMapInjector that injects context using the specified
17
- # header key
15
+ # setter
18
16
  #
19
- # @param [String] baggage_key The baggage header
20
- # key used in the carrier
17
+ # @param [optional Setter] default_setter The default setter used to
18
+ # write context into a carrier during inject. Defaults to a
19
+ # {OpenTelemetry::Context::Propagation::TextMapSetter} instance.
21
20
  # @return [TextMapInjector]
22
- def initialize(baggage_key: 'baggage')
23
- @baggage_key = baggage_key
21
+ def initialize(default_setter = Context::Propagation.text_map_setter)
22
+ @default_setter = default_setter
24
23
  end
25
24
 
26
25
  # Inject in-process baggage into the supplied carrier.
27
26
  #
28
27
  # @param [Carrier] carrier The carrier to inject baggage into
29
28
  # @param [Context] context The context to read baggage from
30
- # @param [optional Callable] getter An optional callable that takes a carrier and a key and
31
- # returns the value associated with the key. If omitted the default getter will be used
32
- # which expects the carrier to respond to [] and []=.
33
- # @yield [Carrier, String] if an optional getter is provided, inject will yield the carrier
34
- # and the header key to the getter.
29
+ # @param [optional Setter] setter If the optional setter is provided, it
30
+ # will be used to write context into the carrier, otherwise the default
31
+ # setter will be used.
35
32
  # @return [Object] carrier with injected baggage
36
- def inject(carrier, context, &setter)
33
+ def inject(carrier, context, setter = nil)
37
34
  return carrier unless (baggage = context[ContextKeys.baggage_key]) && !baggage.empty?
38
35
 
39
- setter ||= default_setter
40
- setter.call(carrier, @baggage_key, encode(baggage))
36
+ setter ||= @default_setter
37
+ setter.set(carrier, BAGGAGE_KEY, encode(baggage))
41
38
 
42
39
  carrier
43
40
  end
@@ -5,18 +5,43 @@
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  require 'opentelemetry/context/propagation/composite_propagator'
8
- require 'opentelemetry/context/propagation/default_getter'
9
- require 'opentelemetry/context/propagation/default_setter'
10
8
  require 'opentelemetry/context/propagation/noop_extractor'
11
9
  require 'opentelemetry/context/propagation/noop_injector'
12
- require 'opentelemetry/context/propagation/propagation'
13
10
  require 'opentelemetry/context/propagation/propagator'
11
+ require 'opentelemetry/context/propagation/text_map_getter'
12
+ require 'opentelemetry/context/propagation/text_map_setter'
13
+ require 'opentelemetry/context/propagation/rack_env_getter'
14
14
 
15
15
  module OpenTelemetry
16
16
  class Context
17
17
  # The propagation module contains APIs and utilities to interact with context
18
18
  # and propagate across process boundaries.
19
19
  module Propagation
20
+ extend self
21
+
22
+ TEXT_MAP_GETTER = TextMapGetter.new
23
+ TEXT_MAP_SETTER = TextMapSetter.new
24
+ RACK_ENV_GETTER = RackEnvGetter.new
25
+
26
+ private_constant :TEXT_MAP_GETTER, :TEXT_MAP_SETTER, :RACK_ENV_GETTER
27
+
28
+ # Returns a {TextMapGetter} instance suitable for reading values from a
29
+ # hash-like carrier
30
+ def text_map_getter
31
+ TEXT_MAP_GETTER
32
+ end
33
+
34
+ # Returns a {TextMapSetter} instance suitable for writing values into a
35
+ # hash-like carrier
36
+ def text_map_setter
37
+ TEXT_MAP_SETTER
38
+ end
39
+
40
+ # Returns a {RackEnvGetter} instance suitable for reading values from a
41
+ # Rack environment.
42
+ def rack_env_getter
43
+ RACK_ENV_GETTER
44
+ end
20
45
  end
21
46
  end
22
47
  end
@@ -30,15 +30,14 @@ module OpenTelemetry
30
30
  # context into
31
31
  # @param [optional Context] context Context to be injected into carrier.
32
32
  # Defaults to +Context.current+
33
- # @param [optional Callable] setter An optional callable that takes a
34
- # carrier, a key and a value and assigns the key-value pair in the
35
- # carrier. If omitted the default setter will be used which expects
36
- # the carrier to respond to [] and []=.
33
+ # @param [optional Setter] setter If the optional setter is provided, it
34
+ # will be used to write context into the carrier, otherwise the default
35
+ # setter will be used.
37
36
  #
38
37
  # @return [Object] carrier
39
- def inject(carrier, context = Context.current, &setter)
38
+ def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
40
39
  @injectors.inject(carrier) do |memo, injector|
41
- injector.inject(memo, context, &setter)
40
+ injector.inject(memo, context, setter)
42
41
  rescue => e # rubocop:disable Style/RescueStandardError
43
42
  OpenTelemetry.logger.warn "Error in CompositePropagator#inject #{e.message}"
44
43
  carrier
@@ -53,15 +52,15 @@ module OpenTelemetry
53
52
  # @param [Object] carrier The carrier to extract context from
54
53
  # @param [optional Context] context Context to be updated with the state
55
54
  # extracted from the carrier. Defaults to +Context.current+
56
- # @param [optional Callable] getter An optional callable that takes a carrier and a key and
57
- # returns the value associated with the key. If omitted the default getter will be used
58
- # which expects the carrier to respond to [] and []=.
55
+ # @param [optional Getter] getter If the optional getter is provided, it
56
+ # will be used to read the header from the carrier, otherwise the default
57
+ # getter will be used.
59
58
  #
60
59
  # @return [Context] a new context updated with state extracted from the
61
60
  # carrier
62
- def extract(carrier, context = Context.current, &getter)
61
+ def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
63
62
  @extractors.inject(context) do |ctx, extractor|
64
- extractor.extract(carrier, ctx, &getter)
63
+ extractor.extract(carrier, ctx, getter)
65
64
  rescue => e # rubocop:disable Style/RescueStandardError
66
65
  OpenTelemetry.logger.warn "Error in CompositePropagator#extract #{e.message}"
67
66
  ctx
@@ -17,7 +17,7 @@ module OpenTelemetry
17
17
  # @param [optional Callable] getter An optional callable that takes a carrier and a key and
18
18
  # and returns the value associated with the key
19
19
  # @return [Context]
20
- def extract(carrier, context, &getter)
20
+ def extract(carrier, context, getter = nil)
21
21
  context
22
22
  end
23
23
  end
@@ -28,13 +28,13 @@ module OpenTelemetry
28
28
  # context into
29
29
  # @param [optional Context] context Context to be injected into carrier. Defaults
30
30
  # to +Context.current+
31
- # @param [optional Callable] setter An optional callable that takes a carrier, a key and
32
- # a value and assigns the key-value pair in the carrier. If omitted the default setter
33
- # will be used which expects the carrier to respond to [] and []=.
31
+ # @param [optional Setter] setter If the optional setter is provided, it
32
+ # will be used to write context into the carrier, otherwise the default
33
+ # setter will be used.
34
34
  #
35
35
  # @return [Object] carrier
36
- def inject(carrier, context = Context.current, &setter)
37
- @injector.inject(carrier, context, &setter)
36
+ def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
37
+ @injector.inject(carrier, context, setter)
38
38
  rescue => e # rubocop:disable Style/RescueStandardError
39
39
  OpenTelemetry.logger.warn "Error in Propagator#inject #{e.message}"
40
40
  carrier
@@ -46,14 +46,14 @@ module OpenTelemetry
46
46
  # @param [Object] carrier The carrier to extract context from
47
47
  # @param [optional Context] context Context to be updated with the state
48
48
  # extracted from the carrier. Defaults to +Context.current+
49
- # @param [optional Callable] getter An optional callable that takes a carrier and a key and
50
- # returns the value associated with the key. If omitted the default getter will be used
51
- # which expects the carrier to respond to [] and []=.
49
+ # @param [optional Getter] getter If the optional getter is provided, it
50
+ # will be used to read the header from the carrier, otherwise the default
51
+ # getter will be used.
52
52
  #
53
53
  # @return [Context] a new context updated with state extracted from the
54
54
  # carrier
55
- def extract(carrier, context = Context.current, &getter)
56
- @extractor.extract(carrier, context, &getter)
55
+ def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
56
+ @extractor.extract(carrier, context, getter)
57
57
  rescue => e # rubocop:disable Style/RescueStandardError
58
58
  OpenTelemetry.logger.warn "Error in Propagator#extract #{e.message}"
59
59
  context
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ class Context
9
+ module Propagation
10
+ # The RackEnvGetter class provides a common methods for reading
11
+ # keys from a rack environment. It abstracts away the rack-normalization
12
+ # process so that keys can be looked up without having to transform them
13
+ # first. With this class you can get +traceparent+ instead of
14
+ # +HTTP_TRACEPARENT+
15
+ class RackEnvGetter
16
+ # Converts key into a rack-normalized key and reads it from the carrier.
17
+ # Useful for extract operations.
18
+ def get(carrier, key)
19
+ carrier[to_rack_key(key)]
20
+ end
21
+
22
+ # Reads all keys from a carrier and converts them from the rack-normalized
23
+ # form to the original. The resulting keys will be lowercase and
24
+ # underscores will be replaced with dashes.
25
+ def keys(carrier)
26
+ carrier.keys.map(&method(:from_rack_key))
27
+ end
28
+
29
+ private
30
+
31
+ def to_rack_key(key)
32
+ ret = 'HTTP_' + key
33
+ ret.tr!('-', '_')
34
+ ret.upcase!
35
+ end
36
+
37
+ def from_rack_key(key)
38
+ start = key.start_with?('HTTP_') ? 5 : 0
39
+ ret = key[start..-1]
40
+ ret.tr!('_', '-')
41
+ ret.downcase!
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ class Context
9
+ module Propagation
10
+ # The default getter module provides a common methods for reading
11
+ # key from a carrier that implements +[]+ and a +keys+ method
12
+ class TextMapGetter
13
+ # Reads a key from a carrier that implements +[]+. Useful for extract
14
+ # operations.
15
+ def get(carrier, key)
16
+ carrier[key]
17
+ end
18
+
19
+ # Reads all keys from a carrier. Useful for iterating over a carrier's
20
+ # keys.
21
+ def keys(carrier)
22
+ carrier.keys
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ class Context
9
+ module Propagation
10
+ # The default setter module provides a common method for writing
11
+ # a key into a carrier that implements +[]=+
12
+ class TextMapSetter
13
+ # Writes key into a carrier that implements +[]=+. Useful for inject
14
+ # operations.
15
+ def set(carrier, key, value)
16
+ carrier[key] = value
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -15,20 +15,13 @@ module OpenTelemetry
15
15
  # for context propagation in the W3C Trace Context format.
16
16
  module TraceContext
17
17
  extend self
18
-
18
+ TRACEPARENT_KEY = 'traceparent'
19
+ TRACESTATE_KEY = 'tracestate'
19
20
  TEXT_MAP_EXTRACTOR = TextMapExtractor.new
20
21
  TEXT_MAP_INJECTOR = TextMapInjector.new
21
- RACK_EXTRACTOR = TextMapExtractor.new(
22
- traceparent_key: 'HTTP_TRACEPARENT',
23
- tracestate_key: 'HTTP_TRACESTATE'
24
- )
25
- RACK_INJECTOR = TextMapInjector.new(
26
- traceparent_key: 'HTTP_TRACEPARENT',
27
- tracestate_key: 'HTTP_TRACESTATE'
28
- )
29
22
 
30
- private_constant :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR,
31
- :RACK_INJECTOR, :RACK_EXTRACTOR
23
+ private_constant :TRACEPARENT_KEY, :TRACESTATE_KEY,
24
+ :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR
32
25
 
33
26
  # Returns an extractor that extracts context using the W3C Trace Context
34
27
  # format
@@ -41,18 +34,6 @@ module OpenTelemetry
41
34
  def text_map_injector
42
35
  TEXT_MAP_INJECTOR
43
36
  end
44
-
45
- # Returns an extractor that extracts context using the W3C Trace Context
46
- # with Rack normalized keys (upcased and prefixed with HTTP_)
47
- def rack_extractor
48
- RACK_EXTRACTOR
49
- end
50
-
51
- # Returns an injector that injects context using the W3C Trace Context
52
- # format with Rack normalized keys (upcased and prefixed with HTTP_)
53
- def rack_injector
54
- RACK_INJECTOR
55
- end
56
37
  end
57
38
  end
58
39
  end
@@ -9,18 +9,15 @@ module OpenTelemetry
9
9
  module TraceContext
10
10
  # Extracts context from carriers in the W3C Trace Context format
11
11
  class TextMapExtractor
12
- include Context::Propagation::DefaultGetter
13
-
14
12
  # Returns a new TextMapExtractor that extracts context using the
15
- # specified header keys
13
+ # specified getter
16
14
  #
17
- # @param [String] traceparent_key The traceparent header key used in the carrier
18
- # @param [String] tracestate_key The tracestate header key used in the carrier
15
+ # @param [optional Getter] default_getter The default getter used to read
16
+ # headers from a carrier during extract. Defaults to a +TextMapGetter+
17
+ # instance.
19
18
  # @return [TextMapExtractor]
20
- def initialize(traceparent_key: 'traceparent',
21
- tracestate_key: 'tracestate')
22
- @traceparent_key = traceparent_key
23
- @tracestate_key = tracestate_key
19
+ def initialize(default_getter = Context::Propagation.text_map_getter)
20
+ @default_getter = default_getter
24
21
  end
25
22
 
26
23
  # Extract a remote {Trace::SpanContext} from the supplied carrier.
@@ -28,17 +25,15 @@ module OpenTelemetry
28
25
  #
29
26
  # @param [Carrier] carrier The carrier to get the header from.
30
27
  # @param [Context] context The context to be updated with extracted context
31
- # @param [optional Callable] getter An optional callable that takes a carrier and a key and
32
- # returns the value associated with the key. If omitted the default getter will be used
33
- # which expects the carrier to respond to [] and []=.
34
- # @yield [Carrier, String] if an optional getter is provided, extract will yield the carrier
35
- # and the header key to the getter.
28
+ # @param [optional Getter] getter If the optional getter is provided, it
29
+ # will be used to read the header from the carrier, otherwise the default
30
+ # getter will be used.
36
31
  # @return [Context] Updated context with span context from the header, or the original
37
32
  # context if parsing fails.
38
- def extract(carrier, context, &getter)
39
- getter ||= default_getter
40
- tp = TraceParent.from_string(getter.call(carrier, @traceparent_key))
41
- tracestate = Tracestate.from_string(getter.call(carrier, @tracestate_key))
33
+ def extract(carrier, context, getter = nil)
34
+ getter ||= @default_getter
35
+ tp = TraceParent.from_string(getter.get(carrier, TRACEPARENT_KEY))
36
+ tracestate = Tracestate.from_string(getter.get(carrier, TRACESTATE_KEY))
42
37
 
43
38
  span_context = Trace::SpanContext.new(trace_id: tp.trace_id,
44
39
  span_id: tp.span_id,
@@ -9,35 +9,30 @@ module OpenTelemetry
9
9
  module TraceContext
10
10
  # Injects context into carriers using the W3C Trace Context format
11
11
  class TextMapInjector
12
- include Context::Propagation::DefaultSetter
13
-
14
12
  # Returns a new TextMapInjector that injects context using the
15
- # specified header keys
13
+ # specified setter
16
14
  #
17
- # @param [String] traceparent_key The traceparent header key used in the carrier
18
- # @param [String] tracestate_key The tracestate header key used in the carrier
15
+ # @param [optional Setter] default_setter The default setter used to
16
+ # write context into a carrier during inject. Defaults to a
17
+ # {TextMapSetter} instance.
19
18
  # @return [TextMapInjector]
20
- def initialize(traceparent_key: 'traceparent',
21
- tracestate_key: 'tracestate')
22
- @traceparent_key = traceparent_key
23
- @tracestate_key = tracestate_key
19
+ def initialize(default_setter = Context::Propagation.text_map_setter)
20
+ @default_setter = default_setter
24
21
  end
25
22
 
26
23
  # Set the span context on the supplied carrier.
27
24
  #
28
25
  # @param [Context] context The active {Context}.
29
- # @param [optional Callable] setter An optional callable that takes a carrier and a key and
30
- # a value and assigns the key-value pair in the carrier. If omitted the default setter
31
- # will be used which expects the carrier to respond to [] and []=.
32
- # @yield [Carrier, String, String] if an optional setter is provided, inject will yield
33
- # carrier, header key, header value to the setter.
26
+ # @param [optional Setter] setter If the optional setter is provided, it
27
+ # will be used to write context into the carrier, otherwise the default
28
+ # setter will be used.
34
29
  # @return [Object] the carrier with context injected
35
- def inject(carrier, context, &setter)
30
+ def inject(carrier, context, setter = nil)
36
31
  return carrier unless (span_context = span_context_from(context))
37
32
 
38
- setter ||= DEFAULT_SETTER
39
- setter.call(carrier, @traceparent_key, TraceParent.from_span_context(span_context).to_s)
40
- setter.call(carrier, @tracestate_key, span_context.tracestate.to_s) unless span_context.tracestate.empty?
33
+ setter ||= @default_setter
34
+ setter.set(carrier, TRACEPARENT_KEY, TraceParent.from_span_context(span_context).to_s)
35
+ setter.set(carrier, TRACESTATE_KEY, span_context.tracestate.to_s) unless span_context.tracestate.empty?
41
36
 
42
37
  carrier
43
38
  end
@@ -6,5 +6,5 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  ## Current OpenTelemetry version
9
- VERSION = '0.13.0'
9
+ VERSION = '0.14.0'
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.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-01-30 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ipsa
@@ -160,12 +160,12 @@ files:
160
160
  - lib/opentelemetry/context/key.rb
161
161
  - lib/opentelemetry/context/propagation.rb
162
162
  - lib/opentelemetry/context/propagation/composite_propagator.rb
163
- - lib/opentelemetry/context/propagation/default_getter.rb
164
- - lib/opentelemetry/context/propagation/default_setter.rb
165
163
  - lib/opentelemetry/context/propagation/noop_extractor.rb
166
164
  - lib/opentelemetry/context/propagation/noop_injector.rb
167
- - lib/opentelemetry/context/propagation/propagation.rb
168
165
  - lib/opentelemetry/context/propagation/propagator.rb
166
+ - lib/opentelemetry/context/propagation/rack_env_getter.rb
167
+ - lib/opentelemetry/context/propagation/text_map_getter.rb
168
+ - lib/opentelemetry/context/propagation/text_map_setter.rb
169
169
  - lib/opentelemetry/error.rb
170
170
  - lib/opentelemetry/instrumentation.rb
171
171
  - lib/opentelemetry/instrumentation/base.rb
@@ -196,10 +196,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
196
196
  licenses:
197
197
  - Apache-2.0
198
198
  metadata:
199
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.13.0/file.CHANGELOG.html
199
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.14.0/file.CHANGELOG.html
200
200
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/api
201
201
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
202
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.13.0
202
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.14.0
203
203
  post_install_message:
204
204
  rdoc_options: []
205
205
  require_paths:
@@ -1,26 +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
- class Context
9
- module Propagation
10
- # The default getter module provides a common method for reading
11
- # a key from a carrier that implements +[]+
12
- module DefaultGetter
13
- DEFAULT_GETTER = ->(carrier, key) { carrier[key] }
14
- private_constant :DEFAULT_GETTER
15
-
16
- # Returns a callable that can read a key from a carrier that implements
17
- # +[]+. Useful for extract operations.
18
- #
19
- # @return [Callable]
20
- def default_getter
21
- DEFAULT_GETTER
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,26 +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
- class Context
9
- module Propagation
10
- # The default setter module provides a common method for writing
11
- # a key into a carrier that implements +[]=+
12
- module DefaultSetter
13
- DEFAULT_SETTER = ->(carrier, key, value) { carrier[key] = value }
14
- private_constant :DEFAULT_SETTER
15
-
16
- # Returns a callable that can write a key into a carrier that implements
17
- # +[]=+. Useful for inject operations.
18
- #
19
- # @return [Callable]
20
- def default_setter
21
- DEFAULT_SETTER
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,27 +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
- class Context
9
- module Propagation
10
- # The Propagation class provides methods to inject and extract context
11
- # to pass across process boundaries
12
- class Propagation
13
- # Get or set the global http propagator. Use a CompositePropagator
14
- # to propagate multiple formats.
15
- attr_accessor :http
16
-
17
- # Get or set the global text propagator. Use a CompositePropagator
18
- # to propagate multiple formats.
19
- attr_accessor :text
20
-
21
- def initialize
22
- @http = @text = Propagator.new(NoopInjector.new, NoopExtractor.new)
23
- end
24
- end
25
- end
26
- end
27
- end