opentelemetry-sdk 1.12.1 → 1.13.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 669386368dd472621a23b59729c2f3dc99922866a87b91d88ff244803e5a8eb9
4
- data.tar.gz: d7d0216e2c302e33bd021d44853b93f91b371d3a0b55049ce218cdba3ac76e95
3
+ metadata.gz: 96d1d6f8f41f39408208c7fa58c1ba8617bb9249106bf8391eeb266c2d38362e
4
+ data.tar.gz: 03b8f1119d65b37cbe3098407b46d0753adbbe52e634a328bfbd5565ab341a22
5
5
  SHA512:
6
- metadata.gz: e590e765a30272482a56cf3de76ae778fbc8218648ec4b8920ae274e39f2a7e57dc501ec13cbb1bbe8dce767306f6f1250538122f7745e133d4a89a7e8b17ed6
7
- data.tar.gz: 8a2d22ae1202b742a5284eddf4cc9e4cca16fd19f76abec30cef8a54cb9a242803bf1c2643a713656b1b370abd3884d74aa091dc04780ae614c3c81680749510
6
+ metadata.gz: b2feacbff16ce07fcbbbda0e040d08c1eb8db2fec25804d8d9a849ed4597c2e4f7f64c5c3700cad5d6fbdfcd30ca3f397e5d3341d5e318b2f6c9a74aef8dd94a
7
+ data.tar.gz: 007725376c74f995289bc476a34905fb0a37334ebb86b370ad5631621a8558ae25dde2e8e693b3d04bf64b45c8cce170215fb55b4381b8f56f698ff7b511867f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v1.13.1 / 2026-09-15
4
+
5
+ * DOCS: Document custom error handlers (#2264)
6
+
7
+ ### v1.13.0 / 2026-07-21
8
+
9
+ * ADDED: Add attributes support to instrumentation scope for tracers (#2094)
10
+
3
11
  ### v1.12.1 / 2026-07-08
4
12
 
5
13
  * DOCS: Update source for gemspec links to RubyDoc (#2123)
data/README.md CHANGED
@@ -97,5 +97,5 @@ The `opentelemetry-sdk` gem is distributed under the Apache 2.0 license. See [LI
97
97
  [license-github]: https://github.com/open-telemetry/opentelemetry-ruby/blob/main/LICENSE
98
98
  [examples-github]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/examples
99
99
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
100
- [community-meetings]: https://github.com/open-telemetry/community#community-meetings
100
+ [community-meetings]: https://github.com/open-telemetry/community/blob/main/README.md#calendar
101
101
  [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
@@ -14,12 +14,15 @@ module OpenTelemetry
14
14
  EMPTY_LIST = [].freeze
15
15
  private_constant(:EMPTY_LIST)
16
16
 
17
+ # No-op because this propagator does not inject any values.
17
18
  def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter); end
18
19
 
20
+ # Returns the passed context unchanged because there is nothing to extract.
19
21
  def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
20
22
  context
21
23
  end
22
24
 
25
+ # Returns an empty list because this propagator does not use carrier fields.
23
26
  def fields
24
27
  EMPTY_LIST
25
28
  end
@@ -31,7 +34,7 @@ module OpenTelemetry
31
34
 
32
35
  private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL
33
36
 
34
- attr_writer :propagators, :error_handler, :id_generator
37
+ attr_writer :propagators, :id_generator
35
38
 
36
39
  def initialize
37
40
  @instrumentation_names = []
@@ -43,6 +46,7 @@ module OpenTelemetry
43
46
  @id_generator = OpenTelemetry::Trace
44
47
  end
45
48
 
49
+ # Returns the configured logger or the global OpenTelemetry logger.
46
50
  def logger
47
51
  @logger ||= OpenTelemetry.logger
48
52
  end
@@ -56,6 +60,26 @@ module OpenTelemetry
56
60
  @logger = ForwardingLogger.new(new_logger, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
57
61
  end
58
62
 
63
+ # Configures the error handler that will be installed on
64
+ # OpenTelemetry during SDK configuration.
65
+ #
66
+ # Assigned object must respond to +#call+ and accept the keyword
67
+ # arguments +exception:+ and +message:+.
68
+ #
69
+ # @param [#call] error_handler The error handler to install
70
+ #
71
+ # @example Configure a custom error handler during SDK setup
72
+ # OpenTelemetry::SDK.configure do |c|
73
+ # c.error_handler = lambda do |exception: nil, message: nil|
74
+ # OpenTelemetry.logger.warn("otel: #{[message, exception&.message].compact.join(' - ')}")
75
+ # end
76
+ # end
77
+ # rubocop:disable-next Style/TrivialAccessors
78
+ def error_handler=(error_handler)
79
+ @error_handler = error_handler
80
+ end
81
+
82
+ # Returns the configured error handler or the global OpenTelemetry error handler.
59
83
  def error_handler
60
84
  @error_handler ||= OpenTelemetry.error_handler
61
85
  end
@@ -190,11 +214,11 @@ module OpenTelemetry
190
214
  when 'otlp'
191
215
  otlp_protocol = ENV['OTEL_EXPORTER_OTLP_TRACES_PROTOCOL'] || ENV['OTEL_EXPORTER_OTLP_PROTOCOL'] || 'http/protobuf'
192
216
 
193
- if otlp_protocol != 'http/protobuf'
217
+ if otlp_protocol == 'http/protobuf'
218
+ fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter')
219
+ else
194
220
  OpenTelemetry.logger.warn "The #{otlp_protocol} transport protocol is not supported by the OTLP exporter, spans will not be exported."
195
221
  nil
196
- else
197
- fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter')
198
222
  end
199
223
  when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter')
200
224
  when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter')
@@ -8,6 +8,7 @@ module OpenTelemetry
8
8
  module SDK
9
9
  # InstrumentationScope is a struct containing scope information for export.
10
10
  InstrumentationScope = Struct.new(:name,
11
- :version)
11
+ :version,
12
+ :attributes)
12
13
  end
13
14
  end
@@ -34,7 +34,7 @@ module OpenTelemetry
34
34
 
35
35
  case value.first
36
36
  when String
37
- value.all? { |v| v.instance_of?(String) }
37
+ value.all?(String)
38
38
  when TrueClass, FalseClass
39
39
  value.all? { |v| boolean?(v) }
40
40
  when Numeric
@@ -13,9 +13,9 @@ module OpenTelemetry
13
13
  class << self
14
14
  private :new
15
15
 
16
- # Returns a newly created {Resource} with the specified attributes
16
+ # Returns a newly created Resource with the specified attributes
17
17
  #
18
- # @param [Hash{String => String, Numeric, Boolean} attributes Hash of key-value pairs to be used
18
+ # @param [Hash{String => String, Numeric, Boolean}] attributes Hash of key-value pairs to be used
19
19
  # as attributes for this resource
20
20
  # @raise [ArgumentError] If attribute keys and values are not strings
21
21
  # @return [Resource]
@@ -30,10 +30,16 @@ module OpenTelemetry
30
30
  new(frozen_attributes)
31
31
  end
32
32
 
33
+ # Returns the default Resource for the current process and SDK.
34
+ #
35
+ # @return [Resource]
33
36
  def default
34
37
  @default ||= create(SemanticConventions::Resource::SERVICE_NAME => 'unknown_service').merge(process).merge(telemetry_sdk).merge(service_name_from_env)
35
38
  end
36
39
 
40
+ # Returns a Resource describing this telemetry SDK.
41
+ #
42
+ # @return [Resource]
37
43
  def telemetry_sdk
38
44
  resource_attributes = {
39
45
  SemanticConventions::Resource::TELEMETRY_SDK_NAME => 'opentelemetry',
@@ -53,6 +59,9 @@ module OpenTelemetry
53
59
  create(resource_attributes)
54
60
  end
55
61
 
62
+ # Returns a Resource describing the current process.
63
+ #
64
+ # @return [Resource]
56
65
  def process
57
66
  resource_attributes = {
58
67
  SemanticConventions::Resource::PROCESS_PID => Process.pid,
@@ -75,7 +84,7 @@ module OpenTelemetry
75
84
 
76
85
  # @api private
77
86
  # The constructor is private and only for use internally by the class.
78
- # Users should use the {create} factory method to obtain a {Resource}
87
+ # Users should use the {create} factory method to obtain a Resource
79
88
  # instance.
80
89
  #
81
90
  # @param [Hash<String, String>] frozen_attributes Frozen-hash of frozen-string
@@ -85,15 +94,15 @@ module OpenTelemetry
85
94
  @attributes = frozen_attributes
86
95
  end
87
96
 
88
- # Returns an enumerator for attributes of this {Resource}
97
+ # Returns an enumerator for attributes of this Resource
89
98
  #
90
99
  # @return [Enumerator]
91
100
  def attribute_enumerator
92
101
  @attribute_enumerator ||= attributes.to_enum
93
102
  end
94
103
 
95
- # Returns a new, merged {Resource} by merging the current {Resource} with
96
- # the other {Resource}. In case of a collision, the other {Resource}
104
+ # Returns a new, merged Resource by merging the current Resource with
105
+ # the other Resource. In case of a collision, the other Resource
97
106
  # takes precedence
98
107
  #
99
108
  # @param [Resource] other The other resource to merge
@@ -210,6 +210,7 @@ module OpenTelemetry
210
210
  end
211
211
 
212
212
  def lock
213
+ # rubocop:disable-next Style/ExplicitBlockArgument
213
214
  @mutex.synchronize do
214
215
  yield
215
216
  end
@@ -39,9 +39,8 @@ module OpenTelemetry
39
39
  private
40
40
 
41
41
  def sample?(trace_id)
42
- # rubocop:disable Lint/FloatComparison
42
+ # rubocop:disable-next Lint/FloatComparison
43
43
  @probability == 1.0 || trace_id[8, 8].unpack1('Q>') < @id_upper_bound
44
- # rubocop:enable Lint/FloatComparison
45
44
  end
46
45
  end
47
46
  end
@@ -14,7 +14,7 @@ module OpenTelemetry
14
14
  # Instrumentation should use the API provided by {OpenTelemetry::Trace::Span}
15
15
  # and should consider {Span} to be write-only.
16
16
  #
17
- # rubocop:disable Metrics/ClassLength
17
+ # rubocop:disable-next Metrics/ClassLength
18
18
  class Span < OpenTelemetry::Trace::Span
19
19
  DEFAULT_STATUS = OpenTelemetry::Trace::Status.unset
20
20
  EMPTY_ATTRIBUTES = {}.freeze
@@ -133,7 +133,7 @@ module OpenTelemetry
133
133
  # documents} certain "standard attributes" that have prescribed semantic
134
134
  # meanings.
135
135
  #
136
- # @param [OpenTelemetry::Trace::Link] the link object to add on the {Span}.
136
+ # @param [OpenTelemetry::Trace::Link] link The link object to add on the {Span}.
137
137
  #
138
138
  # @return [self] returns itself
139
139
  def add_link(link)
@@ -418,7 +418,7 @@ module OpenTelemetry
418
418
  excess_link_count = valid_links.size - link_count_limit
419
419
  valid_links.pop(excess_link_count) if excess_link_count.positive?
420
420
  valid_links.map! do |link|
421
- attrs = Hash[link.attributes] # link.attributes is frozen, so we need an unfrozen copy to adjust.
421
+ attrs = link.attributes.to_h.dup # link.attributes is frozen, so we need an unfrozen copy to adjust.
422
422
  attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
423
423
  excess = attrs.size - link_attribute_count_limit
424
424
  excess.times { attrs.shift } if excess.positive?
@@ -444,7 +444,7 @@ module OpenTelemetry
444
444
 
445
445
  excess = event.attributes.size - event_attribute_count_limit
446
446
  if excess.positive? || !valid_attributes
447
- attrs = Hash[event.attributes] # event.attributes is frozen, so we need an unfrozen copy to adjust.
447
+ attrs = event.attributes.to_h.dup # event.attributes is frozen, so we need an unfrozen copy to adjust.
448
448
  attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
449
449
  excess = attrs.size - event_attribute_count_limit
450
450
  excess.times { attrs.shift } if excess.positive?
@@ -475,7 +475,6 @@ module OpenTelemetry
475
475
  Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
476
476
  end
477
477
  end
478
- # rubocop:enable Metrics/ClassLength
479
478
  end
480
479
  end
481
480
  end
@@ -13,13 +13,15 @@ module OpenTelemetry
13
13
  #
14
14
  # Returns a new {Tracer} instance.
15
15
  #
16
- # @param [String] name Instrumentation package name
17
- # @param [String] version Instrumentation package version
16
+ # @param [String] name Instrumentation scope name
17
+ # @param [String] version Instrumentation scope version
18
18
  # @param [TracerProvider] tracer_provider TracerProvider that initialized the tracer
19
+ # @param [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}] attributes
20
+ # Instrumentation scope attributes
19
21
  #
20
22
  # @return [Tracer]
21
- def initialize(name, version, tracer_provider)
22
- @instrumentation_scope = InstrumentationScope.new(name, version)
23
+ def initialize(name, version, tracer_provider, attributes: nil)
24
+ @instrumentation_scope = InstrumentationScope.new(name, version, attributes || {}.freeze)
23
25
  @tracer_provider = tracer_provider
24
26
  end
25
27
 
@@ -9,8 +9,10 @@ module OpenTelemetry
9
9
  module Trace
10
10
  # {TracerProvider} is the SDK implementation of {OpenTelemetry::Trace::TracerProvider}.
11
11
  class TracerProvider < OpenTelemetry::Trace::TracerProvider # rubocop:disable Metrics/ClassLength
12
- Key = Struct.new(:name, :version)
13
- private_constant(:Key)
12
+ Key = Struct.new(:name, :version, :attributes)
13
+ EMPTY_ATTRIBUTES = {}.freeze
14
+
15
+ private_constant(:Key, :EMPTY_ATTRIBUTES)
14
16
 
15
17
  attr_accessor :span_limits, :id_generator, :sampler
16
18
  attr_reader :resource
@@ -44,15 +46,28 @@ module OpenTelemetry
44
46
 
45
47
  # Returns a {Tracer} instance.
46
48
  #
47
- # @param [optional String] name Instrumentation package name
48
- # @param [optional String] version Instrumentation package version
49
+ # Supports both positional arguments (legacy) and keyword arguments:
50
+ # tracer('name', '1.0') # legacy positional
51
+ # tracer(name: 'name', version: '1.0', attributes: {...}) # keyword
52
+ #
53
+ # When both positional and keyword arguments are provided for the same
54
+ # parameter, the keyword argument takes precedence.
55
+ #
56
+ # @param [String] name Instrumentation scope name
57
+ # @param [String] version Instrumentation scope version
58
+ # @param [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}] attributes
59
+ # Instrumentation scope attributes
49
60
  #
50
61
  # @return [Tracer]
51
- def tracer(name = nil, version = nil)
52
- name ||= ''
53
- version ||= ''
62
+ def tracer(deprecated_name = nil, deprecated_version = nil, name: nil, version: nil, attributes: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
63
+ name ||= deprecated_name || ''
64
+ version ||= deprecated_version || ''
65
+ attributes = attributes&.dup&.freeze || EMPTY_ATTRIBUTES
54
66
  OpenTelemetry.logger.warn 'calling TracerProvider#tracer without providing a tracer name.' if name.empty?
55
- @registry_mutex.synchronize { @registry[Key.new(name, version)] ||= Tracer.new(name, version, self) }
67
+ @registry_mutex.synchronize do
68
+ @registry[Key.new(name, version, attributes)] ||=
69
+ Tracer.new(name, version, self, attributes: attributes)
70
+ end
56
71
  end
57
72
 
58
73
  # Attempts to stop all the activity for this {TracerProvider}. Calls
@@ -7,6 +7,6 @@
7
7
  module OpenTelemetry
8
8
  module SDK
9
9
  ## Current OpenTelemetry version
10
- VERSION = '1.12.1'
10
+ VERSION = '1.13.1'
11
11
  end
12
12
  end
@@ -23,7 +23,7 @@ module OpenTelemetry
23
23
  # ConfigurationError is an exception type used to wrap configuration errors
24
24
  # passed to OpenTelemetry.error_handler. This can be used to distinguish
25
25
  # errors reported during SDK configuration.
26
- ConfigurationError = Class.new(OpenTelemetry::Error)
26
+ ConfigurationError = Class.new(OpenTelemetry::Error) # rubocop:disable Style/EmptyClassDefinition
27
27
 
28
28
  # Configures SDK and instrumentation
29
29
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.1
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
@@ -125,10 +125,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
125
125
  licenses:
126
126
  - Apache-2.0
127
127
  metadata:
128
- changelog_uri: https://rubydoc.info/gems/opentelemetry-sdk/1.12.1/file/CHANGELOG.md
129
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-sdk/v1.12.1/sdk
128
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-sdk/1.13.1/file/CHANGELOG.md
129
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-sdk/v1.13.1/sdk
130
130
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
131
- documentation_uri: https://rubydoc.info/gems/opentelemetry-sdk/1.12.1
131
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-sdk/1.13.1
132
132
  rdoc_options: []
133
133
  require_paths:
134
134
  - lib
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 4.0.10
146
+ rubygems_version: 4.0.16
147
147
  specification_version: 4
148
148
  summary: A stats collection and distributed tracing framework
149
149
  test_files: []