opentelemetry-sdk 0.14.0 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -44
  3. data/README.md +2 -2
  4. data/lib/opentelemetry/sdk.rb +4 -3
  5. data/lib/opentelemetry/sdk/configurator.rb +52 -33
  6. data/lib/opentelemetry/sdk/forwarding_logger.rb +69 -0
  7. data/lib/opentelemetry/sdk/internal.rb +3 -3
  8. data/lib/opentelemetry/sdk/resources/constants.rb +48 -3
  9. data/lib/opentelemetry/sdk/resources/resource.rb +8 -1
  10. data/lib/opentelemetry/sdk/trace.rb +2 -3
  11. data/lib/opentelemetry/sdk/trace/event.rb +7 -36
  12. data/lib/opentelemetry/sdk/trace/export.rb +1 -2
  13. data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +10 -5
  14. data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +4 -0
  15. data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +23 -4
  16. data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +4 -2
  17. data/lib/opentelemetry/sdk/trace/export/{noop_span_exporter.rb → span_exporter.rb} +18 -7
  18. data/lib/opentelemetry/sdk/trace/span.rb +83 -39
  19. data/lib/opentelemetry/sdk/trace/span_data.rb +25 -18
  20. data/lib/opentelemetry/sdk/trace/span_limits.rb +60 -0
  21. data/lib/opentelemetry/sdk/trace/{noop_span_processor.rb → span_processor.rb} +5 -8
  22. data/lib/opentelemetry/sdk/trace/tracer.rb +1 -37
  23. data/lib/opentelemetry/sdk/trace/tracer_provider.rb +106 -19
  24. data/lib/opentelemetry/sdk/version.rb +1 -1
  25. metadata +43 -20
  26. data/lib/opentelemetry/sdk/baggage.rb +0 -16
  27. data/lib/opentelemetry/sdk/baggage/builder.rb +0 -40
  28. data/lib/opentelemetry/sdk/baggage/manager.rb +0 -97
  29. data/lib/opentelemetry/sdk/trace/config.rb +0 -18
  30. data/lib/opentelemetry/sdk/trace/config/trace_config.rb +0 -79
  31. data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +0 -59
  32. data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +0 -86
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'opentelemetry/sdk/baggage/builder'
8
- require 'opentelemetry/sdk/baggage/manager'
9
-
10
- module OpenTelemetry
11
- module SDK
12
- # Contains operational implementations of the Baggage::Manager
13
- module Baggage
14
- end
15
- end
16
- end
@@ -1,40 +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 SDK
9
- module Baggage
10
- # SDK implementation of Baggage::Builder
11
- class Builder
12
- attr_reader :entries
13
-
14
- def initialize(entries)
15
- @entries = entries
16
- end
17
-
18
- # Set key-value in the to-be-created baggage
19
- #
20
- # @param [String] key The key to store this value under
21
- # @param [String] value String value to be stored under key
22
- def set_value(key, value)
23
- @entries[key] = value.to_s
24
- end
25
-
26
- # Removes key from the to-be-created baggage
27
- #
28
- # @param [String] key The key to remove
29
- def remove_value(key)
30
- @entries.delete(key)
31
- end
32
-
33
- # Clears all baggage from the to-be-created baggage
34
- def clear
35
- @entries.clear
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,97 +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 SDK
9
- module Baggage
10
- # Manages baggage
11
- class Manager
12
- BAGGAGE_KEY = OpenTelemetry::Baggage::Propagation::ContextKeys.baggage_key
13
- EMPTY_BAGGAGE = {}.freeze
14
- private_constant(:BAGGAGE_KEY, :EMPTY_BAGGAGE)
15
-
16
- # Used to chain modifications to baggage. The result is a
17
- # context with an updated baggage. If only a single
18
- # modification is being made to baggage, use the other
19
- # methods on +Manager+, if multiple modifications are being made, use
20
- # this one.
21
- #
22
- # @param [optional Context] context The context to update with with new
23
- # modified baggage. Defaults to +Context.current+
24
- # @return [Context]
25
- def build_context(context: Context.current)
26
- builder = Builder.new(baggage_for(context).dup)
27
- yield builder
28
- context.set_value(BAGGAGE_KEY, builder.entries)
29
- end
30
-
31
- # Returns a new context with empty baggage
32
- #
33
- # @param [optional Context] context Context to clear baggage from. Defaults
34
- # to +Context.current+
35
- # @return [Context]
36
- def clear(context: Context.current)
37
- context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE)
38
- end
39
-
40
- # Returns the corresponding baggage value (or nil) for key
41
- #
42
- # @param [String] key The lookup key
43
- # @param [optional Context] context The context from which to retrieve
44
- # the key.
45
- # Defaults to +Context.current+
46
- # @return [String]
47
- def value(key, context: Context.current)
48
- baggage_for(context)[key]
49
- end
50
-
51
- # Returns the baggage
52
- #
53
- # @param [optional Context] context The context from which to retrieve
54
- # the baggage.
55
- # Defaults to +Context.current+
56
- # @return [Hash]
57
- def values(context: Context.current)
58
- baggage_for(context).dup.freeze
59
- end
60
-
61
- # Returns a new context with new key-value pair
62
- #
63
- # @param [String] key The key to store this value under
64
- # @param [String] value String value to be stored under key
65
- # @param [optional Context] context The context to update with new
66
- # value. Defaults to +Context.current+
67
- # @return [Context]
68
- def set_value(key, value, context: Context.current)
69
- new_baggage = baggage_for(context).dup
70
- new_baggage[key] = value
71
- context.set_value(BAGGAGE_KEY, new_baggage)
72
- end
73
-
74
- # Returns a new context with value at key removed
75
- #
76
- # @param [String] key The key to remove
77
- # @param [optional Context] context The context to remove baggage
78
- # from. Defaults to +Context.current+
79
- # @return [Context]
80
- def remove_value(key, context: Context.current)
81
- baggage = baggage_for(context)
82
- return context unless baggage.key?(key)
83
-
84
- new_baggage = baggage.dup
85
- new_baggage.delete(key)
86
- context.set_value(BAGGAGE_KEY, new_baggage)
87
- end
88
-
89
- private
90
-
91
- def baggage_for(context)
92
- context.value(BAGGAGE_KEY) || EMPTY_BAGGAGE
93
- end
94
- end
95
- end
96
- end
97
- 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 SDK
9
- module Trace
10
- # The Config module contains the configuration logic for the
11
- # OpenTelemetry SDK.
12
- module Config
13
- end
14
- end
15
- end
16
- end
17
-
18
- require 'opentelemetry/sdk/trace/config/trace_config'
@@ -1,79 +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 SDK
9
- module Trace
10
- module Config
11
- # Class that holds global trace parameters.
12
- class TraceConfig
13
- # The global default sampler (see {Samplers}).
14
- attr_reader :sampler
15
-
16
- # The global default max number of attributes per {Span}.
17
- attr_reader :max_attributes_count
18
-
19
- # The global default max number of {OpenTelemetry::SDK::Trace::Event}s per {Span}.
20
- attr_reader :max_events_count
21
-
22
- # The global default max number of {OpenTelemetry::Trace::Link} entries per {Span}.
23
- attr_reader :max_links_count
24
-
25
- # The global default max number of attributes per {OpenTelemetry::SDK::Trace::Event}.
26
- attr_reader :max_attributes_per_event
27
-
28
- # The global default max number of attributes per {OpenTelemetry::Trace::Link}.
29
- attr_reader :max_attributes_per_link
30
-
31
- # Returns a {TraceConfig} with the desired values.
32
- #
33
- # @return [TraceConfig] with the desired values.
34
- # @raise [ArgumentError] if any of the max numbers are not positive.
35
- def initialize(sampler: sampler_from_environment(Samplers.parent_based(root: Samplers::ALWAYS_ON)),
36
- max_attributes_count: Integer(ENV.fetch('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 1000)),
37
- max_events_count: Integer(ENV.fetch('OTEL_SPAN_EVENT_COUNT_LIMIT', 1000)),
38
- max_links_count: Integer(ENV.fetch('OTEL_SPAN_LINK_COUNT_LIMIT', 1000)),
39
- max_attributes_per_event: max_attributes_count,
40
- max_attributes_per_link: max_attributes_count)
41
- raise ArgumentError, 'max_attributes_count must be positive' unless max_attributes_count.positive?
42
- raise ArgumentError, 'max_events_count must be positive' unless max_events_count.positive?
43
- raise ArgumentError, 'max_links_count must be positive' unless max_links_count.positive?
44
- raise ArgumentError, 'max_attributes_per_event must be positive' unless max_attributes_per_event.positive?
45
- raise ArgumentError, 'max_attributes_per_link must be positive' unless max_attributes_per_link.positive?
46
-
47
- @sampler = sampler
48
- @max_attributes_count = max_attributes_count
49
- @max_events_count = max_events_count
50
- @max_links_count = max_links_count
51
- @max_attributes_per_event = max_attributes_per_event
52
- @max_attributes_per_link = max_attributes_per_link
53
- end
54
-
55
- # TODO: from_proto
56
- private
57
-
58
- def sampler_from_environment(default_sampler) # rubocop:disable Metrics/CyclomaticComplexity
59
- case ENV['OTEL_TRACE_SAMPLER']
60
- when 'always_on' then Samplers::ALWAYS_ON
61
- when 'always_off' then Samplers::ALWAYS_OFF
62
- when 'traceidratio' then Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACE_SAMPLER_ARG', 1.0)))
63
- when 'parentbased_always_on' then Samplers.parent_based(root: Samplers::ALWAYS_ON)
64
- when 'parentbased_always_off' then Samplers.parent_based(root: Samplers::ALWAYS_OFF)
65
- when 'parentbased_traceidratio' then Samplers.parent_based(root: Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACE_SAMPLER_ARG', 1.0))))
66
- else default_sampler
67
- end
68
- rescue StandardError => e
69
- OpenTelemetry.handle_error(exception: e, message: "installing default sampler #{default_sampler.description}")
70
- default_sampler
71
- end
72
-
73
- # The default {TraceConfig}.
74
- DEFAULT = new
75
- end
76
- end
77
- end
78
- end
79
- end
@@ -1,59 +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 SDK
9
- module Trace
10
- module Export
11
- # Implementation of the SpanExporter duck type that simply forwards all
12
- # received spans to a collection of SpanExporters.
13
- #
14
- # Can be used to export to multiple backends using the same
15
- # SpanProcessor like a {SimpleSpanProcessor} or a
16
- # {BatchSpanProcessor}.
17
- class MultiSpanExporter
18
- def initialize(span_exporters)
19
- @span_exporters = span_exporters.clone.freeze
20
- end
21
-
22
- # Called to export sampled {Span}s.
23
- #
24
- # @param [Enumerable<Span>] spans the list of sampled {Span}s to be
25
- # exported.
26
- # @param [optional Numeric] timeout An optional timeout in seconds.
27
- # @return [Integer] the result of the export.
28
- def export(spans, timeout: nil)
29
- start_time = Time.now
30
- results = @span_exporters.map do |span_exporter|
31
- span_exporter.export(spans, timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
32
- rescue => e # rubocop:disable Style/RescueStandardError
33
- OpenTelemetry.logger.warn("exception raised by export - #{e}")
34
- FAILURE
35
- end
36
- results.uniq.max || SUCCESS
37
- end
38
-
39
- # Called when {TracerProvider#shutdown} is called, if this exporter is
40
- # registered to a {TracerProvider} object.
41
- #
42
- # @param [optional Numeric] timeout An optional timeout in seconds.
43
- # @return [Integer] SUCCESS if no error occurred, FAILURE if a
44
- # non-specific failure occurred, TIMEOUT if a timeout occurred.
45
- def shutdown(timeout: nil)
46
- start_time = Time.now
47
- results = @span_exporters.map do |processor|
48
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
49
- return TIMEOUT if remaining_timeout&.zero?
50
-
51
- processor.shutdown(timeout: remaining_timeout)
52
- end
53
- results.uniq.max || SUCCESS
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,86 +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 SDK
9
- module Trace
10
- # Implementation of the SpanProcessor duck type that simply forwards all
11
- # received events to a list of SpanProcessors.
12
- class MultiSpanProcessor
13
- # Creates a new {MultiSpanProcessor}.
14
- #
15
- # @param [Enumerable<SpanProcessor>] span_processors a collection of
16
- # SpanProcessors.
17
- # @return [MultiSpanProcessor]
18
- def initialize(span_processors)
19
- @span_processors = span_processors.to_a.freeze
20
- end
21
-
22
- # Called when a {Span} is started, if the {Span#recording?}
23
- # returns true.
24
- #
25
- # This method is called synchronously on the execution thread, should
26
- # not throw or block the execution thread.
27
- #
28
- # @param [Span] span the {Span} that just started.
29
- # @param [Context] parent_context the parent {Context} of the newly
30
- # started span.
31
- def on_start(span, parent_context)
32
- @span_processors.each { |processor| processor.on_start(span, parent_context) }
33
- end
34
-
35
- # Called when a {Span} is ended, if the {Span#recording?}
36
- # returns true.
37
- #
38
- # This method is called synchronously on the execution thread, should
39
- # not throw or block the execution thread.
40
- #
41
- # @param [Span] span the {Span} that just ended.
42
- def on_finish(span)
43
- @span_processors.each { |processor| processor.on_finish(span) }
44
- end
45
-
46
- # Export all ended spans to the configured `Exporter` that have not yet
47
- # been exported.
48
- #
49
- # This method should only be called in cases where it is absolutely
50
- # necessary, such as when using some FaaS providers that may suspend
51
- # the process after an invocation, but before the `Processor` exports
52
- # the completed spans.
53
- #
54
- # @param [optional Numeric] timeout An optional timeout in seconds.
55
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
56
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
57
- def force_flush(timeout: nil)
58
- start_time = Time.now
59
- results = @span_processors.map do |processor|
60
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
61
- return Export::TIMEOUT if remaining_timeout&.zero?
62
-
63
- processor.force_flush(timeout: remaining_timeout)
64
- end
65
- results.uniq.max
66
- end
67
-
68
- # Called when {TracerProvider#shutdown} is called.
69
- #
70
- # @param [optional Numeric] timeout An optional timeout in seconds.
71
- # @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
72
- # a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
73
- def shutdown(timeout: nil)
74
- start_time = Time.now
75
- results = @span_processors.map do |processor|
76
- remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
77
- return Export::TIMEOUT if remaining_timeout&.zero?
78
-
79
- processor.shutdown(timeout: remaining_timeout)
80
- end
81
- results.uniq.max
82
- end
83
- end
84
- end
85
- end
86
- end