opentelemetry-api 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/lib/opentelemetry.rb +10 -10
  4. data/lib/opentelemetry/baggage.rb +16 -0
  5. data/lib/opentelemetry/{correlation_context → baggage}/builder.rb +2 -2
  6. data/lib/opentelemetry/{correlation_context → baggage}/manager.rb +8 -3
  7. data/lib/opentelemetry/baggage/propagation.rb +57 -0
  8. data/lib/opentelemetry/baggage/propagation/context_keys.rb +27 -0
  9. data/lib/opentelemetry/{correlation_context/propagation/text_extractor.rb → baggage/propagation/text_map_extractor.rb} +14 -14
  10. data/lib/opentelemetry/baggage/propagation/text_map_injector.rb +55 -0
  11. data/lib/opentelemetry/trace.rb +1 -2
  12. data/lib/opentelemetry/trace/propagation/trace_context.rb +11 -11
  13. data/lib/opentelemetry/trace/propagation/trace_context/{text_extractor.rb → text_map_extractor.rb} +3 -3
  14. data/lib/opentelemetry/trace/propagation/trace_context/{text_injector.rb → text_map_injector.rb} +3 -3
  15. data/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +2 -2
  16. data/lib/opentelemetry/trace/span.rb +10 -18
  17. data/lib/opentelemetry/trace/span_context.rb +25 -1
  18. data/lib/opentelemetry/trace/tracer.rb +1 -1
  19. data/lib/opentelemetry/version.rb +1 -1
  20. metadata +12 -14
  21. data/lib/opentelemetry/correlation_context.rb +0 -16
  22. data/lib/opentelemetry/correlation_context/propagation.rb +0 -57
  23. data/lib/opentelemetry/correlation_context/propagation/context_keys.rb +0 -27
  24. data/lib/opentelemetry/correlation_context/propagation/text_injector.rb +0 -55
  25. data/lib/opentelemetry/internal.rb +0 -22
  26. data/lib/opentelemetry/trace/event.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6851022b08b4488e128a4bc73ef53b1463c8bd04763aba1ecd7279aaf32e65ae
4
- data.tar.gz: fa593580948f328f9445849846e0856ff496f63513c6352e5000cc27f6695faa
3
+ metadata.gz: 538ed3a78ed2551d82e647c361b94afc77a083a1126093cb26674e324197d0a0
4
+ data.tar.gz: eb5a65a102585407772dcc8b57b375c83198cbddc432c97a71d9fdef97e3171a
5
5
  SHA512:
6
- metadata.gz: 280ab63486d494ab2e338cba6d9d8c60ff8dd9c7bf79f70ab83606caa7dd16eb9e10708d6205e6725fed1e519b07e26faf1e267d59d0579cd4b673e97fdfc7cb
7
- data.tar.gz: 756dc2722afe75c45c3aef8c06a1885e77a6f132d7cf4772488df40a5205b6ee182d9cd9e683951c49e9f18b81d12176adc1286e12fbe8dd1c732335df6e2d20
6
+ metadata.gz: '097a3f2d32207a56ba207cc2918f24e4eee28483117c54ed0412e83e617922980f385bf5c1949a91b232c4fa4a5bfccf5c66947ee65fc4ebc26460a27a33f6b6'
7
+ data.tar.gz: 533897d0cea9a0f731e4d7badf100089fb2bb87e95cbe28060e222aea4137272a4e71f9dd65e12ef8a8558bf3635cc512e663de2d5364fea9a1086cab3a9cef1
@@ -1 +1,14 @@
1
1
  # Release History: opentelemetry-api
2
+
3
+ ### v0.6.0 / 2020-09-10
4
+
5
+ * ADDED: Add support for OTEL_LOG_LEVEL env var
6
+ * Documented array valued attributes [#343](https://github.com/open-telemetry/opentelemetry-ruby/pull/343)
7
+ * Renamed CorrelationContext to Baggage [#338](https://github.com/open-telemetry/opentelemetry-ruby/pull/338)
8
+ * Renamed Text* to TextMap* (propagators) [#335](https://github.com/open-telemetry/opentelemetry-ruby/pull/335)
9
+ * Fixed exception semantic conventions (`span.record_error` -> `span.record_exception`) [#333](https://github.com/open-telemetry/opentelemetry-ruby/pull/333)
10
+ * Removed support for lazy event creation [#329](https://github.com/open-telemetry/opentelemetry-ruby/pull/329)
11
+ * `name:` named parameter to `span.add_event` becomes first positional argument
12
+ * `Event` class removed from API
13
+ * Added `hex_trace_id` and `hex_span_id` helpers to `SpanContext` [#332](https://github.com/open-telemetry/opentelemetry-ruby/pull/332)
14
+ * Added `CorrelationContext::Manager.values` method to return correlations as a `Hash` [#323](https://github.com/open-telemetry/opentelemetry-ruby/pull/323)
@@ -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_header_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
@@ -39,13 +39,12 @@ module OpenTelemetry
39
39
  end
40
40
  end
41
41
 
42
- require 'opentelemetry/trace/event'
43
42
  require 'opentelemetry/trace/link'
44
- require 'opentelemetry/trace/propagation'
45
43
  require 'opentelemetry/trace/trace_flags'
46
44
  require 'opentelemetry/trace/span_context'
47
45
  require 'opentelemetry/trace/span_kind'
48
46
  require 'opentelemetry/trace/span'
49
47
  require 'opentelemetry/trace/status'
48
+ require 'opentelemetry/trace/propagation'
50
49
  require 'opentelemetry/trace/tracer'
51
50
  require 'opentelemetry/trace/tracer_provider'
@@ -5,8 +5,8 @@
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  require 'opentelemetry/trace/propagation/trace_context/trace_parent'
8
- require 'opentelemetry/trace/propagation/trace_context/text_extractor'
9
- require 'opentelemetry/trace/propagation/trace_context/text_injector'
8
+ require 'opentelemetry/trace/propagation/trace_context/text_map_extractor'
9
+ require 'opentelemetry/trace/propagation/trace_context/text_map_injector'
10
10
 
11
11
  module OpenTelemetry
12
12
  module Trace
@@ -16,30 +16,30 @@ module OpenTelemetry
16
16
  module TraceContext
17
17
  extend self
18
18
 
19
- TEXT_EXTRACTOR = TextExtractor.new
20
- TEXT_INJECTOR = TextInjector.new
21
- RACK_EXTRACTOR = TextExtractor.new(
19
+ TEXT_MAP_EXTRACTOR = TextMapExtractor.new
20
+ TEXT_MAP_INJECTOR = TextMapInjector.new
21
+ RACK_EXTRACTOR = TextMapExtractor.new(
22
22
  traceparent_key: 'HTTP_TRACEPARENT',
23
23
  tracestate_key: 'HTTP_TRACESTATE'
24
24
  )
25
- RACK_INJECTOR = TextInjector.new(
25
+ RACK_INJECTOR = TextMapInjector.new(
26
26
  traceparent_key: 'HTTP_TRACEPARENT',
27
27
  tracestate_key: 'HTTP_TRACESTATE'
28
28
  )
29
29
 
30
- private_constant :TEXT_INJECTOR, :TEXT_EXTRACTOR,
30
+ private_constant :TEXT_MAP_INJECTOR, :TEXT_MAP_EXTRACTOR,
31
31
  :RACK_INJECTOR, :RACK_EXTRACTOR
32
32
 
33
33
  # Returns an extractor that extracts context using the W3C Trace Context
34
34
  # format
35
- def text_extractor
36
- TEXT_EXTRACTOR
35
+ def text_map_extractor
36
+ TEXT_MAP_EXTRACTOR
37
37
  end
38
38
 
39
39
  # Returns an injector that injects context using the W3C Trace Context
40
40
  # format
41
- def text_injector
42
- TEXT_INJECTOR
41
+ def text_map_injector
42
+ TEXT_MAP_INJECTOR
43
43
  end
44
44
 
45
45
  # Returns an extractor that extracts context using the W3C Trace Context
@@ -8,15 +8,15 @@ module OpenTelemetry
8
8
  module Propagation
9
9
  module TraceContext
10
10
  # Extracts context from carriers in the W3C Trace Context format
11
- class TextExtractor
11
+ class TextMapExtractor
12
12
  include Context::Propagation::DefaultGetter
13
13
 
14
- # Returns a new TextExtractor that extracts context using the
14
+ # Returns a new TextMapExtractor that extracts context using the
15
15
  # specified header keys
16
16
  #
17
17
  # @param [String] traceparent_key The traceparent header key used in the carrier
18
18
  # @param [String] tracestate_key The tracestate header key used in the carrier
19
- # @return [TextExtractor]
19
+ # @return [TextMapExtractor]
20
20
  def initialize(traceparent_key: 'traceparent',
21
21
  tracestate_key: 'tracestate')
22
22
  @traceparent_key = traceparent_key
@@ -8,15 +8,15 @@ module OpenTelemetry
8
8
  module Propagation
9
9
  module TraceContext
10
10
  # Injects context into carriers using the W3C Trace Context format
11
- class TextInjector
11
+ class TextMapInjector
12
12
  include Context::Propagation::DefaultSetter
13
13
 
14
- # Returns a new TextInjector that injects context using the
14
+ # Returns a new TextMapInjector that injects context using the
15
15
  # specified header keys
16
16
  #
17
17
  # @param [String] traceparent_key The traceparent header key used in the carrier
18
18
  # @param [String] tracestate_key The tracestate header key used in the carrier
19
- # @return [TextInjector]
19
+ # @return [TextMapInjector]
20
20
  def initialize(traceparent_key: 'traceparent',
21
21
  tracestate_key: 'tracestate')
22
22
  @traceparent_key = traceparent_key
@@ -25,8 +25,8 @@ module OpenTelemetry
25
25
  REGEXP = /^(?<version>[A-Fa-f0-9]{2})-(?<trace_id>[A-Fa-f0-9]{32})-(?<span_id>[A-Fa-f0-9]{16})-(?<flags>[A-Fa-f0-9]{2})(?<ignored>-.*)?$/.freeze
26
26
  private_constant :REGEXP
27
27
 
28
- INVALID_TRACE_ID = OpenTelemetry::Trace::INVALID_TRACE_ID.unpack1('H*')
29
- INVALID_SPAN_ID = OpenTelemetry::Trace::INVALID_SPAN_ID.unpack1('H*')
28
+ INVALID_TRACE_ID = OpenTelemetry::Trace::SpanContext::INVALID.hex_trace_id
29
+ INVALID_SPAN_ID = OpenTelemetry::Trace::SpanContext::INVALID.hex_span_id
30
30
  private_constant :INVALID_TRACE_ID, :INVALID_SPAN_ID
31
31
 
32
32
  class << self
@@ -50,7 +50,7 @@ module OpenTelemetry
50
50
  # meanings.
51
51
  #
52
52
  # @param [String] key
53
- # @param [String, Boolean, Numeric] value
53
+ # @param [String, Boolean, Numeric, Array<String, Numeric, Boolean>] value
54
54
  #
55
55
  # @return [self] returns itself
56
56
  def set_attribute(key, value)
@@ -58,44 +58,36 @@ module OpenTelemetry
58
58
  end
59
59
  alias []= set_attribute
60
60
 
61
- # Add an Event to a {Span}. This can be accomplished eagerly or lazily.
62
- # Lazy evaluation is useful when the event attributes are expensive to
63
- # build and where the cost can be avoided for an unsampled {Span}.
61
+ # Add an event to a {Span}.
64
62
  #
65
- # Eager example:
63
+ # Example:
66
64
  #
67
- # span.add_event(name: 'event', attributes: {'eager' => true})
68
- #
69
- # Lazy example:
70
- #
71
- # span.add_event { tracer.create_event(name: 'event', attributes: {'eager' => false}) }
65
+ # span.add_event('event', attributes: {'eager' => true})
72
66
  #
73
67
  # Note that the OpenTelemetry project
74
68
  # {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
75
69
  # documents} certain "standard event names and keys" which have
76
70
  # prescribed semantic meanings.
77
71
  #
78
- # @param [optional String] name Optional name of the event. This is
79
- # required if a block is not given.
72
+ # @param [String] name Name of the event.
80
73
  # @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
81
74
  # attributes One or more key:value pairs, where the keys must be
82
75
  # strings and the values may be (array of) string, boolean or numeric
83
- # type. This argument should only be used when passing in a name.
76
+ # type.
84
77
  # @param [optional Time] timestamp Optional timestamp for the event.
85
- # This argument should only be used when passing in a name.
86
78
  #
87
79
  # @return [self] returns itself
88
- def add_event(name: nil, attributes: nil, timestamp: nil)
80
+ def add_event(name, attributes: nil, timestamp: nil)
89
81
  self
90
82
  end
91
83
 
92
- # Record an error during the execution of this span. Multiple errors
84
+ # Record an exception during the execution of this span. Multiple exceptions
93
85
  # can be recorded on a span.
94
86
  #
95
- # @param [Exception] error The error to recorded
87
+ # @param [Exception] exception The exception to recorded
96
88
  #
97
89
  # @return [void]
98
- def record_error(error); end
90
+ def record_exception(exception); end
99
91
 
100
92
  # Sets the Status to the Span
101
93
  #
@@ -11,7 +11,7 @@ module OpenTelemetry
11
11
  # {TraceFlags}, a system-specific tracestate, and a boolean indicating that the SpanContext was
12
12
  # extracted from the wire.
13
13
  class SpanContext
14
- attr_reader :trace_id, :span_id, :trace_flags, :tracestate
14
+ attr_reader :trace_flags, :tracestate
15
15
 
16
16
  # Returns a new {SpanContext}.
17
17
  #
@@ -35,6 +35,30 @@ module OpenTelemetry
35
35
  @remote = remote
36
36
  end
37
37
 
38
+ # Returns the lowercase [hex encoded](https://tools.ietf.org/html/rfc4648#section-8) trace ID.
39
+ #
40
+ # @return [String] A 32-hex-character lowercase string.
41
+ def hex_trace_id
42
+ @trace_id.unpack1('H*')
43
+ end
44
+
45
+ # Returns the lowercase [hex encoded](https://tools.ietf.org/html/rfc4648#section-8) span ID.
46
+ #
47
+ # @return [String] A 16-hex-character lowercase string.
48
+ def hex_span_id
49
+ @span_id.unpack1('H*')
50
+ end
51
+
52
+ # Returns the binary representation of the trace ID.
53
+ #
54
+ # @return [String] A 16-byte binary string.
55
+ attr_reader :trace_id
56
+
57
+ # Returns the binary representation of the span ID.
58
+ #
59
+ # @return [String] An 8-byte binary string.
60
+ attr_reader :span_id
61
+
38
62
  # Returns true if the {SpanContext} has a non-zero trace ID and non-zero span ID.
39
63
  #
40
64
  # @return [Boolean]
@@ -56,7 +56,7 @@ module OpenTelemetry
56
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)
57
57
  with_span(span) { |s, c| yield s, c }
58
58
  rescue Exception => e # rubocop:disable Lint/RescueException
59
- span.record_error(e)
59
+ span.record_exception(e)
60
60
  span.status = Status.new(Status::UNKNOWN_ERROR,
61
61
  description: "Unhandled exception of type: #{e.class}")
62
62
  raise e
@@ -6,5 +6,5 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  ## Current OpenTelemetry version
9
- VERSION = '0.5.1'
9
+ VERSION = '0.6.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.5.1
4
+ version: 0.6.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-07-21 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ipsa
@@ -149,6 +149,13 @@ files:
149
149
  - OVERVIEW.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
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
@@ -213,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
211
  - !ruby/object:Gem::Version
214
212
  version: '0'
215
213
  requirements: []
216
- rubygems_version: 3.0.3
214
+ rubygems_version: 3.1.2
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_OTCORRELATIONS'
22
- )
23
- RACK_INJECTOR = TextInjector.new(
24
- correlation_context_key: 'HTTP_OTCORRELATIONS'
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: 'otcorrelations')
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