From e414458a6904804ffe36d6337f75071a044c3f40 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 13:27:53 +1000 Subject: [PATCH 1/5] enable all lint cops --- api/.rubocop.yml | 2 -- common/.rubocop.yml | 2 -- exporter/otlp-http/.rubocop.yml | 4 ---- exporter/otlp-logs/.rubocop.yml | 4 ---- exporter/otlp-metrics/.rubocop.yml | 4 ---- exporter/otlp/.rubocop.yml | 4 ---- exporter/zipkin/.rubocop.yml | 4 ---- logs_api/.rubocop.yml | 2 -- metrics_sdk/.rubocop.yml | 6 ------ propagator/jaeger/.rubocop_todo.yml | 5 ----- sdk/.rubocop.yml | 4 ---- sdk/.rubocop_todo.yml | 5 ----- sdk_experimental/.rubocop.yml | 4 ---- 13 files changed, 50 deletions(-) diff --git a/api/.rubocop.yml b/api/.rubocop.yml index c1ecf94c7..3a88726ef 100644 --- a/api/.rubocop.yml +++ b/api/.rubocop.yml @@ -4,8 +4,6 @@ Gemspec/DevelopmentDependencies: Enabled: false Style/ExplicitBlockArgument: Enabled: false -Lint/AmbiguousOperatorPrecedence: - Enabled: false Minitest/AssertPredicate: Enabled: false Minitest/RefutePredicate: diff --git a/common/.rubocop.yml b/common/.rubocop.yml index 25da94a3a..3b31480cf 100644 --- a/common/.rubocop.yml +++ b/common/.rubocop.yml @@ -2,8 +2,6 @@ inherit_from: ../contrib/rubocop.yml Style/ExplicitBlockArgument: Enabled: false -Lint/AmbiguousRange: - Enabled: false Minitest/AssertPredicate: Enabled: false Minitest/RefutePredicate: diff --git a/exporter/otlp-http/.rubocop.yml b/exporter/otlp-http/.rubocop.yml index 852c87033..279866ac0 100644 --- a/exporter/otlp-http/.rubocop.yml +++ b/exporter/otlp-http/.rubocop.yml @@ -9,10 +9,6 @@ Metrics/CyclomaticComplexity: Enabled: false Metrics/PerceivedComplexity: Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/SuppressedExceptionInNumberConversion: - Enabled: false Performance/MapCompact: Enabled: false Performance/MethodObjectAsBlock: diff --git a/exporter/otlp-logs/.rubocop.yml b/exporter/otlp-logs/.rubocop.yml index 9be779e65..6bc45bdf1 100644 --- a/exporter/otlp-logs/.rubocop.yml +++ b/exporter/otlp-logs/.rubocop.yml @@ -6,10 +6,6 @@ AllCops: - "lib/opentelemetry/proto/**/*" - "vendor/**/*" -Lint/DuplicateBranch: - Enabled: false -Lint/SuppressedExceptionInNumberConversion: - Enabled: false Performance/MapCompact: Enabled: false Performance/MethodObjectAsBlock: diff --git a/exporter/otlp-metrics/.rubocop.yml b/exporter/otlp-metrics/.rubocop.yml index da47afdef..a7fc4da77 100644 --- a/exporter/otlp-metrics/.rubocop.yml +++ b/exporter/otlp-metrics/.rubocop.yml @@ -13,10 +13,6 @@ Metrics/MethodLength: Enabled: false Metrics/ClassLength: Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/SuppressedExceptionInNumberConversion: - Enabled: false Performance/MapCompact: Enabled: false Performance/MethodObjectAsBlock: diff --git a/exporter/otlp/.rubocop.yml b/exporter/otlp/.rubocop.yml index 6bda33fa6..b727aae8f 100644 --- a/exporter/otlp/.rubocop.yml +++ b/exporter/otlp/.rubocop.yml @@ -5,10 +5,6 @@ AllCops: - "lib/opentelemetry/proto/**/*" - "vendor/**/*" -Lint/DuplicateBranch: - Enabled: false -Lint/SuppressedExceptionInNumberConversion: - Enabled: false Performance/MapCompact: Enabled: false Performance/MethodObjectAsBlock: diff --git a/exporter/zipkin/.rubocop.yml b/exporter/zipkin/.rubocop.yml index 586eb0141..8664afcb6 100644 --- a/exporter/zipkin/.rubocop.yml +++ b/exporter/zipkin/.rubocop.yml @@ -17,9 +17,5 @@ Metrics/CyclomaticComplexity: Enabled: false Style/ExplicitBlockArgument: Enabled: false -Lint/AmbiguousOperatorPrecedence: - Enabled: false -Lint/SuppressedExceptionInNumberConversion: - Enabled: false Minitest/SkipEnsure: Enabled: false diff --git a/logs_api/.rubocop.yml b/logs_api/.rubocop.yml index 543da68f8..993d05dc2 100644 --- a/logs_api/.rubocop.yml +++ b/logs_api/.rubocop.yml @@ -7,7 +7,5 @@ Metrics/PerceivedComplexity: Metrics/CyclomaticComplexity: Max: 20 -Lint/EmptyClass: - Enabled: false Style/ReduceToHash: Enabled: false diff --git a/metrics_sdk/.rubocop.yml b/metrics_sdk/.rubocop.yml index cb3ec2d26..238a9cae4 100644 --- a/metrics_sdk/.rubocop.yml +++ b/metrics_sdk/.rubocop.yml @@ -8,10 +8,6 @@ Metrics/PerceivedComplexity: Max: 30 Metrics/CyclomaticComplexity: Max: 20 -Lint/AmbiguousOperatorPrecedence: - Enabled: false -Lint/AmbiguousRange: - Enabled: false Naming/BlockForwarding: Enabled: false Naming/PredicateMethod: @@ -32,5 +28,3 @@ Style/NilLambda: Enabled: false Style/SuperArguments: Enabled: false -Lint/SymbolConversion: - Enabled: false diff --git a/propagator/jaeger/.rubocop_todo.yml b/propagator/jaeger/.rubocop_todo.yml index 51b68e3b3..fb9e666b6 100644 --- a/propagator/jaeger/.rubocop_todo.yml +++ b/propagator/jaeger/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/MixedRegexpCaptureTypes: - Exclude: - - 'lib/opentelemetry/propagator/jaeger/text_map_propagator.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/SlicingWithRange: diff --git a/sdk/.rubocop.yml b/sdk/.rubocop.yml index 71de374ed..f5136316b 100644 --- a/sdk/.rubocop.yml +++ b/sdk/.rubocop.yml @@ -4,10 +4,6 @@ inherit_from: Style/ExplicitBlockArgument: Enabled: false -Lint/AmbiguousOperatorPrecedence: - Enabled: false -Lint/EmptyClass: - Enabled: false Minitest/UselessAssertion: Enabled: false Naming/BlockForwarding: diff --git a/sdk/.rubocop_todo.yml b/sdk/.rubocop_todo.yml index c587c5557..147aa1abe 100644 --- a/sdk/.rubocop_todo.yml +++ b/sdk/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/FloatComparison: - Exclude: - - 'lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb' - # Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: diff --git a/sdk_experimental/.rubocop.yml b/sdk_experimental/.rubocop.yml index b7134a71b..32c54cac5 100644 --- a/sdk_experimental/.rubocop.yml +++ b/sdk_experimental/.rubocop.yml @@ -11,10 +11,6 @@ Metrics/CyclomaticComplexity: Naming/MethodParameterName: Enabled: false -Lint/AmbiguousOperatorPrecedence: - Enabled: false -Lint/DuplicateBranch: - Enabled: false Naming/PredicateMethod: Enabled: false Style/NegatedIfElseCondition: From 7a59919b19d03562f47a3bb10fa407f01993cf28 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 15:05:17 +1000 Subject: [PATCH 2/5] Address violations --- .../trace_context/text_map_propagator_test.rb | 8 ++++---- common/lib/opentelemetry/common/utilities.rb | 2 +- .../opentelemetry/exporter/otlp/http/trace_exporter.rb | 10 +++------- .../opentelemetry/exporter/otlp/logs/logs_exporter.rb | 8 ++------ .../lib/opentelemetry/exporter/otlp/metrics/util.rb | 6 +----- .../otlp/lib/opentelemetry/exporter/otlp/exporter.rb | 10 +++------- .../lib/opentelemetry/exporter/zipkin/exporter.rb | 6 +----- .../lib/opentelemetry/exporter/zipkin/transformer.rb | 2 +- logs_api/.rubocop.yml | 3 +++ .../exponential_bucket_histogram_test.rb | 8 ++++---- .../exponential_histogram/logarithm_mapping_test.rb | 2 +- .../sdk/metrics/exemplar/exemplar_filter_test.rb | 2 +- .../propagator/jaeger/text_map_propagator.rb | 2 +- sdk/.rubocop.yml | 3 +++ .../sdk/trace/samplers/trace_id_ratio_based.rb | 2 +- sdk/test/opentelemetry/sdk/trace/samplers_test.rb | 2 +- .../samplers/consistent_probability_based_test.rb | 2 +- 17 files changed, 32 insertions(+), 46 deletions(-) diff --git a/api/test/opentelemetry/trace/propagation/trace_context/text_map_propagator_test.rb b/api/test/opentelemetry/trace/propagation/trace_context/text_map_propagator_test.rb index f3151d40d..da113239b 100644 --- a/api/test/opentelemetry/trace/propagation/trace_context/text_map_propagator_test.rb +++ b/api/test/opentelemetry/trace/propagation/trace_context/text_map_propagator_test.rb @@ -47,8 +47,8 @@ ctx = propagator.extract(carrier, context: context) { |c, k| c[k] } span_context = OpenTelemetry::Trace.current_span(ctx).context _(span_context).must_be :remote? - _(span_context.trace_id).must_equal(("\0" * 15 + "\xaa").b) - _(span_context.span_id).must_equal(("\0" * 7 + "\xea").b) + _(span_context.trace_id).must_equal((("\0" * 15) + "\xaa").b) + _(span_context.span_id).must_equal((("\0" * 7) + "\xea").b) _(span_context.trace_flags).must_be :sampled? _(span_context.tracestate).must_equal(tracestate) end @@ -57,8 +57,8 @@ ctx = propagator.extract(carrier, context: context) span_context = OpenTelemetry::Trace.current_span(ctx).context _(span_context).must_be :remote? - _(span_context.trace_id).must_equal(("\0" * 15 + "\xaa").b) - _(span_context.span_id).must_equal(("\0" * 7 + "\xea").b) + _(span_context.trace_id).must_equal((("\0" * 15) + "\xaa").b) + _(span_context.span_id).must_equal((("\0" * 7) + "\xea").b) _(span_context.trace_flags).must_be :sampled? _(span_context.tracestate).must_equal(tracestate) end diff --git a/common/lib/opentelemetry/common/utilities.rb b/common/lib/opentelemetry/common/utilities.rb index af8759a41..56dd2136d 100644 --- a/common/lib/opentelemetry/common/utilities.rb +++ b/common/lib/opentelemetry/common/utilities.rb @@ -82,7 +82,7 @@ def utf8_encode(string, binary: false, placeholder: STRING_PLACEHOLDER) # # @return [String] def truncate(string, size) - string.size > size ? "#{string[0...size - 3]}..." : string + string.size > size ? "#{string[0...(size - 3)]}..." : string end def truncate_attribute_value(value, limit) diff --git a/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb b/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb index 8876f0c4e..37f660bee 100644 --- a/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb +++ b/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb @@ -86,7 +86,7 @@ def shutdown(timeout: nil) private - def fetch_ssl_verify_mode + def fetch_ssl_verify_mode # rubocop:disable Lint/DuplicateBranch if ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER') OpenSSL::SSL::VERIFY_PEER elsif ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE') @@ -94,7 +94,7 @@ def fetch_ssl_verify_mode else OpenSSL::SSL::VERIFY_PEER end - end + end # rubocop:enable Lint/DuplicateBranch def http_connection(uri, ssl_verify_mode, certificate_file, client_certificate_file, client_key_file) http = Net::HTTP.new(uri.hostname, uri.port) @@ -227,11 +227,7 @@ def backoff?(retry_count:, reason:, retry_after: nil) sleep_interval = nil unless retry_after.nil? sleep_interval = - begin - Integer(retry_after) - rescue ArgumentError - nil - end + Integer(retry_after, exception: false) sleep_interval ||= begin Time.httpdate(retry_after) - Time.now diff --git a/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb b/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb index f8c177150..3f4f48d8e 100644 --- a/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb +++ b/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb @@ -137,7 +137,7 @@ def around_request OpenTelemetry::Common::Utilities.untraced { yield } # rubocop:disable Style/ExplicitBlockArgument end - def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity + def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Lint/DuplicateBranch return FAILURE if bytes.nil? request = Net::HTTP::Post.new(@path) @@ -251,11 +251,7 @@ def backoff?(retry_count:, retry_after: nil) # rubocop:disable Metrics/Cyclomati sleep_interval = nil unless retry_after.nil? sleep_interval = - begin - Integer(retry_after) - rescue ArgumentError - nil - end + Integer(retry_after, exception: false) sleep_interval ||= begin Time.httpdate(retry_after) - Time.now diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb index efcbc6ff8..2c262619b 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb @@ -95,11 +95,7 @@ def backoff?(retry_count:, reason:, retry_after: nil) sleep_interval = nil unless retry_after.nil? sleep_interval = - begin - Integer(retry_after) - rescue ArgumentError - nil - end + Integer(retry_after, exception: false) sleep_interval ||= begin Time.httpdate(retry_after) - Time.now diff --git a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb index 30655f901..44d6f5fd4 100644 --- a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb +++ b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb @@ -35,7 +35,7 @@ class Exporter # rubocop:disable Metrics/ClassLength DEFAULT_USER_AGENT = "OTel-OTLP-Exporter-Ruby/#{OpenTelemetry::Exporter::OTLP::VERSION} Ruby/#{RUBY_VERSION} (#{RUBY_PLATFORM}; #{RUBY_ENGINE}/#{RUBY_ENGINE_VERSION})".freeze - def self.ssl_verify_mode + def self.ssl_verify_mode # rubocop:disable Lint/DuplicateBranch if ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER') OpenSSL::SSL::VERIFY_PEER elsif ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE') @@ -43,7 +43,7 @@ def self.ssl_verify_mode else OpenSSL::SSL::VERIFY_PEER end - end + end # rubocop:enable Lint/DuplicateBranch def initialize(endpoint: nil, certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), @@ -275,11 +275,7 @@ def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/ sleep_interval = nil unless retry_after.nil? sleep_interval = - begin - Integer(retry_after) - rescue ArgumentError - nil - end + Integer(retry_after, exception: false) sleep_interval ||= begin Time.httpdate(retry_after) - Time.now diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb index f032bb797..8d33724fc 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb @@ -181,11 +181,7 @@ def backoff?(retry_count:, reason:, retry_after: nil) sleep_interval = nil unless retry_after.nil? sleep_interval = - begin - Integer(retry_after) - rescue ArgumentError - nil - end + Integer(retry_after, exception: false) sleep_interval ||= begin Time.httpdate(retry_after) - Time.now diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb index 0a5319942..5dac8033c 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb @@ -39,7 +39,7 @@ module Transformer def to_zipkin_span(span_d, resource) start_time = span_d.start_timestamp / 1_000 - duration = span_d.end_timestamp / 1_000 - start_time + duration = (span_d.end_timestamp / 1_000) - start_time tags = {} service_name = DEFAULT_SERVICE_NAME resource.attribute_enumerator.select do |key, value| diff --git a/logs_api/.rubocop.yml b/logs_api/.rubocop.yml index 993d05dc2..58ff30b93 100644 --- a/logs_api/.rubocop.yml +++ b/logs_api/.rubocop.yml @@ -7,5 +7,8 @@ Metrics/PerceivedComplexity: Metrics/CyclomaticComplexity: Max: 20 +Lint/EmptyClass: + Exclude: + - 'lib/opentelemetry/logs/log_record.rb' Style/ReduceToHash: Enabled: false diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb index b99ea5d80..2dfe8f35b 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb @@ -407,7 +407,7 @@ def expect_balanced(hdp, count) expbh.update(2**100, {}, data_points) hdp = data_points[{}] - expected_sum = 2**100 + 2**-100 + expected_sum = 2**100 + 2**(-100) _(hdp.sum).must_be_within_epsilon(expected_sum, 1e-5) _(hdp.count).must_equal(2) _(hdp.scale).must_equal(-7) @@ -994,9 +994,9 @@ def skip_on_windows metric_data = metrics_data[0] _(metric_data.start_time_unix_nano).must_equal(start_time_unix_nano) - _(metric_data.min).must_equal(TEST_VALUES[0..index + 1].min) - _(metric_data.max).must_equal(TEST_VALUES[0..index + 1].max) - _(metric_data.sum).must_be_within_epsilon(TEST_VALUES[0..index + 1].sum, 1e-10) + _(metric_data.min).must_equal(TEST_VALUES[0..(index + 1)].min) + _(metric_data.max).must_equal(TEST_VALUES[0..(index + 1)].max) + _(metric_data.sum).must_be_within_epsilon(TEST_VALUES[0..(index + 1)].sum, 1e-10) end expected_bucket_counts = [ diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb index ebf118ff4..baf301122 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb @@ -109,7 +109,7 @@ _(logarithm_mapping.map_to_index(MIN_NORMAL_VALUE / 100)).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1050)).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1073)).must_equal(correct_min_index) - _(logarithm_mapping.map_to_index(1.1 * 2**-1073)).must_equal(correct_min_index) + _(logarithm_mapping.map_to_index(1.1 * 2**(-1073))).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1074)).must_equal(correct_min_index) mapped_lower = logarithm_mapping.get_lower_boundary(min_index) diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/exemplar/exemplar_filter_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/exemplar/exemplar_filter_test.rb index 09048174b..4a0bf34d2 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/exemplar/exemplar_filter_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/exemplar/exemplar_filter_test.rb @@ -19,7 +19,7 @@ ) end let(:timestamp) { 123_456_789 } - let(:attributes) { { 'test': 'test' } } + let(:attributes) { { test: 'test' } } it 'always true for always on exemplar filter' do result = OpenTelemetry::SDK::Metrics::Exemplar::AlwaysOnExemplarFilter.should_sample?(1, timestamp, attributes, context) diff --git a/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb b/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb index a366be000..1d93bc5fd 100644 --- a/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb +++ b/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb @@ -24,7 +24,7 @@ class TextMapPropagator SAMPLED_FLAG_BIT = 0x01 DEBUG_FLAG_BIT = 0x02 FIELDS = [IDENTITY_KEY].freeze - TRACE_SPAN_IDENTITY_REGEX = /\A(?(?:[0-9a-f]){1,32}):(?([0-9a-f]){1,16}):[0-9a-f]{1,16}:(?[0-9a-f]{1,2})\z/ + TRACE_SPAN_IDENTITY_REGEX = /\A(?(?:[0-9a-f]){1,32}):(?([0-9a-f]){1,16}):(?:[0-9a-f]){1,16}:(?[0-9a-f]{1,2})\z/ ZERO_ID_REGEX = /^0+$/ private_constant \ diff --git a/sdk/.rubocop.yml b/sdk/.rubocop.yml index f5136316b..a0d645552 100644 --- a/sdk/.rubocop.yml +++ b/sdk/.rubocop.yml @@ -4,6 +4,9 @@ inherit_from: Style/ExplicitBlockArgument: Enabled: false +Lint/EmptyClass: + Exclude: + - 'test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb' Minitest/UselessAssertion: Enabled: false Naming/BlockForwarding: diff --git a/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb b/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb index 841d76a32..272cb0e03 100644 --- a/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +++ b/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb @@ -16,7 +16,7 @@ class TraceIdRatioBased def initialize(probability) @probability = probability - @id_upper_bound = (probability * (2**64 - 1)).ceil + @id_upper_bound = (probability * ((2**64) - 1)).ceil @description = format('TraceIdRatioBased{%.6f}', probability) end diff --git a/sdk/test/opentelemetry/sdk/trace/samplers_test.rb b/sdk/test/opentelemetry/sdk/trace/samplers_test.rb index 769aad311..340595ead 100644 --- a/sdk/test/opentelemetry/sdk/trace/samplers_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/samplers_test.rb @@ -173,7 +173,7 @@ end it 'samples the smallest ratio larger than the smallest trace_id' do - ratio = 2.0 / (2**64 - 1) + ratio = 2.0 / ((2**64) - 1) sampler = Samplers.trace_id_ratio_based(ratio) result = call_sampler(sampler, trace_id: trace_id(1)) _(result).must_be :sampled? diff --git a/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb b/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb index baec6b261..b24b85e33 100644 --- a/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb +++ b/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb @@ -117,7 +117,7 @@ p_ceil = sampler.instance_variable_get(:@p_ceil) # Verify that the sampling probability encoded in each `p` adds up to the probability # in the the initializer argument - _((2**-p_ceil * ceil_prob) + (2**-p_floor * floor_prob)).must_be_within_epsilon(0.1) + _((2**(-p_ceil) * ceil_prob) + (2**(-p_floor) * floor_prob)).must_be_within_epsilon(0.1) end end end From 6f85b5cd09ec5789ca6214d885b364b2f17bfb17 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 16:18:06 +1000 Subject: [PATCH 3/5] stage 2 of fixes --- .../lib/opentelemetry/exporter/otlp/http/trace_exporter.rb | 6 ++++-- .../lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb | 5 ++++- .../opentelemetry/exporter/otlp/metrics/metrics_exporter.rb | 4 ++-- .../lib/opentelemetry/exporter/otlp/metrics/util.rb | 2 +- exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb | 6 ++++-- .../exponential_bucket_histogram_test.rb | 2 +- .../exponential_histogram/logarithm_mapping_test.rb | 2 +- .../opentelemetry/propagator/jaeger/text_map_propagator.rb | 2 +- .../sdk/trace/samplers/trace_id_ratio_based.rb | 2 ++ 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb b/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb index 37f660bee..8b4f3b3f5 100644 --- a/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb +++ b/exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb @@ -86,7 +86,8 @@ def shutdown(timeout: nil) private - def fetch_ssl_verify_mode # rubocop:disable Lint/DuplicateBranch + # rubocop:disable Lint/DuplicateBranch + def fetch_ssl_verify_mode if ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER') OpenSSL::SSL::VERIFY_PEER elsif ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE') @@ -94,7 +95,8 @@ def fetch_ssl_verify_mode # rubocop:disable Lint/DuplicateBranch else OpenSSL::SSL::VERIFY_PEER end - end # rubocop:enable Lint/DuplicateBranch + end + # rubocop:enable Lint/DuplicateBranch def http_connection(uri, ssl_verify_mode, certificate_file, client_certificate_file, client_key_file) http = Net::HTTP.new(uri.hostname, uri.port) diff --git a/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb b/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb index 3f4f48d8e..865809773 100644 --- a/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb +++ b/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb @@ -137,7 +137,7 @@ def around_request OpenTelemetry::Common::Utilities.untraced { yield } # rubocop:disable Style/ExplicitBlockArgument end - def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Lint/DuplicateBranch + def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity return FAILURE if bytes.nil? request = Net::HTTP::Post.new(@path) @@ -156,6 +156,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, timeout ||= @timeout start_time = OpenTelemetry::Common::Utilities.timeout_timestamp + # rubocop:disable Lint/DuplicateBranch around_request do remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time) return FAILURE if remaining_timeout.zero? @@ -195,6 +196,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, handle_http_error(response) FAILURE end + rescue Net::OpenTimeout, Net::ReadTimeout => e OpenTelemetry.handle_error(exception: e) retry if backoff?(retry_count: retry_count += 1) @@ -223,6 +225,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Exporter#send_bytes') return FAILURE end + # rubocop:enable Lint/DuplicateBranch ensure # Reset timeouts to defaults for the next call. @http.open_timeout = @timeout diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb index 512f916b9..595a777d5 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb @@ -35,7 +35,7 @@ class MetricsExporter < ::OpenTelemetry::SDK::Metrics::Export::MetricReader FAILURE = OpenTelemetry::SDK::Metrics::Export::FAILURE private_constant(:SUCCESS, :FAILURE) - def self.ssl_verify_mode + def self.ssl_verify_mode # rubocop:disable Lint/DuplicateBranch if ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER') OpenSSL::SSL::VERIFY_PEER elsif ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE') @@ -43,7 +43,7 @@ def self.ssl_verify_mode else OpenSSL::SSL::VERIFY_PEER end - end + end # rubocop:enable Lint/DuplicateBranch def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/metrics'), certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb index 2c262619b..122c04b91 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/util.rb @@ -9,7 +9,7 @@ module Exporter module OTLP module Metrics # Util module provide essential functionality for exporter - module Util # rubocop:disable Metrics/ModuleLength + module Util KEEP_ALIVE_TIMEOUT = 30 RETRY_COUNT = 5 ERROR_MESSAGE_INVALID_HEADERS = 'headers must be a String with comma-separated URL Encoded UTF-8 k=v pairs or a Hash' diff --git a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb index 44d6f5fd4..9e84ced97 100644 --- a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb +++ b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb @@ -35,7 +35,8 @@ class Exporter # rubocop:disable Metrics/ClassLength DEFAULT_USER_AGENT = "OTel-OTLP-Exporter-Ruby/#{OpenTelemetry::Exporter::OTLP::VERSION} Ruby/#{RUBY_VERSION} (#{RUBY_PLATFORM}; #{RUBY_ENGINE}/#{RUBY_ENGINE_VERSION})".freeze - def self.ssl_verify_mode # rubocop:disable Lint/DuplicateBranch + # rubocop:disable Lint/DuplicateBranch + def self.ssl_verify_mode if ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER') OpenSSL::SSL::VERIFY_PEER elsif ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE') @@ -43,7 +44,8 @@ def self.ssl_verify_mode # rubocop:disable Lint/DuplicateBranch else OpenSSL::SSL::VERIFY_PEER end - end # rubocop:enable Lint/DuplicateBranch + end + # rubocop:enable Lint/DuplicateBranch def initialize(endpoint: nil, certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb index 2dfe8f35b..a7d90a68e 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb @@ -407,7 +407,7 @@ def expect_balanced(hdp, count) expbh.update(2**100, {}, data_points) hdp = data_points[{}] - expected_sum = 2**100 + 2**(-100) + expected_sum = (2**100) + (2**(-100)) _(hdp.sum).must_be_within_epsilon(expected_sum, 1e-5) _(hdp.count).must_equal(2) _(hdp.scale).must_equal(-7) diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb index baf301122..f45db2638 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb @@ -109,7 +109,7 @@ _(logarithm_mapping.map_to_index(MIN_NORMAL_VALUE / 100)).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1050)).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1073)).must_equal(correct_min_index) - _(logarithm_mapping.map_to_index(1.1 * 2**(-1073))).must_equal(correct_min_index) + _(logarithm_mapping.map_to_index(1.1 * (2**(-1073)))).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1074)).must_equal(correct_min_index) mapped_lower = logarithm_mapping.get_lower_boundary(min_index) diff --git a/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb b/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb index 1d93bc5fd..51357104b 100644 --- a/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb +++ b/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb @@ -24,7 +24,7 @@ class TextMapPropagator SAMPLED_FLAG_BIT = 0x01 DEBUG_FLAG_BIT = 0x02 FIELDS = [IDENTITY_KEY].freeze - TRACE_SPAN_IDENTITY_REGEX = /\A(?(?:[0-9a-f]){1,32}):(?([0-9a-f]){1,16}):(?:[0-9a-f]){1,16}:(?[0-9a-f]{1,2})\z/ + TRACE_SPAN_IDENTITY_REGEX = /\A(?(?:[0-9a-f]){1,32}):(?(?:[0-9a-f]){1,16}):(?:[0-9a-f]){1,16}:(?[0-9a-f]{1,2})\z/ ZERO_ID_REGEX = /^0+$/ private_constant \ diff --git a/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb b/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb index 272cb0e03..55cfb348c 100644 --- a/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +++ b/sdk/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb @@ -39,7 +39,9 @@ def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes: private def sample?(trace_id) + # rubocop:disable Lint/FloatComparison @probability == 1.0 || trace_id[8, 8].unpack1('Q>') < @id_upper_bound + # rubocop:enable Lint/FloatComparison end end end From ab565664a9e6437021c4f4d1f89e8f43571dd9dd Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 16:38:11 +1000 Subject: [PATCH 4/5] stage 3 fixes --- .../lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb | 7 ++++--- .../exporter/otlp/metrics/metrics_exporter.rb | 6 ++++-- exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb | 4 ++-- .../exemplar/simple_fixed_size_exemplar_reservoir.rb | 2 +- .../exponential_bucket_histogram_test.rb | 2 +- .../exponential_histogram/logarithm_mapping_test.rb | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb b/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb index 865809773..a0cda9411 100644 --- a/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb +++ b/exporter/otlp-logs/lib/opentelemetry/exporter/otlp/logs/logs_exporter.rb @@ -38,6 +38,7 @@ class LogsExporter # rubocop:disable Metrics/ClassLength DEFAULT_USER_AGENT = "OTel-OTLP-Exporter-Ruby/#{OpenTelemetry::Exporter::OTLP::Logs::VERSION} Ruby/#{RUBY_VERSION} (#{RUBY_PLATFORM}; #{RUBY_ENGINE}/#{RUBY_ENGINE_VERSION})".freeze + # rubocop:disable Lint/DuplicateBranch def self.ssl_verify_mode if ENV['OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER'] == 'true' OpenSSL::SSL::VERIFY_PEER @@ -47,6 +48,7 @@ def self.ssl_verify_mode OpenSSL::SSL::VERIFY_PEER end end + # rubocop:enable Lint/DuplicateBranch def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/logs'), certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), @@ -196,7 +198,6 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, handle_http_error(response) FAILURE end - rescue Net::OpenTimeout, Net::ReadTimeout => e OpenTelemetry.handle_error(exception: e) retry if backoff?(retry_count: retry_count += 1) @@ -225,7 +226,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Exporter#send_bytes') return FAILURE end - # rubocop:enable Lint/DuplicateBranch + # rubocop:enable Lint/DuplicateBranch ensure # Reset timeouts to defaults for the next call. @http.open_timeout = @timeout @@ -248,7 +249,7 @@ def log_status(body) OpenTelemetry.handle_error(exception: e, message: 'unexpected error decoding rpc.Status in OTLP::Exporter#log_status') end - def backoff?(retry_count:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + def backoff?(retry_count:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity return false if retry_count > RETRY_COUNT sleep_interval = nil diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb index 595a777d5..3b4d2e295 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb @@ -35,7 +35,8 @@ class MetricsExporter < ::OpenTelemetry::SDK::Metrics::Export::MetricReader FAILURE = OpenTelemetry::SDK::Metrics::Export::FAILURE private_constant(:SUCCESS, :FAILURE) - def self.ssl_verify_mode # rubocop:disable Lint/DuplicateBranch + # rubocop:disable Lint/DuplicateBranch + def self.ssl_verify_mode if ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_PEER') OpenSSL::SSL::VERIFY_PEER elsif ENV.key?('OTEL_RUBY_EXPORTER_OTLP_SSL_VERIFY_NONE') @@ -43,7 +44,8 @@ def self.ssl_verify_mode # rubocop:disable Lint/DuplicateBranch else OpenSSL::SSL::VERIFY_PEER end - end # rubocop:enable Lint/DuplicateBranch + end + # rubocop:enable Lint/DuplicateBranch def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/metrics'), certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), diff --git a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb index 9e84ced97..3e782ca01 100644 --- a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb +++ b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb @@ -44,7 +44,7 @@ def self.ssl_verify_mode else OpenSSL::SSL::VERIFY_PEER end - end + end # rubocop:enable Lint/DuplicateBranch def initialize(endpoint: nil, @@ -270,7 +270,7 @@ def measure_request_duration end end - def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => reason }) return false if retry_count > RETRY_COUNT diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb index 97ec2959c..a6c307196 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb @@ -50,7 +50,7 @@ def reset end def find_histogram_bucket - @num_measurements_seen < @max_size ? @num_measurements_seen : rand(0..@num_measurements_seen - 1) + @num_measurements_seen < @max_size ? @num_measurements_seen : rand(0..(@num_measurements_seen - 1)) end end end diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb index a7d90a68e..e8d783366 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponential_bucket_histogram_test.rb @@ -407,7 +407,7 @@ def expect_balanced(hdp, count) expbh.update(2**100, {}, data_points) hdp = data_points[{}] - expected_sum = (2**100) + (2**(-100)) + expected_sum = (2**100) + (2**-100) _(hdp.sum).must_be_within_epsilon(expected_sum, 1e-5) _(hdp.count).must_equal(2) _(hdp.scale).must_equal(-7) diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb index f45db2638..62c5f9f87 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping_test.rb @@ -109,7 +109,7 @@ _(logarithm_mapping.map_to_index(MIN_NORMAL_VALUE / 100)).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1050)).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1073)).must_equal(correct_min_index) - _(logarithm_mapping.map_to_index(1.1 * (2**(-1073)))).must_equal(correct_min_index) + _(logarithm_mapping.map_to_index(1.1 * (2**-1073))).must_equal(correct_min_index) _(logarithm_mapping.map_to_index(2**-1074)).must_equal(correct_min_index) mapped_lower = logarithm_mapping.get_lower_boundary(min_index) From 52ddb416f7fb0ae83ad0ecd34f2b9d54c6677f79 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 16:48:16 +1000 Subject: [PATCH 5/5] final fix --- .../sdk/trace/samplers/consistent_probability_tracestate.rb | 2 ++ .../sdk/trace/samplers/consistent_probability_based_test.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb b/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb index 207886663..0249ede8c 100644 --- a/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb +++ b/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb @@ -33,6 +33,7 @@ module ConsistentProbabilityTraceState def sanitized_tracestate(trace_id, span_context) sampled = span_context.trace_flags.sampled? tracestate = span_context.tracestate + # rubocop:disable Lint/DuplicateBranch parse_ot_vendor_tag(tracestate) do |p, r, rest| if !r.nil? && r > 62 p = r = nil @@ -49,6 +50,7 @@ def sanitized_tracestate(trace_id, span_context) end update_tracestate(tracestate, p, r, rest) end + # rubocop:enable Lint/DuplicateBranch end # parse_ot_vendor_tag parses the 'ot' vendor tag of the tracestate. diff --git a/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb b/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb index b24b85e33..fe533fbf9 100644 --- a/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb +++ b/sdk_experimental/test/opentelemetry/sdk/trace/samplers/consistent_probability_based_test.rb @@ -117,7 +117,7 @@ p_ceil = sampler.instance_variable_get(:@p_ceil) # Verify that the sampling probability encoded in each `p` adds up to the probability # in the the initializer argument - _((2**(-p_ceil) * ceil_prob) + (2**(-p_floor) * floor_prob)).must_be_within_epsilon(0.1) + _(((2**(-p_ceil)) * ceil_prob) + ((2**(-p_floor)) * floor_prob)).must_be_within_epsilon(0.1) end end end