opentelemetry-api 0.10.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/LICENSE +1 -1
  4. data/README.md +2 -2
  5. data/lib/opentelemetry-api.rb +1 -1
  6. data/lib/opentelemetry.rb +22 -4
  7. data/lib/opentelemetry/baggage.rb +1 -1
  8. data/lib/opentelemetry/baggage/builder.rb +1 -1
  9. data/lib/opentelemetry/baggage/manager.rb +1 -1
  10. data/lib/opentelemetry/baggage/propagation.rb +3 -23
  11. data/lib/opentelemetry/baggage/propagation/context_keys.rb +1 -1
  12. data/lib/opentelemetry/baggage/propagation/text_map_extractor.rb +13 -16
  13. data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +13 -16
  14. data/lib/opentelemetry/context.rb +1 -1
  15. data/lib/opentelemetry/context/key.rb +1 -1
  16. data/lib/opentelemetry/context/propagation.rb +29 -4
  17. data/lib/opentelemetry/context/propagation/composite_propagator.rb +11 -12
  18. data/lib/opentelemetry/context/propagation/noop_extractor.rb +2 -2
  19. data/lib/opentelemetry/context/propagation/noop_injector.rb +1 -1
  20. data/lib/opentelemetry/context/propagation/propagator.rb +11 -11
  21. data/lib/opentelemetry/context/propagation/rack_env_getter.rb +46 -0
  22. data/lib/opentelemetry/context/propagation/text_map_getter.rb +27 -0
  23. data/lib/opentelemetry/context/propagation/text_map_setter.rb +21 -0
  24. data/lib/opentelemetry/error.rb +1 -1
  25. data/lib/opentelemetry/instrumentation.rb +1 -1
  26. data/lib/opentelemetry/instrumentation/base.rb +1 -1
  27. data/lib/opentelemetry/instrumentation/registry.rb +2 -3
  28. data/lib/opentelemetry/metrics.rb +1 -1
  29. data/lib/opentelemetry/metrics/handles.rb +1 -1
  30. data/lib/opentelemetry/metrics/instruments.rb +1 -1
  31. data/lib/opentelemetry/metrics/meter.rb +1 -1
  32. data/lib/opentelemetry/metrics/meter_provider.rb +1 -1
  33. data/lib/opentelemetry/trace.rb +15 -4
  34. data/lib/opentelemetry/trace/link.rb +1 -1
  35. data/lib/opentelemetry/trace/propagation.rb +1 -1
  36. data/lib/opentelemetry/trace/propagation/trace_context.rb +5 -24
  37. data/lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb +14 -21
  38. data/lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb +14 -19
  39. data/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +1 -1
  40. data/lib/opentelemetry/trace/span.rb +6 -2
  41. data/lib/opentelemetry/trace/span_context.rb +3 -3
  42. data/lib/opentelemetry/trace/span_kind.rb +1 -1
  43. data/lib/opentelemetry/trace/status.rb +1 -1
  44. data/lib/opentelemetry/trace/trace_flags.rb +1 -1
  45. data/lib/opentelemetry/trace/tracer.rb +1 -1
  46. data/lib/opentelemetry/trace/tracer_provider.rb +1 -1
  47. data/lib/opentelemetry/trace/tracestate.rb +158 -0
  48. data/lib/opentelemetry/trace/util/http_to_status.rb +1 -1
  49. data/lib/opentelemetry/version.rb +2 -2
  50. metadata +9 -8
  51. data/lib/opentelemetry/context/propagation/default_getter.rb +0 -26
  52. data/lib/opentelemetry/context/propagation/default_setter.rb +0 -26
  53. data/lib/opentelemetry/context/propagation/propagation.rb +0 -27
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2020 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
  module OpenTelemetry
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -85,9 +85,13 @@ module OpenTelemetry
85
85
  # can be recorded on a span.
86
86
  #
87
87
  # @param [Exception] exception The exception to recorded
88
+ # @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
89
+ # attributes One or more key:value pairs, where the keys must be
90
+ # strings and the values may be (array of) string, boolean or numeric
91
+ # type.
88
92
  #
89
93
  # @return [void]
90
- def record_exception(exception); end
94
+ def record_exception(exception, attributes: nil); end
91
95
 
92
96
  # Sets the Status to the Span
93
97
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -18,14 +18,14 @@ module OpenTelemetry
18
18
  # @param [optional String] trace_id The trace ID associated with a {Span}.
19
19
  # @param [optional String] span_id The span ID associated with a {Span}.
20
20
  # @param [optional TraceFlags] trace_flags The trace flags associated with a {Span}.
21
- # @param [optional String] tracestate The tracestate associated with a {Span}. May be nil.
21
+ # @param [optional Tracestate] tracestate The tracestate associated with a {Span}. May be nil.
22
22
  # @param [optional Boolean] remote Whether the {SpanContext} was extracted from the wire.
23
23
  # @return [SpanContext]
24
24
  def initialize(
25
25
  trace_id: Trace.generate_trace_id,
26
26
  span_id: Trace.generate_span_id,
27
27
  trace_flags: TraceFlags::DEFAULT,
28
- tracestate: nil,
28
+ tracestate: Tracestate::DEFAULT,
29
29
  remote: false
30
30
  )
31
31
  @trace_id = trace_id
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -0,0 +1,158 @@
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
+ # Tracestate is a part of SpanContext, represented by an immutable list of
10
+ # string key/value pairs and formally defined by the W3C Trace Context
11
+ # specification https://www.w3.org/TR/trace-context/
12
+ class Tracestate
13
+ class << self
14
+ private :new # rubocop:disable Style/AccessModifierDeclarations
15
+
16
+ # Returns a newly created Tracestate parsed from the header provided.
17
+ #
18
+ # @param [String] header Encoding of the tracestate header defined by
19
+ # the W3C Trace Context specification https://www.w3.org/TR/trace-context/
20
+ # @return [Tracestate] A new Tracestate instance or DEFAULT
21
+ def from_string(header) # rubocop:disable Metrics/CyclomaticComplexity:
22
+ return DEFAULT if header.nil? || header.empty?
23
+
24
+ hash = header.split(',').each_with_object({}) do |member, memo|
25
+ member.strip!
26
+ kv = member.split('=')
27
+ k, v = *kv
28
+ next unless kv.length == 2 && VALID_KEY.match?(k) && VALID_VALUE.match?(v)
29
+
30
+ memo[k] = v
31
+ end
32
+ return DEFAULT if hash.empty?
33
+
34
+ new(hash)
35
+ end
36
+
37
+ # Returns a Tracestate created from a Hash.
38
+ #
39
+ # @param [Hash<String, String>] hash Key-value pairs to store in the
40
+ # Tracestate. Keys and values are validated against the W3C Trace
41
+ # Context specification, and any invalid members are logged at
42
+ # DEBUG level and dropped.
43
+ # @return [Tracestate] A new Tracestate instance or DEFAULT
44
+ def from_hash(hash)
45
+ hash = hash.select do |k, v|
46
+ valid = VALID_KEY.match?(k) && VALID_VALUE.match?(v)
47
+ OpenTelemetry.logger.debug("Invalid Tracestate member - #{k} : #{v}") unless valid
48
+ valid
49
+ end
50
+ new(hash)
51
+ end
52
+
53
+ # @api private
54
+ # Returns a new Tracestate created from the Hash provided. This
55
+ # skips validation of the keys and values, assuming they are already
56
+ # valid.
57
+ # This method is intended only for the use of instance methods in
58
+ # this class.
59
+ def create(hash)
60
+ new(hash)
61
+ end
62
+ end
63
+
64
+ MAX_MEMBER_COUNT = 32 # Defined by https://www.w3.org/TR/trace-context/
65
+ VALID_KEY = Regexp.union(%r(^[a-z][a-z0-9_\-*/]{,255}$), %r(^[a-z0-9][a-z0-9_\-*/]{,240}@[a-z][a-z0-9_\-*/]{,13}$)).freeze
66
+ VALID_VALUE = /^[ -~&&[^,=]]{,255}[!-~&&[^,=]]$/.freeze
67
+ private_constant(:MAX_MEMBER_COUNT, :VALID_KEY, :VALID_VALUE)
68
+
69
+ # @api private
70
+ # The constructor is private and only for use internally by the class.
71
+ # Users should use the {from_hash} or {from_string} factory methods to
72
+ # obtain a {Tracestate} instance.
73
+ #
74
+ # @param [Hash<String, String>] hash Key-value pairs
75
+ # @return [Tracestate]
76
+ def initialize(hash)
77
+ excess = hash.size - MAX_MEMBER_COUNT
78
+ hash = Hash[hash.drop(excess)] if excess.positive?
79
+ @hash = hash.freeze
80
+ end
81
+
82
+ # Returns the value associated with the given key, or nil if the key
83
+ # is not present.
84
+ #
85
+ # @param [String] key The key to lookup.
86
+ # @return [String] The value associated with the key, or nil.
87
+ def value(key)
88
+ @hash[key]
89
+ end
90
+
91
+ alias [] value
92
+
93
+ # Adds a new key/value pair or updates an existing value for a given key.
94
+ # Keys and values are validated against the W3C Trace Context
95
+ # specification, and any invalid members are logged at DEBUG level and
96
+ # ignored.
97
+ #
98
+ # @param [String] key The key to add or update.
99
+ # @param [String] value The value to add or update.
100
+ # @return [Tracestate] self, if unchanged, or a new Tracestate containing
101
+ # the new or updated key/value pair.
102
+ def set_value(key, value)
103
+ return self unless VALID_KEY.match?(key) && VALID_VALUE.match?(value)
104
+
105
+ h = Hash[@hash]
106
+ h[key] = value
107
+ self.class.create(h)
108
+ end
109
+
110
+ # Deletes the key/value pair associated with the given key.
111
+ #
112
+ # @param [String] key The key to remove.
113
+ # @return [Tracestate] self, if unchanged, or a new Tracestate without
114
+ # the specified key.
115
+ def delete(key)
116
+ return self unless @hash.key?(key)
117
+
118
+ h = Hash[@hash]
119
+ h.delete(key)
120
+ self.class.create(h)
121
+ end
122
+
123
+ # Returns this Tracestate encoded according to the W3C Trace Context
124
+ # specification https://www.w3.org/TR/trace-context/
125
+ #
126
+ # @return [String] this Tracestate encoded as a string.
127
+ def to_s
128
+ @hash.inject(+'') do |memo, (k, v)|
129
+ memo << k << '=' << v << ','
130
+ end.chop! || ''
131
+ end
132
+
133
+ # Returns this Tracestate as a Hash.
134
+ #
135
+ # @return [Hash] the members of this Tracestate
136
+ def to_h
137
+ @hash.dup
138
+ end
139
+
140
+ # Returns true if this Tracestate is empty.
141
+ #
142
+ # @return [Boolean] true if this Tracestate is empty, else false.
143
+ def empty?
144
+ @hash.empty?
145
+ end
146
+
147
+ # Returns true if this Tracestate equals other.
148
+ #
149
+ # @param [Tracestate] other The Tracestate for comparison.
150
+ # @return [Boolean] true if this Tracestate == other, else false.
151
+ def ==(other)
152
+ @hash == other.to_h
153
+ end
154
+
155
+ DEFAULT = new({})
156
+ end
157
+ end
158
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  module OpenTelemetry
8
8
  ## Current OpenTelemetry version
9
- VERSION = '0.10.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.10.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: 2020-12-03 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
@@ -189,16 +189,17 @@ files:
189
189
  - lib/opentelemetry/trace/trace_flags.rb
190
190
  - lib/opentelemetry/trace/tracer.rb
191
191
  - lib/opentelemetry/trace/tracer_provider.rb
192
+ - lib/opentelemetry/trace/tracestate.rb
192
193
  - lib/opentelemetry/trace/util/http_to_status.rb
193
194
  - lib/opentelemetry/version.rb
194
195
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
195
196
  licenses:
196
197
  - Apache-2.0
197
198
  metadata:
198
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.10.0/file.CHANGELOG.html
199
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/api
199
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.14.0/file.CHANGELOG.html
200
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/api
200
201
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
201
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.10.0
202
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-api/v0.14.0
202
203
  post_install_message:
203
204
  rdoc_options: []
204
205
  require_paths:
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 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 2019 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 2019 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