opentelemetry-api 0.13.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +2 -2
  4. data/lib/opentelemetry.rb +24 -20
  5. data/lib/opentelemetry/baggage.rb +4 -1
  6. data/lib/opentelemetry/baggage/builder.rb +30 -4
  7. data/lib/opentelemetry/baggage/entry.rb +20 -0
  8. data/lib/opentelemetry/baggage/manager.rb +76 -13
  9. data/lib/opentelemetry/baggage/noop_builder.rb +18 -0
  10. data/lib/opentelemetry/baggage/noop_manager.rb +45 -0
  11. data/lib/opentelemetry/baggage/propagation.rb +9 -38
  12. data/lib/opentelemetry/baggage/propagation/text_map_propagator.rb +109 -0
  13. data/lib/opentelemetry/context/propagation.rb +62 -7
  14. data/lib/opentelemetry/context/propagation/composite_text_map_propagator.rb +105 -0
  15. data/lib/opentelemetry/context/propagation/noop_text_map_propagator.rb +51 -0
  16. data/lib/opentelemetry/context/propagation/rack_env_getter.rb +48 -0
  17. data/lib/opentelemetry/context/propagation/text_map_getter.rb +27 -0
  18. data/lib/opentelemetry/context/propagation/text_map_propagator.rb +71 -0
  19. data/lib/opentelemetry/context/propagation/text_map_setter.rb +21 -0
  20. data/lib/opentelemetry/internal.rb +17 -0
  21. data/lib/opentelemetry/internal/proxy_tracer.rb +38 -0
  22. data/lib/opentelemetry/internal/proxy_tracer_provider.rb +59 -0
  23. data/lib/opentelemetry/trace/propagation/trace_context.rb +7 -37
  24. data/lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb +73 -0
  25. data/lib/opentelemetry/trace/span.rb +20 -0
  26. data/lib/opentelemetry/trace/tracer.rb +2 -2
  27. data/lib/opentelemetry/version.rb +1 -1
  28. metadata +21 -26
  29. data/lib/opentelemetry/baggage/propagation/text_map_extractor.rb +0 -60
  30. data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +0 -55
  31. data/lib/opentelemetry/context/propagation/composite_propagator.rb +0 -73
  32. data/lib/opentelemetry/context/propagation/default_getter.rb +0 -26
  33. data/lib/opentelemetry/context/propagation/default_setter.rb +0 -26
  34. data/lib/opentelemetry/context/propagation/noop_extractor.rb +0 -26
  35. data/lib/opentelemetry/context/propagation/noop_injector.rb +0 -26
  36. data/lib/opentelemetry/context/propagation/propagation.rb +0 -27
  37. data/lib/opentelemetry/context/propagation/propagator.rb +0 -64
  38. data/lib/opentelemetry/instrumentation.rb +0 -15
  39. data/lib/opentelemetry/instrumentation/base.rb +0 -245
  40. data/lib/opentelemetry/instrumentation/registry.rb +0 -86
  41. data/lib/opentelemetry/metrics.rb +0 -16
  42. data/lib/opentelemetry/metrics/handles.rb +0 -44
  43. data/lib/opentelemetry/metrics/instruments.rb +0 -105
  44. data/lib/opentelemetry/metrics/meter.rb +0 -72
  45. data/lib/opentelemetry/metrics/meter_provider.rb +0 -22
  46. data/lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb +0 -57
  47. data/lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42c8e52feabfa3bfc793e0699cbd50b72a1df552be7cffd96d2d80237b34e3e9
4
- data.tar.gz: 3e18f329dff954d7b5edeb79a5b7f18f1c24f57af5df9c51cf5d3da2c5d45a63
3
+ metadata.gz: 8c72d994e97f5c64be4418b271fa7f359899afa493910af615521eb785f671c2
4
+ data.tar.gz: 11c0b57837eae216f71e63d9d462f28e41fd873b2c33d9ecffe51f15f13a8373
5
5
  SHA512:
6
- metadata.gz: 0c7f5a046e769ea40092101de2638a418aec4904ea6fec4af72f59e4d4f6f15e23899d31cfbc5c74eb0ca3e63e36b765930e377756f131bccaad5fb20c644fa5
7
- data.tar.gz: 8fc31b5c431446a9534b0cf9cee191b0737ff95a2e824c0d1b68947aa1f53f7f4fa58ab145fc7624cbf2d5cf0840ed3f60885e7fcb10b825b332ad8fc73f2724
6
+ metadata.gz: b162dfbf770ef1a162fe2d6826832d1c51a8a019e5bdcc3632ed6449a832cd3c94d98a627687af22b86b7bcc23956a6e9044834c4010d7ac98a37ae33b204a3e
7
+ data.tar.gz: aca58a7e39e73ae037429a0ce55b01160d20fdedba2c184dff6c2c34e8f17d2086a963f9e294dcccddea9fe81569ab99c2f28ff0e470dfd52576c4b9e49aad61
data/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Release History: opentelemetry-api
2
2
 
3
+ ### v1.0.0.rc1 / 2021-05-21
4
+
5
+ * BREAKING CHANGE: Remove optional parent_context from in_span
6
+
7
+ * FIXED: Remove optional parent_context from in_span
8
+
9
+ ### v0.17.0 / 2021-04-22
10
+
11
+ * BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
12
+
13
+ [Check the propagator documentation](https://open-telemetry.github.io/opentelemetry-ruby/) for the new usage.
14
+ * BREAKING CHANGE: Remove metrics API.
15
+
16
+ `OpenTelemetry::Metrics` and all of its behavior removed until spec stabilizes.
17
+ * BREAKING CHANGE: Extract instrumentation base from api (#698).
18
+
19
+ To take advantage of a base instrumentation class to create your own auto-instrumentation, require and use the `opentelemetry-instrumentation-base` gem.
20
+
21
+ * ADDED: Default noop tracer for instrumentation
22
+ * FIXED: Refactor propagators to add #fields
23
+ * FIXED: Remove metrics API
24
+ * FIXED: Dynamically upgrade global tracer provider
25
+
26
+ ### v0.16.0 / 2021-03-17
27
+
28
+ * ADDED: Span#add_attributes
29
+ * FIXED: Handle rack env getter edge cases
30
+ * DOCS: Replace Gitter with GitHub Discussions
31
+
32
+ ### v0.15.0 / 2021-02-18
33
+
34
+ * ADDED: Add instrumentation config validation
35
+ * DOCS: Clarify nil attribute values not allowed
36
+
37
+ ### v0.14.0 / 2021-02-03
38
+
39
+ * BREAKING CHANGE: Replace getter and setter callables and remove rack specific propagators
40
+
41
+ * ADDED: Replace getter and setter callables and remove rack specific propagators
42
+
3
43
  ### v0.13.0 / 2021-01-29
4
44
 
5
45
  * ADDED: Add optional attributes to record_exception
data/README.md CHANGED
@@ -49,7 +49,7 @@ For additional examples, see the [examples on github][examples-github].
49
49
 
50
50
  The `opentelemetry-api` gem source is [on github][repo-github], along with related gems including `opentelemetry-sdk`.
51
51
 
52
- The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us on our [gitter channel][ruby-gitter] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
52
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
53
53
 
54
54
  ## License
55
55
 
@@ -63,4 +63,4 @@ The `opentelemetry-api` gem is distributed under the Apache 2.0 license. See [LI
63
63
  [examples-github]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/examples
64
64
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
65
65
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
66
- [ruby-gitter]: https://gitter.im/open-telemetry/opentelemetry-ruby
66
+ [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
data/lib/opentelemetry.rb CHANGED
@@ -9,9 +9,8 @@ require 'logger'
9
9
  require 'opentelemetry/error'
10
10
  require 'opentelemetry/context'
11
11
  require 'opentelemetry/baggage'
12
- require_relative './opentelemetry/instrumentation'
13
- require 'opentelemetry/metrics'
14
12
  require 'opentelemetry/trace'
13
+ require 'opentelemetry/internal'
15
14
  require 'opentelemetry/version'
16
15
 
17
16
  # OpenTelemetry is an open source observability framework, providing a
@@ -22,7 +21,10 @@ require 'opentelemetry/version'
22
21
  module OpenTelemetry
23
22
  extend self
24
23
 
25
- attr_writer :tracer_provider, :meter_provider, :baggage, :logger, :error_handler
24
+ @mutex = Mutex.new
25
+ @tracer_provider = Internal::ProxyTracerProvider.new
26
+
27
+ attr_writer :propagation, :baggage, :logger, :error_handler
26
28
 
27
29
  # @return [Object, Logger] configured Logger or a default STDOUT Logger.
28
30
  def logger
@@ -43,33 +45,35 @@ module OpenTelemetry
43
45
  error_handler.call(exception: exception, message: message)
44
46
  end
45
47
 
48
+ # Register the global tracer provider.
49
+ #
50
+ # @param [TracerProvider] provider A tracer provider to register as the
51
+ # global instance.
52
+ def tracer_provider=(provider)
53
+ @mutex.synchronize do
54
+ if @tracer_provider.instance_of? Internal::ProxyTracerProvider
55
+ logger.debug("Upgrading default proxy tracer provider to #{provider.class}")
56
+ @tracer_provider.delegate = provider
57
+ end
58
+ @tracer_provider = provider
59
+ end
60
+ end
61
+
46
62
  # @return [Object, Trace::TracerProvider] registered tracer provider or a
47
63
  # default no-op implementation of the tracer provider.
48
64
  def tracer_provider
49
- @tracer_provider ||= Trace::TracerProvider.new
50
- end
51
-
52
- # @return [Object, Metrics::MeterProvider] registered meter provider or a
53
- # default no-op implementation of the meter provider.
54
- def meter_provider
55
- @meter_provider ||= Metrics::MeterProvider.new
56
- end
57
-
58
- # @return [Instrumentation::Registry] registry containing all known
59
- # instrumentation
60
- def instrumentation_registry
61
- @instrumentation_registry ||= Instrumentation::Registry.new
65
+ @mutex.synchronize { @tracer_provider }
62
66
  end
63
67
 
64
- # @return [Object, Baggage::Manager] registered
68
+ # @return [Object, Baggage::NoopManager] registered
65
69
  # baggage manager or a default no-op implementation of the
66
70
  # manager.
67
71
  def baggage
68
- @baggage ||= Baggage::Manager.new
72
+ @baggage ||= Baggage::NoopManager.new
69
73
  end
70
74
 
71
- # @return [Context::Propagation::Propagation] an instance of the propagation API
75
+ # @return [Context::Propagation::Propagator] a propagator instance
72
76
  def propagation
73
- @propagation ||= Context::Propagation::Propagation.new
77
+ @propagation ||= Context::Propagation::NoopTextMapPropagator.new
74
78
  end
75
79
  end
@@ -4,9 +4,12 @@
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
+ require 'opentelemetry/baggage/propagation'
7
8
  require 'opentelemetry/baggage/builder'
9
+ require 'opentelemetry/baggage/entry'
8
10
  require 'opentelemetry/baggage/manager'
9
- require 'opentelemetry/baggage/propagation'
11
+ require 'opentelemetry/baggage/noop_builder'
12
+ require 'opentelemetry/baggage/noop_manager'
10
13
 
11
14
  module OpenTelemetry
12
15
  # The Baggage module provides functionality to record and propagate
@@ -6,13 +6,39 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  module Baggage
9
- # No op implementation of Baggage::Builder
9
+ # Operational implementation of Baggage::Builder
10
10
  class Builder
11
- def set_value(key, value); end
11
+ # @api private
12
+ attr_reader :entries
12
13
 
13
- def remove_value(key); end
14
+ # @api private
15
+ def initialize(entries)
16
+ @entries = entries
17
+ end
14
18
 
15
- def clear; end
19
+ # Set key-value in the to-be-created baggage
20
+ #
21
+ # @param [String] key The key to store this value under
22
+ # @param [String] value String value to be stored under key
23
+ # @param [optional String] metadata This is here to store properties
24
+ # received from other W3C Baggage impelmentations but is not exposed in
25
+ # OpenTelemetry. This is condsidered private API and not for use by
26
+ # end-users.
27
+ def set_value(key, value, metadata: nil)
28
+ @entries[key] = OpenTelemetry::Baggage::Entry.new(value, metadata)
29
+ end
30
+
31
+ # Removes key from the to-be-created baggage
32
+ #
33
+ # @param [String] key The key to remove
34
+ def remove_value(key)
35
+ @entries.delete(key)
36
+ end
37
+
38
+ # Clears all baggage from the to-be-created baggage
39
+ def clear
40
+ @entries.clear
41
+ end
16
42
  end
17
43
  end
18
44
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ # OpenTelemetry Baggage Implementation
9
+ module Baggage
10
+ # Read-only representation of a baggage entry
11
+ class Entry
12
+ attr_reader :value, :metadata
13
+
14
+ def initialize(value, metadata = nil)
15
+ @value = value
16
+ @metadata = metadata
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,35 +6,98 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  module Baggage
9
- # No op implementation of Baggage::Manager
9
+ # Operational Baggage Manager implementation
10
10
  class Manager
11
- NOOP_BUILDER = Builder.new
12
- EMPTY_VALUES = {}.freeze
13
- private_constant(:NOOP_BUILDER, :EMPTY_VALUES)
11
+ BAGGAGE_KEY = OpenTelemetry::Baggage::Propagation::ContextKeys.baggage_key
12
+ EMPTY_BAGGAGE = {}.freeze
13
+ private_constant(:BAGGAGE_KEY, :EMPTY_BAGGAGE)
14
14
 
15
+ # Used to chain modifications to baggage. The result is a
16
+ # context with an updated baggage. If only a single
17
+ # modification is being made to baggage, use the other
18
+ # methods on +Manager+, if multiple modifications are being made, use
19
+ # this one.
20
+ #
21
+ # @param [optional Context] context The context to update with with new
22
+ # modified baggage. Defaults to +Context.current+
23
+ # @return [Context]
15
24
  def build(context: Context.current)
16
- yield NOOP_BUILDER
17
- context
25
+ builder = Builder.new(baggage_for(context).dup)
26
+ yield builder
27
+ context.set_value(BAGGAGE_KEY, builder.entries)
18
28
  end
19
29
 
20
- def set_value(key, value, context: Context.current)
21
- context
30
+ # Returns a new context with empty baggage
31
+ #
32
+ # @param [optional Context] context Context to clear baggage from. Defaults
33
+ # to +Context.current+
34
+ # @return [Context]
35
+ def clear(context: Context.current)
36
+ context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE)
22
37
  end
23
38
 
39
+ # Returns the corresponding baggage.entry (or nil) for key
40
+ #
41
+ # @param [String] key The lookup key
42
+ # @param [optional Context] context The context from which to retrieve
43
+ # the key.
44
+ # Defaults to +Context.current+
45
+ # @return [String]
24
46
  def value(key, context: Context.current)
25
- nil
47
+ baggage_for(context)[key]&.value
26
48
  end
27
49
 
50
+ # Returns the baggage
51
+ #
52
+ # @param [optional Context] context The context from which to retrieve
53
+ # the baggage.
54
+ # Defaults to +Context.current+
55
+ # @return [Hash]
28
56
  def values(context: Context.current)
29
- EMPTY_VALUES
57
+ baggage_for(context).transform_values(&:value)
58
+ end
59
+
60
+ # @api private
61
+ def raw_entries(context: Context.current)
62
+ baggage_for(context).dup.freeze
63
+ end
64
+
65
+ # Returns a new context with new key-value pair
66
+ #
67
+ # @param [String] key The key to store this value under
68
+ # @param [String] value String value to be stored under key
69
+ # @param [optional String] metadata This is here to store properties
70
+ # received from other W3C Baggage impelmentations but is not exposed in
71
+ # OpenTelemetry. This is condsidered private API and not for use by
72
+ # end-users.
73
+ # @param [optional Context] context The context to update with new
74
+ # value. Defaults to +Context.current+
75
+ # @return [Context]
76
+ def set_value(key, value, metadata: nil, context: Context.current)
77
+ new_baggage = baggage_for(context).dup
78
+ new_baggage[key] = Entry.new(value, metadata)
79
+ context.set_value(BAGGAGE_KEY, new_baggage)
30
80
  end
31
81
 
82
+ # Returns a new context with value at key removed
83
+ #
84
+ # @param [String] key The key to remove
85
+ # @param [optional Context] context The context to remove baggage
86
+ # from. Defaults to +Context.current+
87
+ # @return [Context]
32
88
  def remove_value(key, context: Context.current)
33
- context
89
+ baggage = baggage_for(context)
90
+ return context unless baggage.key?(key)
91
+
92
+ new_baggage = baggage.dup
93
+ new_baggage.delete(key)
94
+ context.set_value(BAGGAGE_KEY, new_baggage)
34
95
  end
35
96
 
36
- def clear(context: Context.current)
37
- context
97
+ private
98
+
99
+ def baggage_for(context)
100
+ context.value(BAGGAGE_KEY) || EMPTY_BAGGAGE
38
101
  end
39
102
  end
40
103
  end
@@ -0,0 +1,18 @@
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 Baggage
9
+ # No op implementation of Baggage::Builder
10
+ class NoopBuilder
11
+ def set_value(key, value, metadata: nil); end
12
+
13
+ def remove_value(key); end
14
+
15
+ def clear; end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
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 Baggage
9
+ # No op implementation of Baggage::Manager
10
+ class NoopManager
11
+ NOOP_BUILDER = NoopBuilder.new
12
+ EMPTY_HASH = {}.freeze
13
+ private_constant(:NOOP_BUILDER, :EMPTY_HASH)
14
+
15
+ def build(context: Context.current)
16
+ yield NOOP_BUILDER
17
+ context
18
+ end
19
+
20
+ def set_value(key, value, metadata: nil, context: Context.current)
21
+ context
22
+ end
23
+
24
+ def value(key, context: Context.current)
25
+ nil
26
+ end
27
+
28
+ def values(context: Context.current)
29
+ EMPTY_HASH
30
+ end
31
+
32
+ def raw_entries(context: Context.current)
33
+ EMPTY_HASH
34
+ end
35
+
36
+ def remove_value(key, context: Context.current)
37
+ context
38
+ end
39
+
40
+ def clear(context: Context.current)
41
+ context
42
+ end
43
+ end
44
+ end
45
+ end
@@ -5,52 +5,23 @@
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  require 'opentelemetry/baggage/propagation/context_keys'
8
- require 'opentelemetry/baggage/propagation/text_map_injector'
9
- require 'opentelemetry/baggage/propagation/text_map_extractor'
8
+ require 'opentelemetry/baggage/propagation/text_map_propagator'
10
9
 
11
10
  module OpenTelemetry
12
11
  module Baggage
13
- # The Baggage::Propagation module contains injectors and
14
- # extractors for sending and receiving baggage over the wire
12
+ # The Baggage::Propagation module contains a text map propagator for
13
+ # sending and receiving baggage over the wire.
15
14
  module Propagation
16
15
  extend self
17
16
 
18
- TEXT_MAP_EXTRACTOR = TextMapExtractor.new
19
- 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
- )
17
+ TEXT_MAP_PROPAGATOR = TextMapPropagator.new
26
18
 
27
- private_constant :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR, :RACK_INJECTOR,
28
- :RACK_EXTRACTOR
19
+ private_constant :TEXT_MAP_PROPAGATOR
29
20
 
30
- # Returns an extractor that extracts context using the W3C Baggage
31
- # format
32
- def text_map_injector
33
- TEXT_MAP_INJECTOR
34
- end
35
-
36
- # Returns an injector that injects context using the W3C Baggage
37
- # format
38
- def text_map_extractor
39
- TEXT_MAP_EXTRACTOR
40
- 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
21
+ # Returns a text map propagator that propagates context using the
22
+ # W3C Baggage format.
23
+ def text_map_propagator
24
+ TEXT_MAP_PROPAGATOR
54
25
  end
55
26
  end
56
27
  end