opentelemetry-api 0.5.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -2
  3. data/CHANGELOG.md +38 -0
  4. data/{OVERVIEW.md → README.md} +0 -0
  5. data/lib/opentelemetry.rb +10 -10
  6. data/lib/opentelemetry/baggage.rb +16 -0
  7. data/lib/opentelemetry/{correlation_context → baggage}/builder.rb +2 -2
  8. data/lib/opentelemetry/{correlation_context → baggage}/manager.rb +8 -3
  9. data/lib/opentelemetry/baggage/propagation.rb +57 -0
  10. data/lib/opentelemetry/baggage/propagation/context_keys.rb +27 -0
  11. data/lib/opentelemetry/{correlation_context/propagation/text_extractor.rb → baggage/propagation/text_map_extractor.rb} +14 -14
  12. data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +55 -0
  13. data/lib/opentelemetry/trace.rb +38 -4
  14. data/lib/opentelemetry/trace/link.rb +3 -3
  15. data/lib/opentelemetry/trace/propagation.rb +0 -1
  16. data/lib/opentelemetry/trace/propagation/trace_context.rb +11 -11
  17. data/lib/opentelemetry/trace/propagation/trace_context/{text_extractor.rb → text_map_extractor.rb} +5 -4
  18. data/lib/opentelemetry/trace/propagation/trace_context/{text_injector.rb → text_map_injector.rb} +5 -6
  19. data/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +4 -4
  20. data/lib/opentelemetry/trace/span.rb +10 -18
  21. data/lib/opentelemetry/trace/span_context.rb +25 -1
  22. data/lib/opentelemetry/trace/status.rb +13 -71
  23. data/lib/opentelemetry/trace/tracer.rb +13 -54
  24. data/lib/opentelemetry/trace/util/http_to_status.rb +4 -23
  25. data/lib/opentelemetry/version.rb +1 -1
  26. metadata +18 -17
  27. data/lib/opentelemetry/correlation_context.rb +0 -16
  28. data/lib/opentelemetry/correlation_context/propagation.rb +0 -57
  29. data/lib/opentelemetry/correlation_context/propagation/context_keys.rb +0 -27
  30. data/lib/opentelemetry/correlation_context/propagation/text_injector.rb +0 -55
  31. data/lib/opentelemetry/internal.rb +0 -22
  32. data/lib/opentelemetry/trace/event.rb +0 -46
  33. data/lib/opentelemetry/trace/propagation/context_keys.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6851022b08b4488e128a4bc73ef53b1463c8bd04763aba1ecd7279aaf32e65ae
4
- data.tar.gz: fa593580948f328f9445849846e0856ff496f63513c6352e5000cc27f6695faa
3
+ metadata.gz: 2cee7fab7654059566d26d776b3813fbf526152804e861788d4c432c1167eb51
4
+ data.tar.gz: e1fb0ea50cf900e5caa840ddbc7031e083d4ac91250befab42036e7be93ab83d
5
5
  SHA512:
6
- metadata.gz: 280ab63486d494ab2e338cba6d9d8c60ff8dd9c7bf79f70ab83606caa7dd16eb9e10708d6205e6725fed1e519b07e26faf1e267d59d0579cd4b673e97fdfc7cb
7
- data.tar.gz: 756dc2722afe75c45c3aef8c06a1885e77a6f132d7cf4772488df40a5205b6ee182d9cd9e683951c49e9f18b81d12176adc1286e12fbe8dd1c732335df6e2d20
6
+ metadata.gz: b0bdfb487a5d1031c9f5981ace74e9535e4bd871059ab7f43070e451c4ef598361dde7c15644a31ba9b4f829f578fdb520568f484250f57ce31e686f0005834d
7
+ data.tar.gz: 3c247ff76a50b9ba58ac6ce3b2f534a86c2792181323c43c5407bc4f13afa17273651eee5eebe808d419b266f7fc94d3cf29a39e05d3b387dd7fbed96819126e
data/.yardopts CHANGED
@@ -1,9 +1,9 @@
1
1
  --no-private
2
2
  --title=OpenTelemetry API
3
3
  --markup=markdown
4
- --main=OVERVIEW.md
4
+ --main=README.md
5
5
  ./lib/opentelemetry/**/*.rb
6
6
  ./lib/opentelemetry.rb
7
7
  -
8
- OVERVIEW.md
8
+ README.md
9
9
  CHANGELOG.md
@@ -1 +1,39 @@
1
1
  # Release History: opentelemetry-api
2
+
3
+ ### v0.10.0 / 2020-12-03
4
+
5
+ * (No significant changes)
6
+
7
+ ### v0.9.0 / 2020-11-27
8
+
9
+ * (No significant changes)
10
+
11
+ ### v0.8.0 / 2020-10-27
12
+
13
+ * BREAKING CHANGE: Move context/span methods to Trace module
14
+ * BREAKING CHANGE: Remove 'canonical' from status codes
15
+ * BREAKING CHANGE: Assorted SpanContext fixes
16
+
17
+ * ADDED: B3 support
18
+ * FIXED: Move context/span methods to Trace module
19
+ * FIXED: Remove 'canonical' from status codes
20
+ * FIXED: Assorted SpanContext fixes
21
+
22
+ ### v0.7.0 / 2020-10-07
23
+
24
+ * FIXED: Safely navigate span variable during error cases
25
+ * DOCS: Standardize toplevel docs structure and readme
26
+ * DOCS: Fix param description in TextMapInjector for Baggage
27
+
28
+ ### v0.6.0 / 2020-09-10
29
+
30
+ * ADDED: Add support for OTEL_LOG_LEVEL env var
31
+ * Documented array valued attributes [#343](https://github.com/open-telemetry/opentelemetry-ruby/pull/343)
32
+ * Renamed CorrelationContext to Baggage [#338](https://github.com/open-telemetry/opentelemetry-ruby/pull/338)
33
+ * Renamed Text* to TextMap* (propagators) [#335](https://github.com/open-telemetry/opentelemetry-ruby/pull/335)
34
+ * Fixed exception semantic conventions (`span.record_error` -> `span.record_exception`) [#333](https://github.com/open-telemetry/opentelemetry-ruby/pull/333)
35
+ * Removed support for lazy event creation [#329](https://github.com/open-telemetry/opentelemetry-ruby/pull/329)
36
+ * `name:` named parameter to `span.add_event` becomes first positional argument
37
+ * `Event` class removed from API
38
+ * Added `hex_trace_id` and `hex_span_id` helpers to `SpanContext` [#332](https://github.com/open-telemetry/opentelemetry-ruby/pull/332)
39
+ * Added `CorrelationContext::Manager.values` method to return correlations as a `Hash` [#323](https://github.com/open-telemetry/opentelemetry-ruby/pull/323)
File without changes
@@ -8,8 +8,7 @@ require 'logger'
8
8
 
9
9
  require 'opentelemetry/error'
10
10
  require 'opentelemetry/context'
11
- require 'opentelemetry/correlation_context'
12
- require 'opentelemetry/internal'
11
+ require 'opentelemetry/baggage'
13
12
  require_relative './opentelemetry/instrumentation'
14
13
  require 'opentelemetry/metrics'
15
14
  require 'opentelemetry/trace'
@@ -23,9 +22,12 @@ require 'opentelemetry/version'
23
22
  module OpenTelemetry
24
23
  extend self
25
24
 
26
- attr_writer :tracer_provider, :meter_provider, :correlations
25
+ attr_writer :tracer_provider, :meter_provider, :baggage, :logger
27
26
 
28
- attr_accessor :logger
27
+ # @return [Object, Logger] configured Logger or a default STDOUT Logger.
28
+ def logger
29
+ @logger ||= Logger.new(STDOUT, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
30
+ end
29
31
 
30
32
  # @return [Object, Trace::TracerProvider] registered tracer provider or a
31
33
  # default no-op implementation of the tracer provider.
@@ -45,17 +47,15 @@ module OpenTelemetry
45
47
  @instrumentation_registry ||= Instrumentation::Registry.new
46
48
  end
47
49
 
48
- # @return [Object, CorrelationContext::Manager] registered
49
- # correlation context manager or a default no-op implementation of the
50
+ # @return [Object, Baggage::Manager] registered
51
+ # baggage manager or a default no-op implementation of the
50
52
  # manager.
51
- def correlations
52
- @correlations ||= CorrelationContext::Manager.new
53
+ def baggage
54
+ @baggage ||= Baggage::Manager.new
53
55
  end
54
56
 
55
57
  # @return [Context::Propagation::Propagation] an instance of the propagation API
56
58
  def propagation
57
59
  @propagation ||= Context::Propagation::Propagation.new
58
60
  end
59
-
60
- self.logger = Logger.new(STDOUT)
61
61
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ require 'opentelemetry/baggage/builder'
8
+ require 'opentelemetry/baggage/manager'
9
+ require 'opentelemetry/baggage/propagation'
10
+
11
+ module OpenTelemetry
12
+ # The Baggage module provides functionality to record and propagate
13
+ # baggage in a distributed trace
14
+ module Baggage
15
+ end
16
+ end
@@ -5,8 +5,8 @@
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  module OpenTelemetry
8
- module CorrelationContext
9
- # No op implementation of CorrelationContext::Builder
8
+ module Baggage
9
+ # No op implementation of Baggage::Builder
10
10
  class Builder
11
11
  def set_value(key, value); end
12
12
 
@@ -5,11 +5,12 @@
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  module OpenTelemetry
8
- module CorrelationContext
9
- # No op implementation of CorrelationContext::Manager
8
+ module Baggage
9
+ # No op implementation of Baggage::Manager
10
10
  class Manager
11
11
  NOOP_BUILDER = Builder.new
12
- private_constant :NOOP_BUILDER
12
+ EMPTY_VALUES = {}.freeze
13
+ private_constant(:NOOP_BUILDER, :EMPTY_VALUES)
13
14
 
14
15
  def build(context: Context.current)
15
16
  yield NOOP_BUILDER
@@ -24,6 +25,10 @@ module OpenTelemetry
24
25
  nil
25
26
  end
26
27
 
28
+ def values(context: Context.current)
29
+ EMPTY_VALUES
30
+ end
31
+
27
32
  def remove_value(key, context: Context.current)
28
33
  context
29
34
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2019 OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ require 'opentelemetry/baggage/propagation/context_keys'
8
+ require 'opentelemetry/baggage/propagation/text_map_injector'
9
+ require 'opentelemetry/baggage/propagation/text_map_extractor'
10
+
11
+ module OpenTelemetry
12
+ module Baggage
13
+ # The Baggage::Propagation module contains injectors and
14
+ # extractors for sending and receiving baggage over the wire
15
+ module Propagation
16
+ extend self
17
+
18
+ TEXT_MAP_EXTRACTOR = TextMapExtractor.new
19
+ TEXT_MAP_INJECTOR = TextMapInjector.new
20
+ RACK_EXTRACTOR = TextMapExtractor.new(
21
+ baggage_key: 'HTTP_BAGGAGE'
22
+ )
23
+ RACK_INJECTOR = TextMapInjector.new(
24
+ baggage_key: 'HTTP_BAGGAGE'
25
+ )
26
+
27
+ private_constant :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR, :RACK_INJECTOR,
28
+ :RACK_EXTRACTOR
29
+
30
+ # Returns an extractor that extracts context using the W3C Baggage
31
+ # format
32
+ def text_map_injector
33
+ TEXT_MAP_INJECTOR
34
+ end
35
+
36
+ # Returns an injector that injects context using the W3C Baggage
37
+ # format
38
+ def text_map_extractor
39
+ TEXT_MAP_EXTRACTOR
40
+ end
41
+
42
+ # Returns an extractor that extracts context using the W3C Baggage
43
+ # format with Rack normalized keys (upcased and prefixed with
44
+ # HTTP_)
45
+ def rack_injector
46
+ RACK_INJECTOR
47
+ end
48
+
49
+ # Returns an injector that injects context using the W3C Baggage
50
+ # format with Rack normalized keys (upcased and prefixed with
51
+ # HTTP_)
52
+ def rack_extractor
53
+ RACK_EXTRACTOR
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,27 @@
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 Baggage
9
+ module Propagation
10
+ # The ContextKeys module contains the keys used to index baggage
11
+ # in a {Context} instance
12
+ module ContextKeys
13
+ extend self
14
+
15
+ BAGGAGE_KEY = Context.create_key('baggage')
16
+ private_constant :BAGGAGE_KEY
17
+
18
+ # Returns the context key that baggage are indexed by
19
+ #
20
+ # @return [Context::Key]
21
+ def baggage_key
22
+ BAGGAGE_KEY
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -7,41 +7,41 @@
7
7
  require 'cgi'
8
8
 
9
9
  module OpenTelemetry
10
- module CorrelationContext
10
+ module Baggage
11
11
  module Propagation
12
- # Extracts correlations from carriers in the W3C Correlation Context format
13
- class TextExtractor
12
+ # Extracts baggage from carriers in the W3C Baggage format
13
+ class TextMapExtractor
14
14
  include Context::Propagation::DefaultGetter
15
15
 
16
- # Returns a new TextExtractor that extracts context using the specified
16
+ # Returns a new TextMapExtractor that extracts context using the specified
17
17
  # header key
18
18
  #
19
- # @param [String] correlation_context_key The correlation context header
19
+ # @param [String] baggage_key The baggage header
20
20
  # key used in the carrier
21
- # @return [TextExtractor]
22
- def initialize(correlation_context_key: 'otcorrelations')
23
- @correlation_context_key = correlation_context_key
21
+ # @return [TextMapExtractor]
22
+ def initialize(baggage_key: 'baggage')
23
+ @baggage_key = baggage_key
24
24
  end
25
25
 
26
- # Extract remote correlations from the supplied carrier.
26
+ # Extract remote baggage from the supplied carrier.
27
27
  # If extraction fails, the original context will be returned
28
28
  #
29
29
  # @param [Carrier] carrier The carrier to get the header from
30
- # @param [Context] context The context to be updated with extracted correlations
30
+ # @param [Context] context The context to be updated with extracted baggage
31
31
  # @param [optional Callable] getter An optional callable that takes a carrier and a key and
32
32
  # returns the value associated with the key. If omitted the default getter will be used
33
33
  # which expects the carrier to respond to [] and []=.
34
34
  # @yield [Carrier, String] if an optional getter is provided, extract will yield the carrier
35
35
  # and the header key to the getter.
36
- # @return [Context] context updated with extracted correlations, or the original context
36
+ # @return [Context] context updated with extracted baggage, or the original context
37
37
  # if extraction fails
38
38
  def extract(carrier, context, &getter)
39
39
  getter ||= default_getter
40
- header = getter.call(carrier, @correlation_context_key)
40
+ header = getter.call(carrier, @baggage_key)
41
41
 
42
42
  entries = header.gsub(/\s/, '').split(',')
43
43
 
44
- correlations = entries.each_with_object({}) do |entry, memo|
44
+ baggage = entries.each_with_object({}) do |entry, memo|
45
45
  # The ignored variable below holds properties as per the W3C spec.
46
46
  # OTel is not using them currently, but they might be used for
47
47
  # metadata in the future
@@ -50,7 +50,7 @@ module OpenTelemetry
50
50
  memo[k] = v
51
51
  end
52
52
 
53
- context.set_value(ContextKeys.correlation_context_key, correlations)
53
+ context.set_value(ContextKeys.baggage_key, baggage)
54
54
  rescue StandardError
55
55
  context
56
56
  end
@@ -0,0 +1,55 @@
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 Baggage
11
+ module Propagation
12
+ # Injects baggage using the W3C Baggage format
13
+ class TextMapInjector
14
+ include Context::Propagation::DefaultSetter
15
+
16
+ # Returns a new TextMapInjector that injects context using the specified
17
+ # header key
18
+ #
19
+ # @param [String] baggage_key The baggage header
20
+ # key used in the carrier
21
+ # @return [TextMapInjector]
22
+ def initialize(baggage_key: 'baggage')
23
+ @baggage_key = baggage_key
24
+ end
25
+
26
+ # Inject in-process baggage into the supplied carrier.
27
+ #
28
+ # @param [Carrier] carrier The carrier to inject baggage into
29
+ # @param [Context] context The context to read baggage 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 baggage
36
+ def inject(carrier, context, &setter)
37
+ return carrier unless (baggage = context[ContextKeys.baggage_key]) && !baggage.empty?
38
+
39
+ setter ||= default_setter
40
+ setter.call(carrier, @baggage_key, encode(baggage))
41
+
42
+ carrier
43
+ end
44
+
45
+ private
46
+
47
+ def encode(baggage)
48
+ baggage.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
@@ -9,6 +9,12 @@ module OpenTelemetry
9
9
  # single logical operation, consolidated across various components of an
10
10
  # application.
11
11
  module Trace
12
+ extend self
13
+
14
+ CURRENT_SPAN_KEY = Context.create_key('current-span')
15
+
16
+ private_constant :CURRENT_SPAN_KEY
17
+
12
18
  # An invalid trace identifier, a 16-byte string with all zero bytes.
13
19
  INVALID_TRACE_ID = ("\0" * 16).b
14
20
 
@@ -19,7 +25,7 @@ module OpenTelemetry
19
25
  # non-zero byte.
20
26
  #
21
27
  # @return [String] a valid trace ID.
22
- def self.generate_trace_id
28
+ def generate_trace_id
23
29
  loop do
24
30
  id = Random::DEFAULT.bytes(16)
25
31
  return id unless id == INVALID_TRACE_ID
@@ -30,22 +36,50 @@ module OpenTelemetry
30
36
  # non-zero byte.
31
37
  #
32
38
  # @return [String] a valid span ID.
33
- def self.generate_span_id
39
+ def generate_span_id
34
40
  loop do
35
41
  id = Random::DEFAULT.bytes(8)
36
42
  return id unless id == INVALID_SPAN_ID
37
43
  end
38
44
  end
45
+
46
+ # Returns the current span from the current or provided context
47
+ #
48
+ # @param [optional Context] context The context to lookup the current
49
+ # {Span} from. Defaults to Context.current
50
+ def current_span(context = nil)
51
+ context ||= Context.current
52
+ context.value(CURRENT_SPAN_KEY) || Span::INVALID
53
+ end
54
+
55
+ # Returns a context containing the span, derived from the optional parent
56
+ # context, or the current context if one was not provided.
57
+ #
58
+ # @param [optional Context] context The context to use as the parent for
59
+ # the returned context
60
+ def context_with_span(span, parent_context: Context.current)
61
+ parent_context.set_value(CURRENT_SPAN_KEY, span)
62
+ end
63
+
64
+ # Activates/deactivates the Span within the current Context, which makes the "current span"
65
+ # available implicitly.
66
+ #
67
+ # On exit, the Span that was active before calling this method will be reactivated.
68
+ #
69
+ # @param [Span] span the span to activate
70
+ # @yield [span, context] yields span and a context containing the span to the block.
71
+ def with_span(span)
72
+ Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
73
+ end
39
74
  end
40
75
  end
41
76
 
42
- require 'opentelemetry/trace/event'
43
77
  require 'opentelemetry/trace/link'
44
- require 'opentelemetry/trace/propagation'
45
78
  require 'opentelemetry/trace/trace_flags'
46
79
  require 'opentelemetry/trace/span_context'
47
80
  require 'opentelemetry/trace/span_kind'
48
81
  require 'opentelemetry/trace/span'
49
82
  require 'opentelemetry/trace/status'
83
+ require 'opentelemetry/trace/propagation'
50
84
  require 'opentelemetry/trace/tracer'
51
85
  require 'opentelemetry/trace/tracer_provider'