opentelemetry-api 0.17.0 → 1.0.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: 9d983ae124f8d6da3e8fa92560912718bdbbc9a3ea89f2012cb2d51e6d80873d
4
- data.tar.gz: 75bc11d4296b0a21a136b3ada57d6a5cf59c736d61d6d113ab4bbd6195dacb8c
3
+ metadata.gz: b25f500e6cfa87fe641a3db001ae9f6adf772a9a742761ccdc21c43c8e78ea96
4
+ data.tar.gz: 7344a0ae9cdc4030634e28bb21ce19a6369a509b8fb0c56dc085e9ce586fd8e5
5
5
  SHA512:
6
- metadata.gz: 2c051831f433ca25fbbdf4662d7ac8e156804bdb98e6dd5d2476597baac55561edc46d32bb3a02d23f7a316e20aee88b6ea5dfae608813933d8d08d5fdbb7afb
7
- data.tar.gz: 9bd812321d5d84960a4e866a50b1a6b483a6742a4a909118792a72859e7123df0f945fea4476eeb9e5eca6e2b120cfd09eee55475a7ef36f11bafb4e124f1258
6
+ metadata.gz: 7a489fb55dc89f48a164c646bc94ec1f5e63a19329a61bf5461b1d1474e6d2b0e9f606d40f85aa2cafdcff377b3cae5b4b9f2d5b62a9965c42577e61aa0122df
7
+ data.tar.gz: 8fb44ad73536ca545b7f7a61c0e2f37fccc29fc5676abd4ca4eaf0572054f0bb77c70c8bb9220af64c7ff23364b662b2f3212a562569e3bc68c645c71ae447b2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Release History: opentelemetry-api
2
2
 
3
+ ### v1.0.0 / 2021-09-29
4
+
5
+ * (No significant changes)
6
+
7
+ ### v1.0.0.rc3 / 2021-08-12
8
+
9
+ * BREAKING CHANGE: Remove optional parent_context from in_span
10
+ * BREAKING CHANGE: Refactor Baggage to remove Noop*
11
+ * BREAKING CHANGE: Total order constraint on span.status=
12
+
13
+ * ADDED: Add Tracer.non_recording_span to API
14
+ * ADDED: Make API's NoopTextMapPropagator private
15
+ * FIXED: Remove optional parent_context from in_span
16
+ * FIXED: Reduce span allocation in API
17
+ * FIXED: Refactor Baggage to remove Noop*
18
+ * FIXED: Total order constraint on span.status=
19
+ * FIXED: Return early if carrier is nil
20
+ * FIXED: Update context to match spec
21
+ * FIXED: Return the original context if the baggage header value is empty
22
+ * DOCS: Update docs to rely more on environment variable configuration
23
+
24
+ ### v1.0.0.rc2 / 2021-06-23
25
+
26
+ * BREAKING CHANGE: Remove optional parent_context from in_span [729](https://github.com/open-telemetry/opentelemetry-ruby/pull/729)
27
+ * BREAKING CHANGE: Refactor Baggage to remove Noop* [800](https://github.com/open-telemetry/opentelemetry-ruby/pull/800)
28
+ - The noop baggage manger has been removed.
29
+ - The baggage management methods are now available through OpenTelemetry::Baggage#method, previously OpenTelemetry.baggage#method
30
+ * BREAKING CHANGE: Total order constraint on span.status= [805](https://github.com/open-telemetry/opentelemetry-ruby/pull/805)
31
+ - 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
32
+ - The HttpToStatus module can be replaced inline as follows `span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(response_code.to_i)`
33
+ - 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.
34
+
35
+ * ADDED: Add Tracer.non_recording_span to API [799](https://github.com/open-telemetry/opentelemetry-ruby/pull/799)
36
+ * FIXED: Reduce span allocation in API [795](https://github.com/open-telemetry/opentelemetry-ruby/pull/795)
37
+ * FIXED: Return early if carrier is nil [835](https://github.com/open-telemetry/opentelemetry-ruby/pull/835)
38
+ * FIXED: Update context to match spec [807](https://github.com/open-telemetry/opentelemetry-ruby/pull/807)
39
+ - The `Context.current` setter has been removed and the previously private attach/detach methods are now available as class methods on the context module.
40
+
41
+ ### v1.0.0.rc1 / 2021-05-21
42
+
43
+ * BREAKING CHANGE: Remove optional parent_context from in_span
44
+
45
+ * FIXED: Remove optional parent_context from in_span
46
+
3
47
  ### v0.17.0 / 2021-04-22
4
48
 
5
49
  * BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
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
@@ -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
@@ -23,21 +23,20 @@ module OpenTelemetry
23
23
  # span and reraised.
24
24
  # @yield [span, context] yields the newly created span and a context containing the
25
25
  # span to the block.
26
- def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, with_parent: nil)
26
+ def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
27
27
  span = nil
28
- span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent)
28
+ span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind)
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 = '0.17.0'
9
+ VERSION = '1.0.0'
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: 0.17.0
4
+ version: 1.0.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-04-23 00:00:00.000000000 Z
11
+ date: 2021-09-30 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/v0.17.0/file.CHANGELOG.html
190
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.0/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/v0.17.0
193
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v1.0.0
198
194
  post_install_message:
199
195
  rdoc_options: []
200
196
  require_paths:
@@ -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