opentelemetry-sdk 0.10.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/LICENSE +1 -1
  4. data/README.md +2 -2
  5. data/lib/opentelemetry-sdk.rb +1 -1
  6. data/lib/opentelemetry/sdk.rb +12 -1
  7. data/lib/opentelemetry/sdk/baggage.rb +1 -1
  8. data/lib/opentelemetry/sdk/baggage/builder.rb +1 -1
  9. data/lib/opentelemetry/sdk/baggage/manager.rb +1 -1
  10. data/lib/opentelemetry/sdk/configurator.rb +15 -8
  11. data/lib/opentelemetry/sdk/instrumentation_library.rb +1 -1
  12. data/lib/opentelemetry/sdk/internal.rb +12 -2
  13. data/lib/opentelemetry/sdk/resources.rb +1 -1
  14. data/lib/opentelemetry/sdk/resources/constants.rb +41 -1
  15. data/lib/opentelemetry/sdk/resources/resource.rb +19 -7
  16. data/lib/opentelemetry/sdk/trace.rb +1 -1
  17. data/lib/opentelemetry/sdk/trace/config.rb +1 -1
  18. data/lib/opentelemetry/sdk/trace/config/trace_config.rb +23 -21
  19. data/lib/opentelemetry/sdk/trace/event.rb +1 -1
  20. data/lib/opentelemetry/sdk/trace/export.rb +2 -1
  21. data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +44 -21
  22. data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +1 -1
  23. data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +1 -1
  24. data/lib/opentelemetry/sdk/trace/export/metrics_reporter.rb +59 -0
  25. data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +1 -1
  26. data/lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb +1 -1
  27. data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +2 -2
  28. data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +1 -1
  29. data/lib/opentelemetry/sdk/trace/noop_span_processor.rb +1 -1
  30. data/lib/opentelemetry/sdk/trace/samplers.rb +1 -1
  31. data/lib/opentelemetry/sdk/trace/samplers/constant_sampler.rb +8 -0
  32. data/lib/opentelemetry/sdk/trace/samplers/decision.rb +1 -1
  33. data/lib/opentelemetry/sdk/trace/samplers/parent_based.rb +12 -0
  34. data/lib/opentelemetry/sdk/trace/samplers/result.rb +1 -1
  35. data/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +5 -1
  36. data/lib/opentelemetry/sdk/trace/span.rb +23 -13
  37. data/lib/opentelemetry/sdk/trace/span_data.rb +1 -1
  38. data/lib/opentelemetry/sdk/trace/tracer.rb +6 -5
  39. data/lib/opentelemetry/sdk/trace/tracer_provider.rb +3 -2
  40. data/lib/opentelemetry/sdk/version.rb +2 -2
  41. metadata +10 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dd502ccc29f875d2af8691a99945f9ff6fcea5505ec0541fffb9798cc8406ec
4
- data.tar.gz: 32c4805d198ad93f29c8b51ebd0d0b2fa0c5d13b5bfc595c22b12762d954259a
3
+ metadata.gz: b64da58e8086f08efd2f7bace98369ec16936abcf95996588bda288a592d5912
4
+ data.tar.gz: 4d67cd982c51998cf0396531bcbaae6f62f23b89314793def72410624c87a645
5
5
  SHA512:
6
- metadata.gz: 8a10fb701cec552ce95f61cdbc124dc82f962cbab938e8c41b897d23d5ad8f778b6487605d35d09876fa8259612cef6f570e8991ba8258dcd0ed2ef9af82040a
7
- data.tar.gz: ec7430fe3bd0ab0f0999c9d22c5d6addbcb45bc37e31b2eb83cb9ddc492c900cf5bf5acd2721c5eadaf1f58caf358d8a0607d7a08aeec7a8de09569f9badb5be
6
+ metadata.gz: 3d8d0331a351e32cf184a512c155c6d3944bb5bbbb2857aad27636bdc7eca58081d45e6d778eecd50681e1a1c471c75f9cf7d8116b57ba5c5c5b7a5838f3a648
7
+ data.tar.gz: ef884f72a85e1457b1d160d2075313df169f895cfe92831d87e77022244db6b6d980f7a36f6c88926886fd67538e916c2e813728ce80aa2897ef24da216d2924
@@ -1,5 +1,37 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v0.13.0 / 2021-01-29
4
+
5
+ * BREAKING CHANGE: Remove MILLIS from BatchSpanProcessor vars
6
+
7
+ * ADDED: Process.runtime resource
8
+ * ADDED: Provide default resource in SDK
9
+ * ADDED: Add optional attributes to record_exception
10
+ * FIXED: Resource.merge consistency
11
+ * FIXED: Remove MILLIS from BatchSpanProcessor vars
12
+
13
+ ### v0.12.1 / 2021-01-13
14
+
15
+ * FIXED: Fix several BatchSpanProcessor errors related to fork safety
16
+ * FIXED: Define default value for traceid ratio
17
+
18
+ ### v0.12.0 / 2020-12-24
19
+
20
+ * ADDED: Structured error handling
21
+ * ADDED: Pluggable ID generation
22
+ * FIXED: BSP dropped span buffer full reporting
23
+ * FIXED: Implement SDK environment variables
24
+ * FIXED: Remove incorrect TODO
25
+
26
+ ### v0.11.1 / 2020-12-16
27
+
28
+ * FIXED: BSP dropped span buffer full reporting
29
+
30
+ ### v0.11.0 / 2020-12-11
31
+
32
+ * ADDED: Metrics reporting from trace export
33
+ * FIXED: Copyright comments to not reference year
34
+
3
35
  ### v0.10.0 / 2020-12-03
4
36
 
5
37
  * BREAKING CHANGE: Allow samplers to modify tracestate
data/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2020 OpenTelemetry Authors
189
+ Copyright The OpenTelemetry Authors
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -66,8 +66,8 @@ The `opentelemetry-sdk` gem is distributed under the Apache 2.0 license. See [LI
66
66
  [opentelemetry-home]: https://opentelemetry.io
67
67
  [bundler-home]: https://bundler.io
68
68
  [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
69
- [license-github]: https://github.com/open-telemetry/opentelemetry-ruby/blob/master/LICENSE
70
- [examples-github]: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/examples
69
+ [license-github]: https://github.com/open-telemetry/opentelemetry-ruby/blob/main/LICENSE
70
+ [examples-github]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/examples
71
71
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
72
72
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
73
73
  [ruby-gitter]: https://gitter.im/open-telemetry/opentelemetry-ruby
@@ -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
 
@@ -18,6 +18,11 @@ module OpenTelemetry
18
18
  module SDK
19
19
  extend self
20
20
 
21
+ # ConfigurationError is an exception type used to wrap configuration errors
22
+ # passed to OpenTelemetry.error_handler. This can be used to distinguish
23
+ # errors reported during SDK configuration.
24
+ ConfigurationError = Class.new(OpenTelemetry::Error)
25
+
21
26
  # Configures SDK and instrumentation
22
27
  #
23
28
  # @yieldparam [Configurator] configurator Yields a configurator to the
@@ -57,6 +62,12 @@ module OpenTelemetry
57
62
  configurator = Configurator.new
58
63
  yield configurator if block_given?
59
64
  configurator.configure
65
+ rescue StandardError
66
+ begin
67
+ raise ConfigurationError
68
+ rescue ConfigurationError => e
69
+ OpenTelemetry.handle_error(exception: e, message: 'unexpected configuration error')
70
+ end
60
71
  end
61
72
  end
62
73
  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,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
 
@@ -16,7 +16,7 @@ module OpenTelemetry
16
16
  private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL
17
17
 
18
18
  attr_writer :logger, :http_extractors, :http_injectors, :text_map_extractors,
19
- :text_map_injectors
19
+ :text_map_injectors, :error_handler, :id_generator
20
20
 
21
21
  def initialize
22
22
  @instrumentation_names = []
@@ -27,13 +27,18 @@ module OpenTelemetry
27
27
  @text_map_injectors = nil
28
28
  @span_processors = []
29
29
  @use_mode = USE_MODE_UNSPECIFIED
30
- @resource = Resources::Resource.telemetry_sdk
30
+ @resource = Resources::Resource.default
31
+ @id_generator = OpenTelemetry::Trace
31
32
  end
32
33
 
33
34
  def logger
34
35
  @logger ||= OpenTelemetry.logger
35
36
  end
36
37
 
38
+ def error_handler
39
+ @error_handler ||= OpenTelemetry.error_handler
40
+ end
41
+
37
42
  # Accepts a resource object that is merged with the default telemetry sdk
38
43
  # resource. The use of this method is optional, and is provided as means
39
44
  # to include additional resource information.
@@ -41,7 +46,7 @@ module OpenTelemetry
41
46
  #
42
47
  # @param [Resource] new_resource The resource to be merged
43
48
  def resource=(new_resource)
44
- @resource = new_resource.merge(@resource)
49
+ @resource = @resource.merge(new_resource)
45
50
  end
46
51
 
47
52
  # Accepts a string that is merged in as the service.name resource attribute.
@@ -49,9 +54,9 @@ module OpenTelemetry
49
54
  # calls to this setter.
50
55
  # @param [String] service_name The value to be used as the service name
51
56
  def service_name=(service_name)
52
- @resource = OpenTelemetry::SDK::Resources::Resource.create(
57
+ self.resource = OpenTelemetry::SDK::Resources::Resource.create(
53
58
  OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:name] => service_name
54
- ).merge(@resource)
59
+ )
55
60
  end
56
61
 
57
62
  # Accepts a string that is merged in as the service.version resource attribute.
@@ -59,9 +64,9 @@ module OpenTelemetry
59
64
  # calls to this setter.
60
65
  # @param [String] service_version The value to be used as the service version
61
66
  def service_version=(service_version)
62
- @resource = OpenTelemetry::SDK::Resources::Resource.create(
67
+ self.resource = OpenTelemetry::SDK::Resources::Resource.create(
63
68
  OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:version] => service_version
64
- ).merge(@resource)
69
+ )
65
70
  end
66
71
 
67
72
  # Install an instrumentation with specificied optional +config+.
@@ -110,9 +115,11 @@ module OpenTelemetry
110
115
  # - install instrumentation
111
116
  def configure
112
117
  OpenTelemetry.logger = logger
118
+ OpenTelemetry.error_handler = error_handler
113
119
  OpenTelemetry.baggage = Baggage::Manager.new
114
120
  configure_propagation
115
121
  configure_span_processors
122
+ tracer_provider.id_generator = @id_generator
116
123
  OpenTelemetry.tracer_provider = tracer_provider
117
124
  install_instrumentation
118
125
  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,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
 
@@ -45,7 +45,17 @@ module OpenTelemetry
45
45
  end
46
46
 
47
47
  def valid_attributes?(attrs)
48
- attrs.nil? || attrs.all? { |k, v| valid_key?(k) && valid_value?(v) }
48
+ attrs.nil? || attrs.all? do |k, v|
49
+ if !valid_key?(k)
50
+ OpenTelemetry.handle_error(message: "invalid attribute key type #{v.class}")
51
+ false
52
+ elsif !valid_value?(v)
53
+ OpenTelemetry.handle_error(message: "invalid attribute value type #{v.class}")
54
+ false
55
+ else
56
+ true
57
+ end
58
+ end
49
59
  end
50
60
  end
51
61
  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,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
 
@@ -77,6 +77,46 @@ module OpenTelemetry
77
77
  deployment_name: 'k8s.deployment.name'
78
78
  }.freeze
79
79
 
80
+ # Attributes defining an operating system process.
81
+ PROCESS_RESOURCE = {
82
+ # Process identifier (PID).
83
+ pid: 'process.pid',
84
+
85
+ # The name of the process executable.
86
+ executable_name: 'process.executable.name',
87
+
88
+ # The full path to the process executable.
89
+ executable_path: 'process.executable.path',
90
+
91
+ # The command used to launch the process (i.e. the command name).
92
+ command: 'process.command',
93
+
94
+ # The full command used to launch the process as a single string
95
+ # representing the full command.
96
+ command_line: 'process.command_line',
97
+
98
+ # All the command arguments (including the command/executable itself)
99
+ # as received by the process.
100
+ command_args: 'process.command_args',
101
+
102
+ # The username of the user that owns the process.
103
+ owner: 'process.owner'
104
+ }.freeze
105
+
106
+ # Attributes defining the single (language) runtime instance which is monitored.
107
+ PROCESS_RUNTIME_RESOURCE = {
108
+ # The name of the runtime of this process.
109
+ name: 'process.runtime.name',
110
+
111
+ # The version of the runtime of this process, as returned by the runtime
112
+ # without modification.
113
+ version: 'process.runtime.version',
114
+
115
+ # An additional description about the runtime of the process, for example
116
+ # a specific vendor customization of the runtime environment.
117
+ description: 'process.runtime.description'
118
+ }.freeze
119
+
80
120
  # Attributes defining a computing instance (e.g. host).
81
121
  HOST_RESOURCE = {
82
122
  # Unique host id. For Cloud this must be the instance_id assigned by the
@@ -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
 
@@ -22,7 +22,7 @@ module OpenTelemetry
22
22
  def create(attributes = {})
23
23
  frozen_attributes = attributes.each_with_object({}) do |(k, v), memo|
24
24
  raise ArgumentError, 'attribute keys must be strings' unless k.is_a?(String)
25
- raise ArgumentError, 'attribute values must be strings, integers, floats, or booleans' unless Internal.valid_value?(v)
25
+ raise ArgumentError, 'attribute values must be (array of) strings, integers, floats, or booleans' unless Internal.valid_value?(v)
26
26
 
27
27
  memo[-k] = v.freeze
28
28
  end.freeze
@@ -30,6 +30,10 @@ module OpenTelemetry
30
30
  new(frozen_attributes)
31
31
  end
32
32
 
33
+ def default
34
+ @default ||= telemetry_sdk.merge(process).merge(create(Constants::SERVICE_RESOURCE[:name] => 'unknown_service'))
35
+ end
36
+
33
37
  def telemetry_sdk
34
38
  resource_attributes = {
35
39
  Constants::TELEMETRY_SDK_RESOURCE[:name] => 'opentelemetry',
@@ -48,6 +52,18 @@ module OpenTelemetry
48
52
  resource_attributes.delete_if { |_key, value| value.nil? || value.empty? }
49
53
  create(resource_attributes)
50
54
  end
55
+
56
+ def process
57
+ resource_attributes = {
58
+ Constants::PROCESS_RESOURCE[:pid] => Process.pid,
59
+ Constants::PROCESS_RESOURCE[:command] => $PROGRAM_NAME,
60
+ Constants::PROCESS_RUNTIME_RESOURCE[:name] => RUBY_ENGINE,
61
+ Constants::PROCESS_RUNTIME_RESOURCE[:version] => RUBY_VERSION,
62
+ Constants::PROCESS_RUNTIME_RESOURCE[:description] => RUBY_DESCRIPTION
63
+ }
64
+
65
+ create(resource_attributes)
66
+ end
51
67
  end
52
68
 
53
69
  # @api private
@@ -79,11 +95,7 @@ module OpenTelemetry
79
95
  def merge(other)
80
96
  return self unless other.is_a?(Resource)
81
97
 
82
- merged_attributes = attributes.merge(other.attributes) do |_, old_v, new_v|
83
- old_v.empty? ? new_v : old_v
84
- end
85
-
86
- self.class.send(:new, merged_attributes.freeze)
98
+ self.class.send(:new, attributes.merge(other.attributes).freeze)
87
99
  end
88
100
 
89
101
  protected
@@ -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
 
@@ -10,20 +10,6 @@ module OpenTelemetry
10
10
  module Config
11
11
  # Class that holds global trace parameters.
12
12
  class TraceConfig
13
- DEFAULT_SAMPLER = Samplers.parent_based(root: Samplers::ALWAYS_ON)
14
- DEFAULT_MAX_ATTRIBUTES_COUNT = 32
15
- DEFAULT_MAX_EVENTS_COUNT = 128
16
- DEFAULT_MAX_LINKS_COUNT = 32
17
- DEFAULT_MAX_ATTRIBUTES_PER_EVENT = 32
18
- DEFAULT_MAX_ATTRIBUTES_PER_LINK = 32
19
-
20
- private_constant(:DEFAULT_SAMPLER,
21
- :DEFAULT_MAX_ATTRIBUTES_COUNT,
22
- :DEFAULT_MAX_EVENTS_COUNT,
23
- :DEFAULT_MAX_LINKS_COUNT,
24
- :DEFAULT_MAX_ATTRIBUTES_PER_EVENT,
25
- :DEFAULT_MAX_ATTRIBUTES_PER_LINK)
26
-
27
13
  # The global default sampler (see {Samplers}).
28
14
  attr_reader :sampler
29
15
 
@@ -46,12 +32,12 @@ module OpenTelemetry
46
32
  #
47
33
  # @return [TraceConfig] with the desired values.
48
34
  # @raise [ArgumentError] if any of the max numbers are not positive.
49
- def initialize(sampler: DEFAULT_SAMPLER,
50
- max_attributes_count: DEFAULT_MAX_ATTRIBUTES_COUNT,
51
- max_events_count: DEFAULT_MAX_EVENTS_COUNT,
52
- max_links_count: DEFAULT_MAX_LINKS_COUNT,
53
- max_attributes_per_event: DEFAULT_MAX_ATTRIBUTES_PER_EVENT,
54
- max_attributes_per_link: DEFAULT_MAX_ATTRIBUTES_PER_LINK)
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)
55
41
  raise ArgumentError, 'max_attributes_count must be positive' unless max_attributes_count.positive?
56
42
  raise ArgumentError, 'max_events_count must be positive' unless max_events_count.positive?
57
43
  raise ArgumentError, 'max_links_count must be positive' unless max_links_count.positive?
@@ -67,6 +53,22 @@ module OpenTelemetry
67
53
  end
68
54
 
69
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
70
72
 
71
73
  # The default {TraceConfig}.
72
74
  DEFAULT = new
@@ -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
 
@@ -30,6 +30,7 @@ end
30
30
  require 'opentelemetry/sdk/trace/export/batch_span_processor'
31
31
  require 'opentelemetry/sdk/trace/export/console_span_exporter'
32
32
  require 'opentelemetry/sdk/trace/export/in_memory_span_exporter'
33
+ require 'opentelemetry/sdk/trace/export/metrics_reporter'
33
34
  require 'opentelemetry/sdk/trace/export/multi_span_exporter'
34
35
  require 'opentelemetry/sdk/trace/export/noop_span_exporter'
35
36
  require 'opentelemetry/sdk/trace/export/simple_span_processor'
@@ -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
 
@@ -19,7 +19,7 @@ module OpenTelemetry
19
19
  # All spans reported by the SDK implementation are first added to a
20
20
  # synchronized queue (with a {max_queue_size} maximum size, after the
21
21
  # size is reached spans are dropped) and exported every
22
- # schedule_delay_millis to the exporter pipeline in batches of
22
+ # schedule_delay to the exporter pipeline in batches of
23
23
  # max_export_batch_size.
24
24
  #
25
25
  # If the queue gets half full a preemptive notification is sent to the
@@ -29,11 +29,11 @@ module OpenTelemetry
29
29
  # Returns a new instance of the {BatchSpanProcessor}.
30
30
  #
31
31
  # @param [SpanExporter] exporter
32
- # @param [Numeric] exporter_timeout_millis the delay interval between two
33
- # consecutive exports. Defaults to the value of the OTEL_BSP_EXPORT_TIMEOUT_MILLIS
32
+ # @param [Numeric] exporter_timeout the delay interval between two
33
+ # consecutive exports. Defaults to the value of the OTEL_BSP_EXPORT_TIMEOUT
34
34
  # environment variable, if set, or 30,000 (30 seconds).
35
- # @param [Numeric] schedule_delay_millis the maximum allowed time to export data.
36
- # Defaults to the value of the OTEL_BSP_SCHEDULE_DELAY_MILLIS environment
35
+ # @param [Numeric] schedule_delay the maximum allowed time to export data.
36
+ # Defaults to the value of the OTEL_BSP_SCHEDULE_DELAY environment
37
37
  # variable, if set, or 5,000 (5 seconds).
38
38
  # @param [Integer] max_queue_size the maximum queue size in spans.
39
39
  # Defaults to the value of the OTEL_BSP_MAX_QUEUE_SIZE environment
@@ -44,22 +44,24 @@ module OpenTelemetry
44
44
  #
45
45
  # @return a new instance of the {BatchSpanProcessor}.
46
46
  def initialize(exporter:,
47
- exporter_timeout_millis: Float(ENV.fetch('OTEL_BSP_EXPORT_TIMEOUT_MILLIS', 30_000)),
48
- schedule_delay_millis: Float(ENV.fetch('OTEL_BSP_SCHEDULE_DELAY_MILLIS', 5_000)),
47
+ exporter_timeout: Float(ENV.fetch('OTEL_BSP_EXPORT_TIMEOUT', 30_000)),
48
+ schedule_delay: Float(ENV.fetch('OTEL_BSP_SCHEDULE_DELAY', 5_000)),
49
49
  max_queue_size: Integer(ENV.fetch('OTEL_BSP_MAX_QUEUE_SIZE', 2048)),
50
50
  max_export_batch_size: Integer(ENV.fetch('OTEL_BSP_MAX_EXPORT_BATCH_SIZE', 512)),
51
- start_thread_on_boot: String(ENV['OTEL_RUBY_BSP_START_THREAD_ON_BOOT']) !~ /false/i)
51
+ start_thread_on_boot: String(ENV['OTEL_RUBY_BSP_START_THREAD_ON_BOOT']) !~ /false/i,
52
+ metrics_reporter: nil)
52
53
  raise ArgumentError if max_export_batch_size > max_queue_size
53
54
 
54
55
  @exporter = exporter
55
- @exporter_timeout_seconds = exporter_timeout_millis / 1000.0
56
+ @exporter_timeout_seconds = exporter_timeout / 1000.0
56
57
  @mutex = Mutex.new
57
58
  @export_mutex = Mutex.new
58
59
  @condition = ConditionVariable.new
59
60
  @keep_running = true
60
- @delay_seconds = schedule_delay_millis / 1000.0
61
+ @delay_seconds = schedule_delay / 1000.0
61
62
  @max_queue_size = max_queue_size
62
63
  @batch_size = max_export_batch_size
64
+ @metrics_reporter = metrics_reporter || OpenTelemetry::SDK::Trace::Export::MetricsReporter
63
65
  @spans = []
64
66
  @pid = nil
65
67
  @thread = nil
@@ -76,7 +78,10 @@ module OpenTelemetry
76
78
  lock do
77
79
  reset_on_fork
78
80
  n = spans.size + 1 - max_queue_size
79
- spans.shift(n) if n.positive?
81
+ if n.positive?
82
+ spans.shift(n)
83
+ report_dropped_spans(n, reason: 'buffer-full')
84
+ end
80
85
  spans << span
81
86
  @condition.signal if spans.size > batch_size
82
87
  end
@@ -93,10 +98,10 @@ module OpenTelemetry
93
98
  # @param [optional Numeric] timeout An optional timeout in seconds.
94
99
  # @return [Integer] SUCCESS if no error occurred, FAILURE if a
95
100
  # non-specific failure occurred, TIMEOUT if a timeout occurred.
96
- def force_flush(timeout: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
101
+ def force_flush(timeout: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
97
102
  start_time = Time.now
98
103
  snapshot = lock do
99
- reset_on_fork(restart_thread: false) if @keep_running
104
+ reset_on_fork if @keep_running
100
105
  spans.shift(spans.size)
101
106
  end
102
107
  until snapshot.empty?
@@ -114,7 +119,10 @@ module OpenTelemetry
114
119
  # the snapshot because they're older than any spans in the spans buffer.
115
120
  lock do
116
121
  n = spans.size + snapshot.size - max_queue_size
117
- snapshot.shift(n) if n.positive?
122
+ if n.positive?
123
+ snapshot.shift(n)
124
+ report_dropped_spans(n, reason: 'buffer-full')
125
+ end
118
126
  spans.unshift(snapshot) unless snapshot.empty?
119
127
  @condition.signal if spans.size > max_queue_size / 2
120
128
  end
@@ -128,24 +136,26 @@ module OpenTelemetry
128
136
  # non-specific failure occurred, TIMEOUT if a timeout occurred.
129
137
  def shutdown(timeout: nil)
130
138
  start_time = Time.now
131
- lock do
139
+ thread = lock do
132
140
  @keep_running = false
133
141
  @condition.signal
142
+ @thread
134
143
  end
135
144
 
136
- @thread.join(timeout)
145
+ thread&.join(timeout)
137
146
  force_flush(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
138
147
  @exporter.shutdown(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
148
+ dropped_spans = lock { spans.size }
149
+ report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.positive?
139
150
  end
140
151
 
141
152
  private
142
153
 
143
154
  attr_reader :spans, :max_queue_size, :batch_size
144
155
 
145
- def work
156
+ def work # rubocop:disable Metrics/AbcSize
146
157
  loop do
147
158
  batch = lock do
148
- reset_on_fork(restart_thread: false)
149
159
  @condition.wait(@mutex, @delay_seconds) if spans.size < batch_size && @keep_running
150
160
  @condition.wait(@mutex, @delay_seconds) while spans.empty? && @keep_running
151
161
  return unless @keep_running
@@ -153,6 +163,8 @@ module OpenTelemetry
153
163
  fetch_batch
154
164
  end
155
165
 
166
+ @metrics_reporter.observe_value('otel.bsp.buffer_utilization', value: spans.size / max_queue_size.to_f)
167
+
156
168
  export_batch(batch)
157
169
  end
158
170
  end
@@ -163,7 +175,7 @@ module OpenTelemetry
163
175
 
164
176
  @pid = pid
165
177
  spans.clear
166
- @thread = Thread.new { work } if restart_thread
178
+ @thread = restart_thread ? Thread.new { work } : nil
167
179
  end
168
180
 
169
181
  def export_batch(batch, timeout: @exporter_timeout_seconds)
@@ -173,7 +185,18 @@ module OpenTelemetry
173
185
  end
174
186
 
175
187
  def report_result(result_code, batch)
176
- OpenTelemetry.logger.error("Unable to export #{batch.size} spans") unless result_code == SUCCESS
188
+ if result_code == SUCCESS
189
+ @metrics_reporter.add_to_counter('otel.bsp.export.success')
190
+ @metrics_reporter.add_to_counter('otel.bsp.exported_spans', increment: batch.size)
191
+ else
192
+ OpenTelemetry.handle_error(message: "Unable to export #{batch.size} spans")
193
+ @metrics_reporter.add_to_counter('otel.bsp.export.failure')
194
+ report_dropped_spans(batch.size, reason: 'export-failure')
195
+ end
196
+ end
197
+
198
+ def report_dropped_spans(count, reason:)
199
+ @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: count, labels: { 'reason' => reason })
177
200
  end
178
201
 
179
202
  def fetch_batch
@@ -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,59 @@
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
+ # MetricsReporter defines an interface used for reporting metrics from
12
+ # span processors (like the BatchSpanProcessor) and exporters. It can
13
+ # be used to report metrics such as dropped spans, and successful and
14
+ # failed export attempts. This exists to decouple the Trace SDK from
15
+ # the unstable OpenTelemetry Metrics API. An example implementation in
16
+ # terms of StatsD is:
17
+ #
18
+ # module MetricsReporter
19
+ # def add_to_counter(metric, increment: 1, labels: {})
20
+ # StatsD.increment(metric, increment, labels, no_prefix: true)
21
+ # end
22
+ # def record_value(metric, value:, labels: {})
23
+ # StatsD.distribution(metric, value, labels, no_prefix: true)
24
+ # end
25
+ # def observe_value(metric, value:, labels: {})
26
+ # StatsD.gauge(metric, value, labels, no_prefix: true)
27
+ # end
28
+ # end
29
+ module MetricsReporter
30
+ extend self
31
+
32
+ # Adds an increment to a metric with the provided labels.
33
+ #
34
+ # @param [String] metric The metric name.
35
+ # @param [optional Numeric] increment An optional increment to report.
36
+ # @param [optional Hash<String, String>] labels Optional labels to
37
+ # associate with the metric.
38
+ def add_to_counter(metric, increment: 1, labels: {}); end
39
+
40
+ # Records a value for a metric with the provided labels.
41
+ #
42
+ # @param [String] metric The metric name.
43
+ # @param [Numeric] value The value to report.
44
+ # @param [optional Hash<String, String>] labels Optional labels to
45
+ # associate with the metric.
46
+ def record_value(metric, value:, labels: {}); end
47
+
48
+ # Observes a value for a metric with the provided labels.
49
+ #
50
+ # @param [String] metric The metric name.
51
+ # @param [Numeric] value The value to observe.
52
+ # @param [optional Hash<String, String>] labels Optional labels to
53
+ # associate with the metric.
54
+ def observe_value(metric, value:, labels: {}); end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ 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,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
 
@@ -57,7 +57,7 @@ module OpenTelemetry
57
57
 
58
58
  @span_exporter&.export([span.to_span_data])
59
59
  rescue => e # rubocop:disable Style/RescueStandardError
60
- OpenTelemetry.logger.error("unexpected error in span.on_finish - #{e}")
60
+ OpenTelemetry.handle_error(exception: e, message: 'unexpected error in span.on_finish')
61
61
  end
62
62
 
63
63
  # Export all ended spans to the configured `Exporter` that have not yet
@@ -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
 
@@ -19,12 +19,20 @@ module OpenTelemetry
19
19
  @description = description
20
20
  end
21
21
 
22
+ def ==(other)
23
+ @decision == other.decision && @description == other.description
24
+ end
25
+
22
26
  # @api private
23
27
  #
24
28
  # See {Samplers}.
25
29
  def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
26
30
  Result.new(decision: @decision, tracestate: OpenTelemetry::Trace.current_span(parent_context).context.tracestate)
27
31
  end
32
+
33
+ protected
34
+
35
+ attr_reader :decision
28
36
  end
29
37
  end
30
38
  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
 
@@ -26,6 +26,14 @@ module OpenTelemetry
26
26
  @local_parent_not_sampled = local_parent_not_sampled
27
27
  end
28
28
 
29
+ def ==(other)
30
+ @root == other.root &&
31
+ @remote_parent_sampled == other.remote_parent_sampled &&
32
+ @remote_parent_not_sampled == other.remote_parent_not_sampled &&
33
+ @local_parent_sampled == other.local_parent_sampled &&
34
+ @local_parent_not_sampled == other.local_parent_not_sampled
35
+ end
36
+
29
37
  # @api private
30
38
  #
31
39
  # See {Samplers}.
@@ -47,6 +55,10 @@ module OpenTelemetry
47
55
  end
48
56
  delegate.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
49
57
  end
58
+
59
+ protected
60
+
61
+ attr_reader :root, :remote_parent_sampled, :remote_parent_not_sampled, :local_parent_sampled, :local_parent_not_sampled
50
62
  end
51
63
  end
52
64
  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,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
 
@@ -20,6 +20,10 @@ module OpenTelemetry
20
20
  @description = format('TraceIdRatioBased{%.6f}', probability)
21
21
  end
22
22
 
23
+ def ==(other)
24
+ @description == other.description
25
+ end
26
+
23
27
  # @api private
24
28
  #
25
29
  # See {Samplers}.
@@ -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
 
@@ -120,15 +120,20 @@ module OpenTelemetry
120
120
  # can be recorded on a span.
121
121
  #
122
122
  # @param [Exception] exception The exception to be recorded
123
+ # @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
124
+ # attributes One or more key:value pairs, where the keys must be
125
+ # strings and the values may be (array of) string, boolean or numeric
126
+ # type.
123
127
  #
124
128
  # @return [void]
125
- def record_exception(exception)
126
- add_event('exception',
127
- attributes: {
128
- 'exception.type' => exception.class.to_s,
129
- 'exception.message' => exception.message,
130
- 'exception.stacktrace' => exception.full_message(highlight: false, order: :top)
131
- })
129
+ def record_exception(exception, attributes: nil)
130
+ event_attributes = {
131
+ 'exception.type' => exception.class.to_s,
132
+ 'exception.message' => exception.message,
133
+ 'exception.stacktrace' => exception.full_message(highlight: false, order: :top)
134
+ }
135
+ event_attributes.merge!(attributes) unless attributes.nil?
136
+ add_event('exception', attributes: event_attributes)
132
137
  end
133
138
 
134
139
  # Sets the Status to the Span
@@ -199,7 +204,7 @@ module OpenTelemetry
199
204
  return self
200
205
  end
201
206
  @end_timestamp = end_timestamp || Time.now
202
- @attributes.freeze
207
+ @attributes = validated_attributes(@attributes).freeze
203
208
  @events.freeze
204
209
  @ended = true
205
210
  end
@@ -269,12 +274,16 @@ module OpenTelemetry
269
274
 
270
275
  private
271
276
 
277
+ def validated_attributes(attrs)
278
+ return attrs if Internal.valid_attributes?(attrs)
279
+
280
+ attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
281
+ end
282
+
272
283
  def trim_span_attributes(attrs)
273
284
  return if attrs.nil?
274
285
 
275
286
  excess = attrs.size - @trace_config.max_attributes_count
276
- # TODO: with Ruby 2.5, replace with the more efficient
277
- # attrs.shift(excess) if excess.positive?
278
287
  excess.times { attrs.shift } if excess.positive?
279
288
  nil
280
289
  end
@@ -301,11 +310,12 @@ module OpenTelemetry
301
310
  def append_event(events, event) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
302
311
  max_events_count = @trace_config.max_events_count
303
312
  max_attributes_per_event = @trace_config.max_attributes_per_event
313
+ valid_attributes = Internal.valid_attributes?(event.attributes)
304
314
 
305
315
  # Fast path (likely) common case.
306
316
  if events.size < max_events_count &&
307
317
  event.attributes.size <= max_attributes_per_event &&
308
- Internal.valid_attributes?(event.attributes)
318
+ valid_attributes
309
319
  return events << event
310
320
  end
311
321
 
@@ -314,7 +324,7 @@ module OpenTelemetry
314
324
  events.shift(excess) if excess.positive?
315
325
 
316
326
  excess = event.attributes.size - max_attributes_per_event
317
- if excess.positive? || !Internal.valid_attributes?(event.attributes)
327
+ if excess.positive? || !valid_attributes
318
328
  attrs = Hash[event.attributes] # event.attributes is frozen, so we need an unfrozen copy to adjust.
319
329
  attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
320
330
  excess = attrs.size - max_attributes_per_event
@@ -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 2020 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -42,7 +42,7 @@ module OpenTelemetry
42
42
  parent_span_id = parent_span_context.span_id
43
43
  trace_id = parent_span_context.trace_id
44
44
  end
45
- trace_id ||= OpenTelemetry::Trace.generate_trace_id
45
+ trace_id ||= tracer_provider.id_generator.generate_trace_id
46
46
  sampler = tracer_provider.active_trace_config.sampler
47
47
  result = sampler.should_sample?(trace_id: trace_id, parent_context: with_parent, links: links, name: name, kind: kind, attributes: attributes)
48
48
  internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, with_parent)
@@ -50,10 +50,11 @@ module OpenTelemetry
50
50
 
51
51
  private
52
52
 
53
- def internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, parent_context) # rubocop:disable Metrics/AbcSize
53
+ def internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, parent_context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
54
+ span_id = tracer_provider.id_generator.generate_span_id
54
55
  if result.recording? && !tracer_provider.stopped?
55
56
  trace_flags = result.sampled? ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT
56
- context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, trace_flags: trace_flags, tracestate: result.tracestate)
57
+ context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id, trace_flags: trace_flags, tracestate: result.tracestate)
57
58
  attributes = attributes&.merge(result.attributes) || result.attributes
58
59
  Span.new(
59
60
  context,
@@ -70,7 +71,7 @@ module OpenTelemetry
70
71
  @instrumentation_library
71
72
  )
72
73
  else
73
- OpenTelemetry::Trace::Span.new(span_context: OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id))
74
+ OpenTelemetry::Trace::Span.new(span_context: OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id, tracestate: result.tracestate))
74
75
  end
75
76
  end
76
77
  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
 
@@ -12,7 +12,7 @@ module OpenTelemetry
12
12
  Key = Struct.new(:name, :version)
13
13
  private_constant(:Key)
14
14
 
15
- attr_accessor :active_trace_config
15
+ attr_accessor :active_trace_config, :id_generator
16
16
  attr_reader :active_span_processor, :stopped, :resource
17
17
  alias stopped? stopped
18
18
 
@@ -24,6 +24,7 @@ module OpenTelemetry
24
24
  @registry = {}
25
25
  @active_span_processor = NoopSpanProcessor.instance
26
26
  @active_trace_config = Config::TraceConfig::DEFAULT
27
+ @id_generator = OpenTelemetry::Trace
27
28
  @registered_span_processors = []
28
29
  @stopped = false
29
30
  @resource = resource
@@ -1,12 +1,12 @@
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
  module SDK
9
9
  ## Current OpenTelemetry version
10
- VERSION = '0.10.0'
10
+ VERSION = '0.13.0'
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.13.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-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.0
19
+ version: 0.13.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.0
26
+ version: 0.13.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opentelemetry-common
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.0
33
+ version: 0.13.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.0
40
+ version: 0.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -180,6 +180,7 @@ files:
180
180
  - lib/opentelemetry/sdk/trace/export/batch_span_processor.rb
181
181
  - lib/opentelemetry/sdk/trace/export/console_span_exporter.rb
182
182
  - lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb
183
+ - lib/opentelemetry/sdk/trace/export/metrics_reporter.rb
183
184
  - lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb
184
185
  - lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb
185
186
  - lib/opentelemetry/sdk/trace/export/simple_span_processor.rb
@@ -200,10 +201,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
200
201
  licenses:
201
202
  - Apache-2.0
202
203
  metadata:
203
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.10.0/file.CHANGELOG.html
204
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/sdk
204
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.13.0/file.CHANGELOG.html
205
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/sdk
205
206
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
206
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.10.0
207
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.13.0
207
208
  post_install_message:
208
209
  rdoc_options: []
209
210
  require_paths: