opentelemetry-api 0.3.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -2
  3. data/CHANGELOG.md +19 -0
  4. data/LICENSE +1 -1
  5. data/{OVERVIEW.md → README.md} +0 -0
  6. data/lib/opentelemetry.rb +11 -11
  7. data/lib/opentelemetry/baggage.rb +16 -0
  8. data/lib/opentelemetry/{correlation_context → baggage}/builder.rb +2 -2
  9. data/lib/opentelemetry/{correlation_context → baggage}/manager.rb +8 -3
  10. data/lib/opentelemetry/baggage/propagation.rb +57 -0
  11. data/lib/opentelemetry/baggage/propagation/context_keys.rb +27 -0
  12. data/lib/opentelemetry/{correlation_context/propagation/text_extractor.rb → baggage/propagation/text_map_extractor.rb} +14 -14
  13. data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +55 -0
  14. data/lib/opentelemetry/context/propagation/composite_propagator.rb +8 -12
  15. data/lib/opentelemetry/instrumentation.rb +2 -2
  16. data/lib/opentelemetry/instrumentation/{adapter.rb → base.rb} +54 -53
  17. data/lib/opentelemetry/instrumentation/registry.rb +32 -32
  18. data/lib/opentelemetry/trace.rb +13 -16
  19. data/lib/opentelemetry/trace/propagation/trace_context.rb +11 -11
  20. data/lib/opentelemetry/trace/propagation/trace_context/{text_extractor.rb → text_map_extractor.rb} +5 -4
  21. data/lib/opentelemetry/trace/propagation/trace_context/{text_injector.rb → text_map_injector.rb} +4 -5
  22. data/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +9 -5
  23. data/lib/opentelemetry/trace/span.rb +10 -18
  24. data/lib/opentelemetry/trace/span_context.rb +25 -1
  25. data/lib/opentelemetry/trace/status.rb +7 -65
  26. data/lib/opentelemetry/trace/tracer.rb +20 -28
  27. data/lib/opentelemetry/trace/util/http_to_status.rb +4 -23
  28. data/lib/opentelemetry/version.rb +1 -1
  29. metadata +15 -17
  30. data/lib/opentelemetry/correlation_context.rb +0 -16
  31. data/lib/opentelemetry/correlation_context/propagation.rb +0 -57
  32. data/lib/opentelemetry/correlation_context/propagation/context_keys.rb +0 -27
  33. data/lib/opentelemetry/correlation_context/propagation/text_injector.rb +0 -55
  34. data/lib/opentelemetry/internal.rb +0 -22
  35. data/lib/opentelemetry/trace/event.rb +0 -46
@@ -8,33 +8,26 @@ module OpenTelemetry
8
8
  module Trace
9
9
  # No-op implementation of Tracer.
10
10
  class Tracer
11
- EXTRACTED_SPAN_CONTEXT_KEY = Propagation::ContextKeys.extracted_span_context_key
12
11
  CURRENT_SPAN_KEY = Propagation::ContextKeys.current_span_key
13
12
 
14
- private_constant :EXTRACTED_SPAN_CONTEXT_KEY, :CURRENT_SPAN_KEY
13
+ private_constant :CURRENT_SPAN_KEY
15
14
 
16
15
  # Returns the current span from the current or provided context
17
16
  #
18
17
  # @param [optional Context] context The context to lookup the current
19
18
  # {Span} from. Defaults to Context.current
20
- def current_span(context = Context.current)
19
+ def current_span(context = nil)
20
+ context ||= Context.current
21
21
  context.value(CURRENT_SPAN_KEY) || Span::INVALID
22
22
  end
23
23
 
24
- # Returns the the active span context from the given {Context}, or current
25
- # if one is not explicitly passed in. The active span context may refer to
26
- # a {SpanContext} that has been extracted. If both a current {Span} and an
27
- # extracted, {SpanContext} exist, the context of the current {Span} will be
28
- # returned.
29
- #
30
- # @param [optional Context] context The context to lookup the active
31
- # {SpanContext} from.
24
+ # Returns a context containing the span, derived from the optional parent
25
+ # context, or the current context if one was not provided.
32
26
  #
33
- def active_span_context(context = nil)
34
- context ||= Context.current
35
- context.value(CURRENT_SPAN_KEY)&.context ||
36
- context.value(EXTRACTED_SPAN_CONTEXT_KEY) ||
37
- SpanContext::INVALID
27
+ # @param [optional Context] context The context to use as the parent for
28
+ # the returned context
29
+ def context_with_span(span, parent_context: Context.current)
30
+ parent_context.set_value(CURRENT_SPAN_KEY, span)
38
31
  end
39
32
 
40
33
  # This is a helper for the default use-case of extending the current trace with a span.
@@ -52,16 +45,17 @@ module OpenTelemetry
52
45
  # span and reraised.
53
46
  # @yield [span, context] yields the newly created span and a context containing the
54
47
  # span to the block.
55
- def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, with_parent: nil, with_parent_context: nil)
56
- span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent, with_parent_context: with_parent_context)
48
+ def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, with_parent: nil)
49
+ span = nil
50
+ span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind, with_parent: with_parent)
57
51
  with_span(span) { |s, c| yield s, c }
58
52
  rescue Exception => e # rubocop:disable Lint/RescueException
59
- span.record_error(e)
60
- span.status = Status.new(Status::UNKNOWN_ERROR,
61
- description: "Unhandled exception of type: #{e.class}")
53
+ span&.record_exception(e)
54
+ span&.status = Status.new(Status::ERROR,
55
+ description: "Unhandled exception of type: #{e.class}")
62
56
  raise e
63
57
  ensure
64
- span.finish
58
+ span&.finish
65
59
  end
66
60
 
67
61
  # Activates/deactivates the Span within the current Context, which makes the "current span"
@@ -84,14 +78,12 @@ module OpenTelemetry
84
78
  #
85
79
  # Parent context can be either passed explicitly, or inferred from currently activated span.
86
80
  #
87
- # @param [optional Span] with_parent Explicitly managed parent Span, overrides
88
- # +with_parent_context+.
89
- # @param [optional Context] with_parent_context Explicitly managed. Overridden by
90
- # +with_parent+.
81
+ # @param [optional Context] with_parent Explicitly managed parent context
91
82
  #
92
83
  # @return [Span]
93
- def start_span(name, with_parent: nil, with_parent_context: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
94
- span_context = with_parent&.context || active_span_context(with_parent_context)
84
+ def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
85
+ span_context = current_span(with_parent).context
86
+
95
87
  if span_context.valid?
96
88
  Span.new(span_context: span_context)
97
89
  else
@@ -9,36 +9,17 @@ module OpenTelemetry
9
9
  module Util
10
10
  # Convenience methods, not necessarily required by the API specification.
11
11
  module HttpToStatus
12
- # Implemented according to
13
- # https://github.com/open-telemetry/opentelemetry-specification/issues/306
14
- # https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-http.md#status
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.
15
14
  #
16
15
  # @param code Numeric HTTP status
17
16
  # @return Status
18
- def http_to_status(code) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
17
+ def http_to_status(code)
19
18
  case code.to_i
20
19
  when 100..399
21
20
  new(const_get(:OK))
22
- when 401
23
- new(const_get(:UNAUTHENTICATED))
24
- when 403
25
- new(const_get(:PERMISSION_DENIED))
26
- when 404
27
- new(const_get(:NOT_FOUND))
28
- when 429
29
- new(const_get(:RESOURCE_EXHAUSTED))
30
- when 400..499
31
- new(const_get(:INVALID_ARGUMENT))
32
- when 501
33
- new(const_get(:UNIMPLEMENTED))
34
- when 503
35
- new(const_get(:UNAVAILABLE))
36
- when 504
37
- new(const_get(:DEADLINE_EXCEEDED))
38
- when 500..599
39
- new(const_get(:INTERNAL_ERROR))
40
21
  else
41
- new(const_get(:UNKNOWN_ERROR))
22
+ new(const_get(:ERROR))
42
23
  end
43
24
  end
44
25
  end
@@ -6,5 +6,5 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  ## Current OpenTelemetry version
9
- VERSION = '0.3.0'
9
+ VERSION = '0.7.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.3.0
4
+ version: 0.7.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-04-03 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ipsa
@@ -146,9 +146,16 @@ files:
146
146
  - ".yardopts"
147
147
  - CHANGELOG.md
148
148
  - LICENSE
149
- - OVERVIEW.md
149
+ - README.md
150
150
  - lib/opentelemetry-api.rb
151
151
  - lib/opentelemetry.rb
152
+ - lib/opentelemetry/baggage.rb
153
+ - lib/opentelemetry/baggage/builder.rb
154
+ - lib/opentelemetry/baggage/manager.rb
155
+ - lib/opentelemetry/baggage/propagation.rb
156
+ - lib/opentelemetry/baggage/propagation/context_keys.rb
157
+ - lib/opentelemetry/baggage/propagation/text_map_extractor.rb
158
+ - lib/opentelemetry/baggage/propagation/text_map_injector.rb
152
159
  - lib/opentelemetry/context.rb
153
160
  - lib/opentelemetry/context/key.rb
154
161
  - lib/opentelemetry/context/propagation.rb
@@ -159,31 +166,22 @@ files:
159
166
  - lib/opentelemetry/context/propagation/noop_injector.rb
160
167
  - lib/opentelemetry/context/propagation/propagation.rb
161
168
  - lib/opentelemetry/context/propagation/propagator.rb
162
- - lib/opentelemetry/correlation_context.rb
163
- - lib/opentelemetry/correlation_context/builder.rb
164
- - lib/opentelemetry/correlation_context/manager.rb
165
- - lib/opentelemetry/correlation_context/propagation.rb
166
- - lib/opentelemetry/correlation_context/propagation/context_keys.rb
167
- - lib/opentelemetry/correlation_context/propagation/text_extractor.rb
168
- - lib/opentelemetry/correlation_context/propagation/text_injector.rb
169
169
  - lib/opentelemetry/error.rb
170
170
  - lib/opentelemetry/instrumentation.rb
171
- - lib/opentelemetry/instrumentation/adapter.rb
171
+ - lib/opentelemetry/instrumentation/base.rb
172
172
  - lib/opentelemetry/instrumentation/registry.rb
173
- - lib/opentelemetry/internal.rb
174
173
  - lib/opentelemetry/metrics.rb
175
174
  - lib/opentelemetry/metrics/handles.rb
176
175
  - lib/opentelemetry/metrics/instruments.rb
177
176
  - lib/opentelemetry/metrics/meter.rb
178
177
  - lib/opentelemetry/metrics/meter_provider.rb
179
178
  - lib/opentelemetry/trace.rb
180
- - lib/opentelemetry/trace/event.rb
181
179
  - lib/opentelemetry/trace/link.rb
182
180
  - lib/opentelemetry/trace/propagation.rb
183
181
  - lib/opentelemetry/trace/propagation/context_keys.rb
184
182
  - lib/opentelemetry/trace/propagation/trace_context.rb
185
- - lib/opentelemetry/trace/propagation/trace_context/text_extractor.rb
186
- - lib/opentelemetry/trace/propagation/trace_context/text_injector.rb
183
+ - lib/opentelemetry/trace/propagation/trace_context/text_map_extractor.rb
184
+ - lib/opentelemetry/trace/propagation/trace_context/text_map_injector.rb
187
185
  - lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb
188
186
  - lib/opentelemetry/trace/span.rb
189
187
  - lib/opentelemetry/trace/span_context.rb
@@ -206,14 +204,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
204
  requirements:
207
205
  - - ">="
208
206
  - !ruby/object:Gem::Version
209
- version: 2.4.0
207
+ version: 2.5.0
210
208
  required_rubygems_version: !ruby/object:Gem::Requirement
211
209
  requirements:
212
210
  - - ">="
213
211
  - !ruby/object:Gem::Version
214
212
  version: '0'
215
213
  requirements: []
216
- rubygems_version: 3.0.3
214
+ rubygems_version: 3.1.4
217
215
  signing_key:
218
216
  specification_version: 4
219
217
  summary: A stats collection and distributed tracing framework
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'opentelemetry/correlation_context/builder'
8
- require 'opentelemetry/correlation_context/manager'
9
- require 'opentelemetry/correlation_context/propagation'
10
-
11
- module OpenTelemetry
12
- # The CorrelationContext module provides functionality to record and propagate
13
- # correlations in a distributed trace
14
- module CorrelationContext
15
- end
16
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'opentelemetry/correlation_context/propagation/context_keys'
8
- require 'opentelemetry/correlation_context/propagation/text_injector'
9
- require 'opentelemetry/correlation_context/propagation/text_extractor'
10
-
11
- module OpenTelemetry
12
- module CorrelationContext
13
- # The Correlation::Propagation module contains injectors and
14
- # extractors for sending and receiving correlation context over the wire
15
- module Propagation
16
- extend self
17
-
18
- TEXT_EXTRACTOR = TextExtractor.new
19
- TEXT_INJECTOR = TextInjector.new
20
- RACK_EXTRACTOR = TextExtractor.new(
21
- correlation_context_key: 'HTTP_CORRELATION_CONTEXT'
22
- )
23
- RACK_INJECTOR = TextInjector.new(
24
- correlation_context_key: 'HTTP_CORRELATION_CONTEXT'
25
- )
26
-
27
- private_constant :TEXT_INJECTOR, :TEXT_EXTRACTOR, :RACK_INJECTOR,
28
- :RACK_EXTRACTOR
29
-
30
- # Returns an extractor that extracts context using the W3C Correlation
31
- # Context format
32
- def text_injector
33
- TEXT_INJECTOR
34
- end
35
-
36
- # Returns an injector that injects context using the W3C Correlation
37
- # Context format
38
- def text_extractor
39
- TEXT_EXTRACTOR
40
- end
41
-
42
- # Returns an extractor that extracts context using the W3C Correlation
43
- # Context 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 Correlation
50
- # Context format with Rack normalized keys (upcased and prefixed with
51
- # HTTP_)
52
- def rack_extractor
53
- RACK_EXTRACTOR
54
- end
55
- end
56
- end
57
- 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
- module CorrelationContext
9
- module Propagation
10
- # The ContextKeys module contains the keys used to index correlations
11
- # in a {Context} instance
12
- module ContextKeys
13
- extend self
14
-
15
- CORRELATION_CONTEXT_KEY = Context.create_key('correlation-context')
16
- private_constant :CORRELATION_CONTEXT_KEY
17
-
18
- # Returns the context key that correlations are indexed by
19
- #
20
- # @return [Context::Key]
21
- def correlation_context_key
22
- CORRELATION_CONTEXT_KEY
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'cgi'
8
-
9
- module OpenTelemetry
10
- module CorrelationContext
11
- module Propagation
12
- # Injects correlation context using the W3C Correlation Context format
13
- class TextInjector
14
- include Context::Propagation::DefaultSetter
15
-
16
- # Returns a new TextInjector that injects context using the specified
17
- # header key
18
- #
19
- # @param [String] correlation_context_header_key The correlation context header
20
- # key used in the carrier
21
- # @return [TextInjector]
22
- def initialize(correlation_context_key: 'Correlation-Context')
23
- @correlation_context_key = correlation_context_key
24
- end
25
-
26
- # Inject in-process correlations into the supplied carrier.
27
- #
28
- # @param [Carrier] carrier The carrier to inject correlations into
29
- # @param [Context] context The context to read correlations from
30
- # @param [optional Callable] getter An optional callable that takes a carrier and a key and
31
- # returns the value associated with the key. If omitted the default getter will be used
32
- # which expects the carrier to respond to [] and []=.
33
- # @yield [Carrier, String] if an optional getter is provided, inject will yield the carrier
34
- # and the header key to the getter.
35
- # @return [Object] carrier with injected correlations
36
- def inject(carrier, context, &setter)
37
- return carrier unless (correlations = context[ContextKeys.correlation_context_key]) && !correlations.empty?
38
-
39
- setter ||= default_setter
40
- setter.call(carrier, @correlation_context_key, encode(correlations))
41
-
42
- carrier
43
- end
44
-
45
- private
46
-
47
- def encode(correlations)
48
- correlations.inject(+'') do |memo, (k, v)|
49
- memo << CGI.escape(k.to_s) << '=' << CGI.escape(v.to_s) << ','
50
- end.chop!
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,22 +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
- # @api private
9
- #
10
- # Internal contains helpers used by the no-op API implementation.
11
- module Internal
12
- extend self
13
-
14
- def printable_ascii?(string)
15
- return false unless string.is_a?(String)
16
-
17
- r = 32..126
18
- string.each_codepoint { |c| return false unless r.include?(c) }
19
- true
20
- end
21
- end
22
- end
@@ -1,46 +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
- module Trace
9
- # A text annotation with a set of attributes and a timestamp.
10
- class Event
11
- EMPTY_ATTRIBUTES = {}.freeze
12
-
13
- private_constant :EMPTY_ATTRIBUTES
14
-
15
- # Returns the name of this event
16
- #
17
- # @return [String]
18
- attr_reader :name
19
-
20
- # Returns the frozen attributes for this event
21
- #
22
- # @return [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
23
- attr_reader :attributes
24
-
25
- # Returns the timestamp for this event
26
- #
27
- # @return [Time]
28
- attr_reader :timestamp
29
-
30
- # Returns a new immutable {Event}.
31
- #
32
- # @param [String] name The name of this event
33
- # @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
34
- # attributes A hash of attributes for this event. Attributes will be
35
- # frozen during Event initialization.
36
- # @param [optional Time] timestamp The timestamp for this event.
37
- # Defaults to Time.now.
38
- # @return [Event]
39
- def initialize(name:, attributes: nil, timestamp: nil)
40
- @name = name
41
- @attributes = attributes.freeze || EMPTY_ATTRIBUTES
42
- @timestamp = timestamp || Time.now
43
- end
44
- end
45
- end
46
- end