opentelemetry-api 1.0.0.rc1 → 1.0.1

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: 8c72d994e97f5c64be4418b271fa7f359899afa493910af615521eb785f671c2
4
- data.tar.gz: 11c0b57837eae216f71e63d9d462f28e41fd873b2c33d9ecffe51f15f13a8373
3
+ metadata.gz: b78ad94bb13917c6a8b6202d920944c1465eb634dc9776559a84149974f55b82
4
+ data.tar.gz: 2454e81466acd5b7334a6e46f6f442b3e6a0b1afa8c33bf0fa1efdbdabb74da3
5
5
  SHA512:
6
- metadata.gz: b162dfbf770ef1a162fe2d6826832d1c51a8a019e5bdcc3632ed6449a832cd3c94d98a627687af22b86b7bcc23956a6e9044834c4010d7ac98a37ae33b204a3e
7
- data.tar.gz: aca58a7e39e73ae037429a0ce55b01160d20fdedba2c184dff6c2c34e8f17d2086a963f9e294dcccddea9fe81569ab99c2f28ff0e470dfd52576c4b9e49aad61
6
+ metadata.gz: 6db7e0e3d83ed9c232dc0a88ada719283c24d6fbc9e5863a44c90646b129cef129d1a04a3a7ea12d77aa692db5ba4dc69a96e95e4e680f0045d4917470dcbe29
7
+ data.tar.gz: d534d75d903d70b3db8fb838b9cb8562910cab8c98586f551f71cd9abe46cba97167a5298afa8472edcf3a96613a06b22060e29daecb4bb2d5a37f02c21f0f05
data/CHANGELOG.md CHANGED
@@ -1,10 +1,52 @@
1
1
  # Release History: opentelemetry-api
2
2
 
3
+ ### v1.0.1 / 2021-12-01
4
+
5
+ * FIXED: Deprecate api rack env getter
6
+
7
+ ### v1.0.0 / 2021-09-29
8
+
9
+ * (No significant changes)
10
+
11
+ ### v1.0.0.rc3 / 2021-08-12
12
+
13
+ * BREAKING CHANGE: Remove optional parent_context from in_span
14
+ * BREAKING CHANGE: Refactor Baggage to remove Noop*
15
+ * BREAKING CHANGE: Total order constraint on span.status=
16
+
17
+ * ADDED: Add Tracer.non_recording_span to API
18
+ * ADDED: Make API's NoopTextMapPropagator private
19
+ * FIXED: Remove optional parent_context from in_span
20
+ * FIXED: Reduce span allocation in API
21
+ * FIXED: Refactor Baggage to remove Noop*
22
+ * FIXED: Total order constraint on span.status=
23
+ * FIXED: Return early if carrier is nil
24
+ * FIXED: Update context to match spec
25
+ * FIXED: Return the original context if the baggage header value is empty
26
+ * DOCS: Update docs to rely more on environment variable configuration
27
+
28
+ ### v1.0.0.rc2 / 2021-06-23
29
+
30
+ * BREAKING CHANGE: Remove optional parent_context from in_span [729](https://github.com/open-telemetry/opentelemetry-ruby/pull/729)
31
+ * BREAKING CHANGE: Refactor Baggage to remove Noop* [800](https://github.com/open-telemetry/opentelemetry-ruby/pull/800)
32
+ - The noop baggage manger has been removed.
33
+ - The baggage management methods are now available through OpenTelemetry::Baggage#method, previously OpenTelemetry.baggage#method
34
+ * BREAKING CHANGE: Total order constraint on span.status= [805](https://github.com/open-telemetry/opentelemetry-ruby/pull/805)
35
+ - The OpenTelemetry::Trace::Util::HttpToStatus module has been removed as it was incorrectly setting the span status to OK for codes codes in the range 100..399
36
+ - The HttpToStatus module can be replaced inline as follows `span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(response_code.to_i)`
37
+ - The `Status.new(code, description:)` initializer has been hidden in favour of simpler constructors for each status code: `Status.ok`, `Status.error` and `Status.unset`. Each constructor takes an optional description.
38
+
39
+ * ADDED: Add Tracer.non_recording_span to API [799](https://github.com/open-telemetry/opentelemetry-ruby/pull/799)
40
+ * FIXED: Reduce span allocation in API [795](https://github.com/open-telemetry/opentelemetry-ruby/pull/795)
41
+ * FIXED: Return early if carrier is nil [835](https://github.com/open-telemetry/opentelemetry-ruby/pull/835)
42
+ * FIXED: Update context to match spec [807](https://github.com/open-telemetry/opentelemetry-ruby/pull/807)
43
+ - The `Context.current` setter has been removed and the previously private attach/detach methods are now available as class methods on the context module.
44
+
3
45
  ### v1.0.0.rc1 / 2021-05-21
4
46
 
5
47
  * BREAKING CHANGE: Remove optional parent_context from in_span
6
48
 
7
- * FIXED: Remove optional parent_context from in_span
49
+ * FIXED: Remove optional parent_context from in_span
8
50
 
9
51
  ### v0.17.0 / 2021-04-22
10
52
 
data/README.md CHANGED
@@ -29,11 +29,11 @@ Then, use the OpenTelemetry interfaces to produces traces and other telemetry da
29
29
  ```ruby
30
30
  require 'opentelemetry'
31
31
 
32
- # Obtain the current default tracer factory
33
- factory = OpenTelemetry.tracer_factory
32
+ # Obtain the current default tracer provider
33
+ provider = OpenTelemetry.tracer_provider
34
34
 
35
35
  # Create a trace
36
- tracer = factory.tracer('my_app', '1.0')
36
+ tracer = provider.tracer('my_app', '1.0')
37
37
 
38
38
  # Record spans
39
39
  tracer.in_span('my_task') do |task_span|
@@ -29,7 +29,7 @@ module OpenTelemetry
29
29
  # will be used to write context into the carrier, otherwise the default
30
30
  # text map setter will be used.
31
31
  def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter)
32
- baggage = OpenTelemetry.baggage.raw_entries(context: context)
32
+ baggage = OpenTelemetry::Baggage.raw_entries(context: context)
33
33
 
34
34
  return if baggage.nil? || baggage.empty?
35
35
 
@@ -39,7 +39,8 @@ module OpenTelemetry
39
39
  end
40
40
 
41
41
  # Extract remote baggage from the supplied carrier.
42
- # If extraction fails, the original context will be returned
42
+ # If extraction fails or there is no baggage to extract,
43
+ # then the original context will be returned
43
44
  #
44
45
  # @param [Carrier] carrier The carrier to get the header from
45
46
  # @param [optional Context] context Context to be updated with the baggage
@@ -52,10 +53,11 @@ module OpenTelemetry
52
53
  # if extraction fails
53
54
  def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
54
55
  header = getter.get(carrier, BAGGAGE_KEY)
56
+ return context if header.nil? || header.empty?
55
57
 
56
58
  entries = header.gsub(/\s/, '').split(',')
57
59
 
58
- OpenTelemetry.baggage.build(context: context) do |builder|
60
+ OpenTelemetry::Baggage.build(context: context) do |builder|
59
61
  entries.each do |entry|
60
62
  # Note metadata is currently unused in OpenTelemetry, but is part
61
63
  # the W3C spec where it's referred to as properties. We preserve
@@ -7,13 +7,103 @@
7
7
  require 'opentelemetry/baggage/propagation'
8
8
  require 'opentelemetry/baggage/builder'
9
9
  require 'opentelemetry/baggage/entry'
10
- require 'opentelemetry/baggage/manager'
11
- require 'opentelemetry/baggage/noop_builder'
12
- require 'opentelemetry/baggage/noop_manager'
13
10
 
14
11
  module OpenTelemetry
15
12
  # The Baggage module provides functionality to record and propagate
16
13
  # baggage in a distributed trace
17
14
  module Baggage
15
+ extend self
16
+
17
+ BAGGAGE_KEY = OpenTelemetry::Baggage::Propagation::ContextKeys.baggage_key
18
+ EMPTY_BAGGAGE = {}.freeze
19
+ private_constant(:BAGGAGE_KEY, :EMPTY_BAGGAGE)
20
+
21
+ # Used to chain modifications to baggage. The result is a
22
+ # context with an updated baggage. If only a single
23
+ # modification is being made to baggage, use the other
24
+ # methods on +Baggage+, if multiple modifications are being made, use
25
+ # this one.
26
+ #
27
+ # @param [optional Context] context The context to update with with new
28
+ # modified baggage. Defaults to +Context.current+
29
+ # @return [Context]
30
+ def build(context: Context.current)
31
+ builder = Builder.new(baggage_for(context).dup)
32
+ yield builder
33
+ context.set_value(BAGGAGE_KEY, builder.entries)
34
+ end
35
+
36
+ # Returns a new context with empty baggage
37
+ #
38
+ # @param [optional Context] context Context to clear baggage from. Defaults
39
+ # to +Context.current+
40
+ # @return [Context]
41
+ def clear(context: Context.current)
42
+ context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE)
43
+ end
44
+
45
+ # Returns the corresponding baggage.entry (or nil) for key
46
+ #
47
+ # @param [String] key The lookup key
48
+ # @param [optional Context] context The context from which to retrieve
49
+ # the key.
50
+ # Defaults to +Context.current+
51
+ # @return [String]
52
+ def value(key, context: Context.current)
53
+ baggage_for(context)[key]&.value
54
+ end
55
+
56
+ # Returns the baggage
57
+ #
58
+ # @param [optional Context] context The context from which to retrieve
59
+ # the baggage.
60
+ # Defaults to +Context.current+
61
+ # @return [Hash]
62
+ def values(context: Context.current)
63
+ baggage_for(context).transform_values(&:value)
64
+ end
65
+
66
+ # @api private
67
+ def raw_entries(context: Context.current)
68
+ baggage_for(context).dup.freeze
69
+ end
70
+
71
+ # Returns a new context with new key-value pair
72
+ #
73
+ # @param [String] key The key to store this value under
74
+ # @param [String] value String value to be stored under key
75
+ # @param [optional String] metadata This is here to store properties
76
+ # received from other W3C Baggage impelmentations but is not exposed in
77
+ # OpenTelemetry. This is condsidered private API and not for use by
78
+ # end-users.
79
+ # @param [optional Context] context The context to update with new
80
+ # value. Defaults to +Context.current+
81
+ # @return [Context]
82
+ def set_value(key, value, metadata: nil, context: Context.current)
83
+ new_baggage = baggage_for(context).dup
84
+ new_baggage[key] = Entry.new(value, metadata)
85
+ context.set_value(BAGGAGE_KEY, new_baggage)
86
+ end
87
+
88
+ # Returns a new context with value at key removed
89
+ #
90
+ # @param [String] key The key to remove
91
+ # @param [optional Context] context The context to remove baggage
92
+ # from. Defaults to +Context.current+
93
+ # @return [Context]
94
+ def remove_value(key, context: Context.current)
95
+ baggage = baggage_for(context)
96
+ return context unless baggage.key?(key)
97
+
98
+ new_baggage = baggage.dup
99
+ new_baggage.delete(key)
100
+ context.set_value(BAGGAGE_KEY, new_baggage)
101
+ end
102
+
103
+ private
104
+
105
+ def baggage_for(context)
106
+ context.value(BAGGAGE_KEY) || EMPTY_BAGGAGE
107
+ end
18
108
  end
19
109
  end
@@ -7,41 +7,17 @@
7
7
  module OpenTelemetry
8
8
  class Context
9
9
  module Propagation
10
- # A no-op text map propagator implementation
10
+ # @api private
11
11
  class NoopTextMapPropagator
12
12
  EMPTY_LIST = [].freeze
13
13
  private_constant(:EMPTY_LIST)
14
14
 
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.
23
15
  def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter); end
24
16
 
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
37
17
  def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
38
18
  context
39
19
  end
40
20
 
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.
45
21
  def fields
46
22
  EMPTY_LIST
47
23
  end
@@ -7,6 +7,9 @@
7
7
  module OpenTelemetry
8
8
  class Context
9
9
  module Propagation
10
+ # @deprecated Use the rack env getter found in the
11
+ # opentelemetry-common gem instead.
12
+
10
13
  # The RackEnvGetter class provides a common methods for reading
11
14
  # keys from a rack environment. It abstracts away the rack-normalization
12
15
  # process so that keys can be looked up without having to transform them
@@ -67,9 +67,13 @@ module OpenTelemetry
67
67
  TEXT_MAP_SETTER
68
68
  end
69
69
 
70
+ # @deprecated Use the rack env getter found in the
71
+ # opentelemetry-common gem instead.
70
72
  # Returns a {RackEnvGetter} instance suitable for reading values from a
71
73
  # Rack environment.
72
74
  def rack_env_getter
75
+ OpenTelemetry.logger.warn('OpenTelemetry::Context::Propagation.rack_env_getter has been deprecated \
76
+ use OpenTelemetry::Common::Propagation.rack_env_getter from the opentelemetry-common gem instead.')
73
77
  RACK_ENV_GETTER
74
78
  end
75
79
  end
@@ -10,8 +10,11 @@ require 'opentelemetry/context/propagation'
10
10
  module OpenTelemetry
11
11
  # Manages context on a per-fiber basis
12
12
  class Context
13
- KEY = :__opentelemetry_context__
14
13
  EMPTY_ENTRIES = {}.freeze
14
+ STACK_KEY = :__opentelemetry_context_storage__
15
+ private_constant :EMPTY_ENTRIES, :STACK_KEY
16
+
17
+ DetachError = Class.new(OpenTelemetry::Error)
15
18
 
16
19
  class << self
17
20
  # Returns a key used to index a value in a Context
@@ -26,14 +29,36 @@ module OpenTelemetry
26
29
  #
27
30
  # @return [Context]
28
31
  def current
29
- Thread.current[KEY] ||= ROOT
32
+ stack.last || ROOT
30
33
  end
31
34
 
32
- # Sets the current context
35
+ # Associates a Context with the caller's current Fiber. Every call to
36
+ # this operation should be paired with a corresponding call to detach.
33
37
  #
34
- # @param [Context] ctx The context to be made active
35
- def current=(ctx)
36
- Thread.current[KEY] = ctx
38
+ # Returns a token to be used with the matching call to detach
39
+ #
40
+ # @param [Context] context The new context
41
+ # @return [Object] A token to be used when detaching
42
+ def attach(context)
43
+ s = stack
44
+ s.push(context)
45
+ s.size
46
+ end
47
+
48
+ # Restores the previous Context associated with the current Fiber.
49
+ # The supplied token is used to check if the call to detach is balanced
50
+ # with a corresponding attach call. A warning is logged if the
51
+ # calls are unbalanced.
52
+ #
53
+ # @param [Object] token The token provided by the matching call to attach
54
+ # @return [Boolean] True if the calls matched, false otherwise
55
+ def detach(token)
56
+ s = stack
57
+ calls_matched = (token == s.size)
58
+ OpenTelemetry.handle_error(exception: DetachError.new('calls to detach should match corresponding calls to attach.')) unless calls_matched
59
+
60
+ s.pop
61
+ calls_matched
37
62
  end
38
63
 
39
64
  # Executes a block with ctx as the current context. It restores
@@ -42,10 +67,10 @@ module OpenTelemetry
42
67
  # @param [Context] ctx The context to be made active
43
68
  # @yield [context] Yields context to the block
44
69
  def with_current(ctx)
45
- prev = ctx.attach
70
+ token = attach(ctx)
46
71
  yield ctx
47
72
  ensure
48
- ctx.detach(prev)
73
+ detach(token)
49
74
  end
50
75
 
51
76
  # Execute a block in a new context with key set to value. Restores the
@@ -58,10 +83,10 @@ module OpenTelemetry
58
83
  # the block
59
84
  def with_value(key, value)
60
85
  ctx = current.set_value(key, value)
61
- prev = ctx.attach
86
+ token = attach(ctx)
62
87
  yield ctx, value
63
88
  ensure
64
- ctx.detach(prev)
89
+ detach(token)
65
90
  end
66
91
 
67
92
  # Execute a block in a new context where its values are merged with the
@@ -75,10 +100,10 @@ module OpenTelemetry
75
100
  # to the block
76
101
  def with_values(values)
77
102
  ctx = current.set_values(values)
78
- prev = ctx.attach
103
+ token = attach(ctx)
79
104
  yield ctx, values
80
105
  ensure
81
- ctx.detach(prev)
106
+ detach(token)
82
107
  end
83
108
 
84
109
  # Returns the value associated with key in the current context
@@ -89,16 +114,21 @@ module OpenTelemetry
89
114
  end
90
115
 
91
116
  def clear
92
- self.current = ROOT
117
+ stack.clear
93
118
  end
94
119
 
95
120
  def empty
96
- new(nil, EMPTY_ENTRIES)
121
+ new(EMPTY_ENTRIES)
122
+ end
123
+
124
+ private
125
+
126
+ def stack
127
+ Thread.current[STACK_KEY] ||= []
97
128
  end
98
129
  end
99
130
 
100
- def initialize(parent, entries)
101
- @parent = parent
131
+ def initialize(entries)
102
132
  @entries = entries.freeze
103
133
  end
104
134
 
@@ -120,7 +150,7 @@ module OpenTelemetry
120
150
  def set_value(key, value)
121
151
  new_entries = @entries.dup
122
152
  new_entries[key] = value
123
- Context.new(self, new_entries)
153
+ Context.new(new_entries)
124
154
  end
125
155
 
126
156
  # Returns a new Context with the current context's entries merged with the
@@ -131,22 +161,7 @@ module OpenTelemetry
131
161
  # @param [Object] value Object to be stored under key
132
162
  # @return [Context]
133
163
  def set_values(values) # rubocop:disable Naming/AccessorMethodName:
134
- Context.new(self, @entries.merge(values))
135
- end
136
-
137
- # @api private
138
- def attach
139
- prev = self.class.current
140
- self.class.current = self
141
- prev
142
- end
143
-
144
- # @api private
145
- def detach(ctx_to_attach = nil)
146
- OpenTelemetry.logger.warn 'Calls to detach should match corresponding calls to attach' if self.class.current != self
147
-
148
- ctx_to_attach ||= @parent || ROOT
149
- ctx_to_attach.attach
164
+ Context.new(@entries.merge(values))
150
165
  end
151
166
 
152
167
  ROOT = empty.freeze
@@ -8,7 +8,7 @@ module OpenTelemetry
8
8
  module Trace
9
9
  module Propagation
10
10
  module TraceContext
11
- # Propagates baggage using the W3C Trace Context format
11
+ # Propagates trace context using the W3C Trace Context format
12
12
  class TextMapPropagator
13
13
  TRACEPARENT_KEY = 'traceparent'
14
14
  TRACESTATE_KEY = 'tracestate'
@@ -53,7 +53,7 @@ module OpenTelemetry
53
53
  trace_flags: tp.flags,
54
54
  tracestate: tracestate,
55
55
  remote: true)
56
- span = Trace::Span.new(span_context: span_context)
56
+ span = OpenTelemetry::Trace.non_recording_span(span_context)
57
57
  OpenTelemetry::Trace.context_with_span(span)
58
58
  rescue OpenTelemetry::Error
59
59
  context
@@ -4,15 +4,41 @@
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
- require 'opentelemetry/trace/util/http_to_status'
8
-
9
7
  module OpenTelemetry
10
8
  module Trace
11
9
  # Status represents the status of a finished {Span}. It is composed of a
12
10
  # status code in conjunction with an optional descriptive message.
13
11
  class Status
14
- # Convenience utility, not in API spec:
15
- extend Util::HttpToStatus
12
+ class << self
13
+ private :new # rubocop:disable Style/AccessModifierDeclarations
14
+
15
+ # Returns a newly created {Status} with code == UNSET and an optional
16
+ # description.
17
+ #
18
+ # @param [String] description
19
+ # @return [Status]
20
+ def unset(description = '')
21
+ new(UNSET, description: description)
22
+ end
23
+
24
+ # Returns a newly created {Status} with code == OK and an optional
25
+ # description.
26
+ #
27
+ # @param [String] description
28
+ # @return [Status]
29
+ def ok(description = '')
30
+ new(OK, description: description)
31
+ end
32
+
33
+ # Returns a newly created {Status} with code == ERROR and an optional
34
+ # description.
35
+ #
36
+ # @param [String] description
37
+ # @return [Status]
38
+ def error(description = '')
39
+ new(ERROR, description: description)
40
+ end
41
+ end
16
42
 
17
43
  # Retrieve the status code of this Status.
18
44
  #
@@ -24,7 +50,10 @@ module OpenTelemetry
24
50
  # @return [String]
25
51
  attr_reader :description
26
52
 
27
- # Initialize a Status.
53
+ # @api private
54
+ # The constructor is private and only for use internally by the class.
55
+ # Users should use the {unset}, {error}, or {ok} factory methods to
56
+ # obtain a {Status} instance.
28
57
  #
29
58
  # @param [Integer] code One of the status codes below
30
59
  # @param [String] description
@@ -29,15 +29,14 @@ module OpenTelemetry
29
29
  Trace.with_span(span) { |s, c| yield s, c }
30
30
  rescue Exception => e # rubocop:disable Lint/RescueException
31
31
  span&.record_exception(e)
32
- span&.status = Status.new(Status::ERROR,
33
- description: "Unhandled exception of type: #{e.class}")
32
+ span&.status = Status.error("Unhandled exception of type: #{e.class}")
34
33
  raise e
35
34
  ensure
36
35
  span&.finish
37
36
  end
38
37
 
39
38
  def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
40
- Span.new
39
+ Span::INVALID
41
40
  end
42
41
 
43
42
  # Used when a caller wants to manage the activation/deactivation and lifecycle of
@@ -49,12 +48,12 @@ module OpenTelemetry
49
48
  #
50
49
  # @return [Span]
51
50
  def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
52
- span_context = OpenTelemetry::Trace.current_span(with_parent).context
51
+ span = OpenTelemetry::Trace.current_span(with_parent)
53
52
 
54
- if span_context.valid?
55
- Span.new(span_context: span_context)
53
+ if span.context.valid?
54
+ span
56
55
  else
57
- Span.new
56
+ Span::INVALID
58
57
  end
59
58
  end
60
59
  end
@@ -81,6 +81,16 @@ module OpenTelemetry
81
81
  def with_span(span)
82
82
  Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
83
83
  end
84
+
85
+ # Wraps a SpanContext with an object implementing the Span interface. This is done in order
86
+ # to expose a SpanContext as a Span in operations such as in-process Span propagation.
87
+ #
88
+ # @param [SpanContext] span_context SpanContext to be wrapped
89
+ #
90
+ # @return [Span]
91
+ def non_recording_span(span_context)
92
+ Span.new(span_context: span_context)
93
+ end
84
94
  end
85
95
  end
86
96
 
@@ -6,5 +6,5 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  ## Current OpenTelemetry version
9
- VERSION = '1.0.0.rc1'
9
+ VERSION = '1.0.1'
10
10
  end
data/lib/opentelemetry.rb CHANGED
@@ -24,7 +24,7 @@ module OpenTelemetry
24
24
  @mutex = Mutex.new
25
25
  @tracer_provider = Internal::ProxyTracerProvider.new
26
26
 
27
- attr_writer :propagation, :baggage, :logger, :error_handler
27
+ attr_writer :propagation, :logger, :error_handler
28
28
 
29
29
  # @return [Object, Logger] configured Logger or a default STDOUT Logger.
30
30
  def logger
@@ -65,13 +65,6 @@ module OpenTelemetry
65
65
  @mutex.synchronize { @tracer_provider }
66
66
  end
67
67
 
68
- # @return [Object, Baggage::NoopManager] registered
69
- # baggage manager or a default no-op implementation of the
70
- # manager.
71
- def baggage
72
- @baggage ||= Baggage::NoopManager.new
73
- end
74
-
75
68
  # @return [Context::Propagation::Propagator] a propagator instance
76
69
  def propagation
77
70
  @propagation ||= Context::Propagation::NoopTextMapPropagator.new
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: 1.0.0.rc1
4
+ version: 1.0.1
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-05-21 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ipsa
@@ -152,9 +152,6 @@ files:
152
152
  - lib/opentelemetry/baggage.rb
153
153
  - lib/opentelemetry/baggage/builder.rb
154
154
  - lib/opentelemetry/baggage/entry.rb
155
- - lib/opentelemetry/baggage/manager.rb
156
- - lib/opentelemetry/baggage/noop_builder.rb
157
- - lib/opentelemetry/baggage/noop_manager.rb
158
155
  - lib/opentelemetry/baggage/propagation.rb
159
156
  - lib/opentelemetry/baggage/propagation/context_keys.rb
160
157
  - lib/opentelemetry/baggage/propagation/text_map_propagator.rb
@@ -185,16 +182,15 @@ files:
185
182
  - lib/opentelemetry/trace/tracer.rb
186
183
  - lib/opentelemetry/trace/tracer_provider.rb
187
184
  - lib/opentelemetry/trace/tracestate.rb
188
- - lib/opentelemetry/trace/util/http_to_status.rb
189
185
  - lib/opentelemetry/version.rb
190
186
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
191
187
  licenses:
192
188
  - Apache-2.0
193
189
  metadata:
194
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.0.rc1/file.CHANGELOG.html
190
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.1/file.CHANGELOG.html
195
191
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/api
196
192
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
197
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.0.rc1
193
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.1
198
194
  post_install_message:
199
195
  rdoc_options: []
200
196
  require_paths:
@@ -206,9 +202,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
202
  version: 2.5.0
207
203
  required_rubygems_version: !ruby/object:Gem::Requirement
208
204
  requirements:
209
- - - ">"
205
+ - - ">="
210
206
  - !ruby/object:Gem::Version
211
- version: 1.3.1
207
+ version: '0'
212
208
  requirements: []
213
209
  rubygems_version: 3.1.6
214
210
  signing_key:
@@ -1,104 +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 Baggage
9
- # Operational Baggage Manager implementation
10
- class Manager
11
- BAGGAGE_KEY = OpenTelemetry::Baggage::Propagation::ContextKeys.baggage_key
12
- EMPTY_BAGGAGE = {}.freeze
13
- private_constant(:BAGGAGE_KEY, :EMPTY_BAGGAGE)
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]
24
- def build(context: Context.current)
25
- builder = Builder.new(baggage_for(context).dup)
26
- yield builder
27
- context.set_value(BAGGAGE_KEY, builder.entries)
28
- end
29
-
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)
37
- end
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]
46
- def value(key, context: Context.current)
47
- baggage_for(context)[key]&.value
48
- end
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]
56
- def values(context: Context.current)
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)
80
- end
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]
88
- def remove_value(key, context: Context.current)
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)
95
- end
96
-
97
- private
98
-
99
- def baggage_for(context)
100
- context.value(BAGGAGE_KEY) || EMPTY_BAGGAGE
101
- end
102
- end
103
- end
104
- end
@@ -1,18 +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 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
@@ -1,45 +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 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
@@ -1,28 +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 Trace
9
- module Util
10
- # Convenience methods, not necessarily required by the API specification.
11
- module HttpToStatus
12
- # Maps numeric HTTP status codes to Trace::Status. This module is a mixin for Trace::Status
13
- # and is not intended for standalone use.
14
- #
15
- # @param code Numeric HTTP status
16
- # @return Status
17
- def http_to_status(code)
18
- case code.to_i
19
- when 100..399
20
- new(const_get(:OK))
21
- else
22
- new(const_get(:ERROR))
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end