From a43ffff60cfa0a9dac88a453d6592b9ec38a564d Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 18:29:51 +1000 Subject: [PATCH 01/13] remove some style cop disablement --- exporter/otlp-common/.rubocop.yml | 3 --- exporter/otlp/.rubocop.yml | 2 -- exporter/zipkin/.rubocop.yml | 2 -- exporter/zipkin/.rubocop_todo.yml | 6 ------ logs_api/.rubocop.yml | 2 -- metrics_api/.rubocop.yml | 2 -- propagator/jaeger/.rubocop.yml | 5 ----- propagator/jaeger/.rubocop_todo.yml | 6 ------ sdk/.rubocop_todo.yml | 7 ------- sdk_experimental/.rubocop.yml | 2 -- 10 files changed, 37 deletions(-) diff --git a/exporter/otlp-common/.rubocop.yml b/exporter/otlp-common/.rubocop.yml index 859b15d9d..5401c3f32 100644 --- a/exporter/otlp-common/.rubocop.yml +++ b/exporter/otlp-common/.rubocop.yml @@ -11,6 +11,3 @@ Metrics/MethodLength: Enabled: false Metrics/PerceivedComplexity: Enabled: false - -Style/ObjectThen: - Enabled: false diff --git a/exporter/otlp/.rubocop.yml b/exporter/otlp/.rubocop.yml index 6bda33fa6..15997074b 100644 --- a/exporter/otlp/.rubocop.yml +++ b/exporter/otlp/.rubocop.yml @@ -13,5 +13,3 @@ Performance/MapCompact: Enabled: false Performance/MethodObjectAsBlock: Enabled: false -Style/ObjectThen: - Enabled: false diff --git a/exporter/zipkin/.rubocop.yml b/exporter/zipkin/.rubocop.yml index 586eb0141..a4dae929a 100644 --- a/exporter/zipkin/.rubocop.yml +++ b/exporter/zipkin/.rubocop.yml @@ -15,8 +15,6 @@ Metrics/PerceivedComplexity: Enabled: false Metrics/CyclomaticComplexity: Enabled: false -Style/ExplicitBlockArgument: - Enabled: false Lint/AmbiguousOperatorPrecedence: Enabled: false Lint/SuppressedExceptionInNumberConversion: diff --git a/exporter/zipkin/.rubocop_todo.yml b/exporter/zipkin/.rubocop_todo.yml index d1a173295..be76a8852 100644 --- a/exporter/zipkin/.rubocop_todo.yml +++ b/exporter/zipkin/.rubocop_todo.yml @@ -15,9 +15,3 @@ Metrics/CyclomaticComplexity: # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 14 - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/ZeroLengthPredicate: - Exclude: - - 'lib/opentelemetry/exporter/zipkin/transformer.rb' diff --git a/logs_api/.rubocop.yml b/logs_api/.rubocop.yml index 543da68f8..829247386 100644 --- a/logs_api/.rubocop.yml +++ b/logs_api/.rubocop.yml @@ -9,5 +9,3 @@ Metrics/CyclomaticComplexity: Lint/EmptyClass: Enabled: false -Style/ReduceToHash: - Enabled: false diff --git a/metrics_api/.rubocop.yml b/metrics_api/.rubocop.yml index 2a189d282..29c769651 100644 --- a/metrics_api/.rubocop.yml +++ b/metrics_api/.rubocop.yml @@ -9,5 +9,3 @@ Metrics/CyclomaticComplexity: Max: 20 Minitest/AssertKindOf: Enabled: false -Style/EmptyClassDefinition: - Enabled: false diff --git a/propagator/jaeger/.rubocop.yml b/propagator/jaeger/.rubocop.yml index 71dd9e790..bfe3b19f7 100644 --- a/propagator/jaeger/.rubocop.yml +++ b/propagator/jaeger/.rubocop.yml @@ -1,8 +1,3 @@ inherit_from: - ../../contrib/rubocop.yml - .rubocop_todo.yml - -Style/BitwisePredicate: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false diff --git a/propagator/jaeger/.rubocop_todo.yml b/propagator/jaeger/.rubocop_todo.yml index 51b68e3b3..56519add4 100644 --- a/propagator/jaeger/.rubocop_todo.yml +++ b/propagator/jaeger/.rubocop_todo.yml @@ -10,9 +10,3 @@ Lint/MixedRegexpCaptureTypes: Exclude: - 'lib/opentelemetry/propagator/jaeger/text_map_propagator.rb' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/SlicingWithRange: - Exclude: - - 'lib/opentelemetry/propagator/jaeger/text_map_propagator.rb' diff --git a/sdk/.rubocop_todo.yml b/sdk/.rubocop_todo.yml index c587c5557..66265e21b 100644 --- a/sdk/.rubocop_todo.yml +++ b/sdk/.rubocop_todo.yml @@ -20,10 +20,3 @@ Metrics/CyclomaticComplexity: # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 9 - -# Offense count: 1 -# Configuration parameters: AllowedMethods. -# AllowedMethods: respond_to_missing? -Style/OptionalBooleanParameter: - Exclude: - - 'test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb' diff --git a/sdk_experimental/.rubocop.yml b/sdk_experimental/.rubocop.yml index b7134a71b..35ba36003 100644 --- a/sdk_experimental/.rubocop.yml +++ b/sdk_experimental/.rubocop.yml @@ -17,5 +17,3 @@ Lint/DuplicateBranch: Enabled: false Naming/PredicateMethod: Enabled: false -Style/NegatedIfElseCondition: - Enabled: false From b3e304df10064abcdf5ee9bdd1d02813b3e01c6e Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 19:19:28 +1000 Subject: [PATCH 02/13] Address violations --- .../otlp-common/lib/opentelemetry/exporter/otlp/common.rb | 2 +- exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb | 2 +- .../zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb | 4 ++-- .../zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb | 2 +- logs_api/benchmarks/log_record_bench.rb | 6 +++--- .../sdk/trace/export/batch_span_processor_test.rb | 2 +- .../trace/samplers/parent_consistent_probability_based.rb | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb b/exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb index 26c2cffe4..07e63a46a 100644 --- a/exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb +++ b/exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb @@ -101,7 +101,7 @@ def as_otlp_span(span_data) ) end, dropped_links_count: span_data.total_recorded_links - span_data.links&.size.to_i, - status: span_data.status&.yield_self do |status| + status: span_data.status&.then do |status| Opentelemetry::Proto::Trace::V1::Status.new( code: as_otlp_status_code(status.code), message: status.description diff --git a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb index 30655f901..7f4c7b818 100644 --- a/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb +++ b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb @@ -362,7 +362,7 @@ def as_otlp_span(span_data) # rubocop:disable Metrics/MethodLength, Metrics/Cycl ) end, dropped_links_count: span_data.total_recorded_links - span_data.links&.size.to_i, - status: span_data.status&.yield_self do |status| + status: span_data.status&.then do |status| Opentelemetry::Proto::Trace::V1::Status.new( code: as_otlp_status_code(status.code), message: status.description diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb index f032bb797..b28891e11 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb @@ -100,8 +100,8 @@ def encode_spans(span_data) span_data.map! { |span| Transformer.to_zipkin_span(span, span.resource) } end - def around_request - OpenTelemetry::Common::Utilities.untraced { yield } + def around_request(&block) + OpenTelemetry::Common::Utilities.untraced { block.call } end def valid_headers?(headers) diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb index 0a5319942..b035e6505 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb @@ -115,7 +115,7 @@ def add_annotations(zipkin_span, span_data) return if span_data.events.nil? || span_data.events.empty? events = span_data.events.map do |event| - if event.attributes.keys.length.zero? + if event.attributes.keys.empty? { timestamp: event.timestamp / 1_000, value: event.name diff --git a/logs_api/benchmarks/log_record_bench.rb b/logs_api/benchmarks/log_record_bench.rb index c1e24b54b..684179b91 100644 --- a/logs_api/benchmarks/log_record_bench.rb +++ b/logs_api/benchmarks/log_record_bench.rb @@ -7,9 +7,9 @@ require 'benchmark/ips' require 'opentelemetry-logs-sdk' -small_attrs = 1.upto(1).each_with_object({}) { |i, h| h["key.#{i}"] = "value_#{i}" } -medium_attrs = 1.upto(3).each_with_object({}) { |i, h| h["key.#{i}"] = "value_#{i}" } -large_attrs = 1.upto(8).each_with_object({}) { |i, h| h["key.#{i}"] = "value_#{i}" } +small_attrs = 1.upto(1).to_h { |i| ["key.#{i}", "value_#{i}"] } +medium_attrs = 1.upto(3).to_h { |i| ["key.#{i}", "value_#{i}"] } +large_attrs = 1.upto(8).to_h { |i| ["key.#{i}", "value_#{i}"] } Benchmark.ips do |x| x.report 'LogRecord.new with 1 attributes' do diff --git a/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb b/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb index 3adf093c4..5a4419003 100644 --- a/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb @@ -69,7 +69,7 @@ def observe_value(metric, value:, labels: {}); end end class TestSpan - def initialize(id = nil, recording = true) + def initialize(id = nil, recording: true) trace_flags = recording ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT @context = OpenTelemetry::Trace::SpanContext.new(trace_flags: trace_flags) @id = id diff --git a/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb b/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb index f6b833342..162437378 100644 --- a/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb +++ b/sdk_experimental/lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb @@ -40,15 +40,15 @@ def description # See {Samplers}. def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context - if !parent_span_context.valid? - @root.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes) - else + if parent_span_context.valid? tracestate = sanitized_tracestate(trace_id, parent_span_context) if parent_span_context.trace_flags.sampled? Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: tracestate) else Result.new(decision: Decision::DROP, tracestate: tracestate) end + else + @root.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes) end end From 39a6a98247a447006ff3d21f82f01f63d80a2741 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 19:57:55 +1000 Subject: [PATCH 03/13] Address more violations --- exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb | 2 +- metrics_api/lib/opentelemetry/metrics/meter.rb | 2 ++ .../opentelemetry/propagator/jaeger/text_map_propagator.rb | 4 ++-- .../sdk/trace/export/batch_span_processor_test.rb | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb index b28891e11..765425df6 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb @@ -101,7 +101,7 @@ def encode_spans(span_data) end def around_request(&block) - OpenTelemetry::Common::Utilities.untraced { block.call } + OpenTelemetry::Common::Utilities.untraced { yield } end def valid_headers?(headers) diff --git a/metrics_api/lib/opentelemetry/metrics/meter.rb b/metrics_api/lib/opentelemetry/metrics/meter.rb index 56df0e582..f32311e79 100644 --- a/metrics_api/lib/opentelemetry/metrics/meter.rb +++ b/metrics_api/lib/opentelemetry/metrics/meter.rb @@ -20,10 +20,12 @@ class Meter private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :GAUGE, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER) + # rubocop:disable Style/EmptyClassDefinition DuplicateInstrumentError = Class.new(OpenTelemetry::Error) InstrumentNameError = Class.new(OpenTelemetry::Error) InstrumentUnitError = Class.new(OpenTelemetry::Error) InstrumentDescriptionError = Class.new(OpenTelemetry::Error) + # rubocop:enable Style/EmptyClassDefinition def initialize @mutex = Mutex.new 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..2c44b7766 100644 --- a/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb +++ b/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb @@ -106,7 +106,7 @@ def context_with_extracted_baggage(carrier, context, getter) baggage_key_prefix = 'uberctx-' OpenTelemetry::Baggage.build(context: context) do |b| getter.keys(carrier).each do |carrier_key| - baggage_key = carrier_key.start_with?(baggage_key_prefix) && carrier_key[baggage_key_prefix.length..-1] + baggage_key = carrier_key.start_with?(baggage_key_prefix) && carrier_key[baggage_key_prefix.length..] next unless baggage_key raw_value = getter.get(carrier, carrier_key) @@ -129,7 +129,7 @@ def to_jaeger_flags(context, span_context) end def to_trace_flags(sampling_flags) - if (sampling_flags & SAMPLED_FLAG_BIT) != 0 + if sampling_flags.anybits?(SAMPLED_FLAG_BIT) Trace::TraceFlags::SAMPLED else Trace::TraceFlags::DEFAULT diff --git a/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb b/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb index 5a4419003..6d698d8fc 100644 --- a/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/export/batch_span_processor_test.rb @@ -314,7 +314,7 @@ def shutdown(timeout: nil) bsp = BatchSpanProcessor.new(te, max_queue_size: 6, max_export_batch_size: 3) - tss = [TestSpan.new, TestSpan.new(nil, false)] + tss = [TestSpan.new, TestSpan.new(nil, recording: false)] tss.each { |ts| bsp.on_finish(ts) } bsp.shutdown From 504dd4fa2fec9ae8719b85536201e228b9bd7968 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Thu, 11 Jun 2026 20:06:36 +1000 Subject: [PATCH 04/13] Another fix --- exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb index 765425df6..5ee1cf96b 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb @@ -100,7 +100,7 @@ def encode_spans(span_data) span_data.map! { |span| Transformer.to_zipkin_span(span, span.resource) } end - def around_request(&block) + def around_request(&) OpenTelemetry::Common::Utilities.untraced { yield } end From 774158c7dd924c55fb979154c85a457d2ca5959f Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 00:03:32 +1000 Subject: [PATCH 05/13] Update exporter.rb --- exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb index 5ee1cf96b..ecd93852f 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb @@ -100,8 +100,8 @@ def encode_spans(span_data) span_data.map! { |span| Transformer.to_zipkin_span(span, span.resource) } end - def around_request(&) - OpenTelemetry::Common::Utilities.untraced { yield } + def around_request + OpenTelemetry::Common::Utilities.untraced { yield } # rubocop:disable Style/ExplicitBlockArgument end def valid_headers?(headers) From daea72edc445747b098433432f4803d63649db07 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 00:11:58 +1000 Subject: [PATCH 06/13] Remove last of disablements --- api/.rubocop.yml | 12 ------------ common/.rubocop.yml | 2 -- metrics_sdk/.rubocop.yml | 14 -------------- sdk/.rubocop.yml | 12 ------------ 4 files changed, 40 deletions(-) diff --git a/api/.rubocop.yml b/api/.rubocop.yml index c1ecf94c7..229ac0c23 100644 --- a/api/.rubocop.yml +++ b/api/.rubocop.yml @@ -2,8 +2,6 @@ inherit_from: ../contrib/rubocop.yml Gemspec/DevelopmentDependencies: Enabled: false -Style/ExplicitBlockArgument: - Enabled: false Lint/AmbiguousOperatorPrecedence: Enabled: false Minitest/AssertPredicate: @@ -12,13 +10,3 @@ Minitest/RefutePredicate: Enabled: false Performance/MethodObjectAsBlock: Enabled: false -Style/BitwisePredicate: - Enabled: false -Style/EmptyClassDefinition: - Enabled: false -Style/HashConversion: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/OneClassPerFile: - Enabled: false diff --git a/common/.rubocop.yml b/common/.rubocop.yml index 25da94a3a..c57c5369a 100644 --- a/common/.rubocop.yml +++ b/common/.rubocop.yml @@ -1,7 +1,5 @@ inherit_from: ../contrib/rubocop.yml -Style/ExplicitBlockArgument: - Enabled: false Lint/AmbiguousRange: Enabled: false Minitest/AssertPredicate: diff --git a/metrics_sdk/.rubocop.yml b/metrics_sdk/.rubocop.yml index cb3ec2d26..9de5d2629 100644 --- a/metrics_sdk/.rubocop.yml +++ b/metrics_sdk/.rubocop.yml @@ -18,19 +18,5 @@ Naming/PredicateMethod: Enabled: false Performance/CollectionLiteralInLoop: Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionQuerying: - Enabled: false -Style/EmptyClassDefinition: - Enabled: false -Style/FetchEnvVar: - Enabled: false -Style/MapIntoArray: - Enabled: false -Style/NilLambda: - Enabled: false -Style/SuperArguments: - Enabled: false Lint/SymbolConversion: Enabled: false diff --git a/sdk/.rubocop.yml b/sdk/.rubocop.yml index 71de374ed..29e6651cb 100644 --- a/sdk/.rubocop.yml +++ b/sdk/.rubocop.yml @@ -2,8 +2,6 @@ inherit_from: - ../contrib/rubocop.yml - .rubocop_todo.yml -Style/ExplicitBlockArgument: - Enabled: false Lint/AmbiguousOperatorPrecedence: Enabled: false Lint/EmptyClass: @@ -14,13 +12,3 @@ Naming/BlockForwarding: Enabled: false Naming/PredicateMethod: Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/EmptyClassDefinition: - Enabled: false -Style/HashConversion: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/PredicateWithKind: - Enabled: false From 2b5cb438f05deb7477a2a530086162ca99c2d18a Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 00:50:07 +1000 Subject: [PATCH 07/13] Attempt 1 violation fixes --- api/.rubocop.yml | 3 ++ api/benchmarks/context_bench.rb | 2 +- api/lib/opentelemetry/context.rb | 2 +- .../propagation/trace_context/trace_parent.rb | 2 ++ api/lib/opentelemetry/trace/trace_flags.rb | 2 +- api/lib/opentelemetry/trace/tracer.rb | 2 +- api/lib/opentelemetry/trace/tracestate.rb | 6 ++-- common/lib/opentelemetry/common/utilities.rb | 2 +- .../lib/opentelemetry/sdk/logs/log_record.rb | 2 +- .../metrics/export/periodic_metric_reader.rb | 4 +-- .../sdk/metrics/meter_provider.rb | 4 +-- .../periodic_metric_reader_test.rb | 6 ++-- .../aggregation_temporality_test.rb | 30 +++++++++---------- .../opentelemetry/sdk/metrics/meter_test.rb | 6 ++-- metrics_sdk/test/test_helper.rb | 6 ++-- .../opentelemetry/sdk/forwarding_logger.rb | 28 ++++++++--------- sdk/lib/opentelemetry/sdk/trace/span.rb | 4 +-- 17 files changed, 58 insertions(+), 53 deletions(-) diff --git a/api/.rubocop.yml b/api/.rubocop.yml index 229ac0c23..5d5a3853a 100644 --- a/api/.rubocop.yml +++ b/api/.rubocop.yml @@ -10,3 +10,6 @@ Minitest/RefutePredicate: Enabled: false Performance/MethodObjectAsBlock: Enabled: false +Style/OneClassPerFile: + Exclude: + - 'benchmarks/context_bench.rb' \ No newline at end of file diff --git a/api/benchmarks/context_bench.rb b/api/benchmarks/context_bench.rb index 59444da24..7e1d34945 100644 --- a/api/benchmarks/context_bench.rb +++ b/api/benchmarks/context_bench.rb @@ -108,7 +108,7 @@ class FiberAttributeContext EMPTY_ENTRIES = {}.freeze private_constant :EMPTY_ENTRIES - DetachError = Class.new(StandardError) + DetachError = Class.new(StandardError) # rubocop:disable Style/EmptyClassDefinition class << self def current diff --git a/api/lib/opentelemetry/context.rb b/api/lib/opentelemetry/context.rb index c118f1cd0..722a157c6 100644 --- a/api/lib/opentelemetry/context.rb +++ b/api/lib/opentelemetry/context.rb @@ -15,7 +15,7 @@ class Context EMPTY_ENTRIES = {}.freeze private_constant :EMPTY_ENTRIES - DetachError = Class.new(OpenTelemetry::Error) + DetachError = Class.new(OpenTelemetry::Error) # rubocop:disable Style/EmptyClassDefinition class << self # Returns a key used to index a value in a Context diff --git a/api/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb b/api/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb index eaf26c469..8d56b8deb 100644 --- a/api/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb +++ b/api/lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb @@ -11,10 +11,12 @@ module TraceContext # https://www.w3.org/TR/trace-context/ # {Trace::SpanContext} class TraceParent + # rubocop:disable Style/EmptyClassDefinition InvalidFormatError = Class.new(Error) InvalidVersionError = Class.new(Error) InvalidTraceIDError = Class.new(Error) InvalidSpanIDError = Class.new(Error) + # rubocop:enable Style/EmptyClassDefinition TRACE_PARENT_HEADER = 'traceparent' SUPPORTED_VERSION = 0 diff --git a/api/lib/opentelemetry/trace/trace_flags.rb b/api/lib/opentelemetry/trace/trace_flags.rb index 23998ca04..4442e7563 100644 --- a/api/lib/opentelemetry/trace/trace_flags.rb +++ b/api/lib/opentelemetry/trace/trace_flags.rb @@ -40,7 +40,7 @@ def initialize(flags) # # @return [Boolean] def sampled? - (@flags & 1) != 0 + @flags.anybits?(1) end DEFAULT = from_byte(0) diff --git a/api/lib/opentelemetry/trace/tracer.rb b/api/lib/opentelemetry/trace/tracer.rb index 373994161..651d3af5f 100644 --- a/api/lib/opentelemetry/trace/tracer.rb +++ b/api/lib/opentelemetry/trace/tracer.rb @@ -34,7 +34,7 @@ class Tracer def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, record_exception: true) span = nil span = start_span(name, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind) - Trace.with_span(span) { |s, c| yield s, c } + Trace.with_span(span) { |s, c| yield s, c } # rubocop:disable Style/ExplicitBlockArgument rescue Exception => e # rubocop:disable Lint/RescueException span&.record_exception(e) if record_exception span&.status = Status.error("Unhandled exception of type: #{e.class}") diff --git a/api/lib/opentelemetry/trace/tracestate.rb b/api/lib/opentelemetry/trace/tracestate.rb index 8f206760d..8195edaee 100644 --- a/api/lib/opentelemetry/trace/tracestate.rb +++ b/api/lib/opentelemetry/trace/tracestate.rb @@ -75,7 +75,7 @@ def create(hash) # @return [Tracestate] def initialize(hash) excess = hash.size - MAX_MEMBER_COUNT - hash = Hash[hash.drop(excess)] if excess.positive? + hash = hash.drop(excess).to_h if excess.positive? @hash = hash.freeze end @@ -105,7 +105,7 @@ def set_value(key, value) return self end - h = Hash[@hash] + h = @hash.to_h h[key] = value self.class.create(h) end @@ -118,7 +118,7 @@ def set_value(key, value) def delete(key) return self unless @hash.key?(key) - h = Hash[@hash] + h = @hash.to_h h.delete(key) self.class.create(h) end diff --git a/common/lib/opentelemetry/common/utilities.rb b/common/lib/opentelemetry/common/utilities.rb index af8759a41..1644bdcbd 100644 --- a/common/lib/opentelemetry/common/utilities.rb +++ b/common/lib/opentelemetry/common/utilities.rb @@ -104,7 +104,7 @@ def truncate_attribute_value(value, limit) def untraced(context = Context.current) context = context.set_value(UNTRACED_KEY, true) if block_given? - Context.with_current(context) { |ctx| yield ctx } + Context.with_current(context) { |ctx| yield ctx } #rubocop:disable Style/ExplicitBlockArgument else context end diff --git a/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb b/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb index 355db31c8..11f642546 100644 --- a/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb +++ b/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb @@ -81,7 +81,7 @@ def initialize( @severity_text = severity_text @severity_number = severity_number @body = body - @attributes = attributes.nil? ? nil : Hash[attributes] # We need a mutable copy of attributes + @attributes = attributes.nil? ? nil : attributes.to_h # We need a mutable copy of attributes @event_name = event_name @trace_id = trace_id @span_id = span_id diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb index fe139da34..af0cfc29f 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb @@ -134,8 +134,8 @@ def report_result(result_code) OpenTelemetry.logger.debug 'Successfully exported metrics' if result_code == Export::SUCCESS end - def lock(&block) - @mutex.synchronize(&block) + def lock(&) + @mutex.synchronize(&) end end end diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb index 5510b5a42..5f46516a1 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb @@ -131,7 +131,7 @@ def register_synchronous_instrument(instrument) alias register_asynchronous_instrument register_synchronous_instrument def exemplar_filter_setup - case ENV['OTEL_METRICS_EXEMPLAR_FILTER'] + case ENV.fetch('OTEL_METRICS_EXEMPLAR_FILTER', nil) when 'always_on' @exemplar_filter = Exemplar::AlwaysOnExemplarFilter when nil, '', 'trace_based' @@ -139,7 +139,7 @@ def exemplar_filter_setup when 'always_off' @exemplar_filter = Exemplar::AlwaysOffExemplarFilter else - OpenTelemetry.logger.warn("OTEL_METRICS_EXEMPLAR_FILTER #{ENV['OTEL_METRICS_EXEMPLAR_FILTER']} is not part of the provided exemplar filters. Using trace_based.") + OpenTelemetry.logger.warn("OTEL_METRICS_EXEMPLAR_FILTER #{ENV.fetch('OTEL_METRICS_EXEMPLAR_FILTER', nil)} is not part of the provided exemplar filters. Using trace_based.") @exemplar_filter = Exemplar::TraceBasedExemplarFilter end end diff --git a/metrics_sdk/test/integration/periodic_metric_reader_test.rb b/metrics_sdk/test/integration/periodic_metric_reader_test.rb index 199eabc98..9f65221f6 100644 --- a/metrics_sdk/test/integration/periodic_metric_reader_test.rb +++ b/metrics_sdk/test/integration/periodic_metric_reader_test.rb @@ -11,12 +11,12 @@ describe '#periodic_metric_reader' do before do reset_metrics_sdk - @original_temp = ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] - ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = 'delta' + @original_temp = ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) + ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = 'delta' end after do - ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = @original_temp + ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = @original_temp end # OTLP cannot export a metric without data points diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb index dfd123500..17660814f 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb @@ -12,7 +12,7 @@ it 'returns cumulative for counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'cumulative') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :counter, default: :cumulative ) @@ -25,7 +25,7 @@ it 'returns cumulative for observable_counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'cumulative') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :observable_counter, default: :cumulative ) @@ -37,7 +37,7 @@ it 'returns cumulative for histogram instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'cumulative') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :histogram, default: :cumulative ) @@ -49,7 +49,7 @@ it 'returns cumulative for up_down_counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'cumulative') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :up_down_counter, default: :cumulative ) @@ -61,7 +61,7 @@ it 'returns cumulative for observable_up_down_counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'CUMULATIVE') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :observable_up_down_counter, default: :cumulative ) @@ -75,7 +75,7 @@ it 'returns delta for counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'delta') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :counter, default: :cumulative ) @@ -88,7 +88,7 @@ it 'returns delta for observable_counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'delta') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :observable_counter, default: :cumulative ) @@ -100,7 +100,7 @@ it 'returns delta for histogram instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'DELTA') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :histogram, default: :cumulative ) @@ -114,7 +114,7 @@ it 'returns delta for counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'lowmemory') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :counter, default: :cumulative ) @@ -126,7 +126,7 @@ it 'returns cumulative for observable_counter instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'lowmemory') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :observable_counter, default: :cumulative ) @@ -138,7 +138,7 @@ it 'returns delta for histogram instrument' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'LOWMEMORY') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :histogram, default: :cumulative ) @@ -250,7 +250,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to cumulative' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'cumulative') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], instrument_kind: :counter, default: :delta ) @@ -261,7 +261,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to delta' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'delta') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], instrument_kind: :histogram, default: :cumulative ) @@ -272,7 +272,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to lowmemory for non-observable counter' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'lowmemory') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], instrument_kind: :counter, default: :cumulative ) @@ -283,7 +283,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to lowmemory for observable counter' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'lowmemory') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], instrument_kind: :observable_counter, default: :delta ) diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb index 2b010fa8c..81f2c3636 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb @@ -63,12 +63,12 @@ OpenTelemetry::SDK.configure OpenTelemetry.meter_provider.add_metric_reader(metric_exporter) - @original_temp = ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] - ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = 'delta' + @original_temp = ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) + ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = 'delta' end after do - ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = @original_temp + ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = @original_temp end it 'create callback with multi asychronous instrument' do diff --git a/metrics_sdk/test/test_helper.rb b/metrics_sdk/test/test_helper.rb index 865883196..bc6c0e8e8 100644 --- a/metrics_sdk/test/test_helper.rb +++ b/metrics_sdk/test/test_helper.rb @@ -34,8 +34,8 @@ def with_test_logger end def create_meter - ENV['OTEL_TRACES_EXPORTER'] = 'console' - ENV['OTEL_METRICS_EXPORTER'] = 'none' + ENV.fetch('OTEL_TRACES_EXPORTER', nil) = 'console' + ENV.fetch('OTEL_METRICS_EXPORTER', nil) = 'none' OpenTelemetry::SDK.configure OpenTelemetry.meter_provider.add_metric_reader(metric_exporter) OpenTelemetry.meter_provider.enable_exemplar_filter(exemplar_filter: OpenTelemetry::SDK::Metrics::Exemplar::AlwaysOnExemplarFilter) @@ -43,7 +43,7 @@ def create_meter end # Suppress warn-level logs about a missing OTLP exporter for traces -ENV['OTEL_TRACES_EXPORTER'] = 'none' +ENV.fetch('OTEL_TRACES_EXPORTER', nil) = 'none' MAX_NORMAL_EXPONENT = OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::IEEE754::MAX_NORMAL_EXPONENT MIN_NORMAL_EXPONENT = OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::IEEE754::MIN_NORMAL_EXPONENT diff --git a/sdk/lib/opentelemetry/sdk/forwarding_logger.rb b/sdk/lib/opentelemetry/sdk/forwarding_logger.rb index 2bb467a34..1326bbd3e 100644 --- a/sdk/lib/opentelemetry/sdk/forwarding_logger.rb +++ b/sdk/lib/opentelemetry/sdk/forwarding_logger.rb @@ -35,34 +35,34 @@ def initialize(logger, level:) end end - def add(severity, message = nil, progname = nil, &block) + def add(severity, message = nil, progname = nil, &) return true if severity < @level - @logger.add(severity, message, progname, &block) + @logger.add(severity, message, progname, &) end - def debug(progname = nil, &block) - add(Logger::DEBUG, nil, progname, &block) + def debug(progname = nil, &) + add(Logger::DEBUG, nil, progname, &) end - def info(progname = nil, &block) - add(Logger::INFO, nil, progname, &block) + def info(progname = nil, &) + add(Logger::INFO, nil, progname, &) end - def warn(progname = nil, &block) - add(Logger::WARN, nil, progname, &block) + def warn(progname = nil, &) + add(Logger::WARN, nil, progname, &) end - def error(progname = nil, &block) - add(Logger::ERROR, nil, progname, &block) + def error(progname = nil, &) + add(Logger::ERROR, nil, progname, &) end - def fatal(progname = nil, &block) - add(Logger::FATAL, nil, progname, &block) + def fatal(progname = nil, &) + add(Logger::FATAL, nil, progname, &) end - def unknown(progname = nil, &block) - add(Logger::UNKNOWN, nil, progname, &block) + def unknown(progname = nil, &) + add(Logger::UNKNOWN, nil, progname, &) end end end diff --git a/sdk/lib/opentelemetry/sdk/trace/span.rb b/sdk/lib/opentelemetry/sdk/trace/span.rb index 5a3e69cb7..e77b6355e 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span.rb @@ -418,7 +418,7 @@ def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:di excess_link_count = valid_links.size - link_count_limit valid_links.pop(excess_link_count) if excess_link_count.positive? valid_links.map! do |link| - attrs = Hash[link.attributes] # link.attributes is frozen, so we need an unfrozen copy to adjust. + attrs = link.attributes.to_h # link.attributes is frozen, so we need an unfrozen copy to adjust. attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) } excess = attrs.size - link_attribute_count_limit excess.times { attrs.shift } if excess.positive? @@ -444,7 +444,7 @@ def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity, excess = event.attributes.size - event_attribute_count_limit if excess.positive? || !valid_attributes - attrs = Hash[event.attributes] # event.attributes is frozen, so we need an unfrozen copy to adjust. + attrs = event.attributes.to_h # event.attributes is frozen, so we need an unfrozen copy to adjust. attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) } excess = attrs.size - event_attribute_count_limit excess.times { attrs.shift } if excess.positive? From 8bf8d6279476b31d7bcf1e16b53d6ecc02f2cf8c Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 01:12:24 +1000 Subject: [PATCH 08/13] fixes --- api/.rubocop.yml | 2 +- api/lib/opentelemetry/trace/tracestate.rb | 4 ++-- common/lib/opentelemetry/common/utilities.rb | 2 +- logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb | 2 +- metrics_sdk/test/integration/periodic_metric_reader_test.rb | 4 ++-- metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb | 4 ++-- metrics_sdk/test/test_helper.rb | 6 +++--- sdk/lib/opentelemetry/sdk/trace/span.rb | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api/.rubocop.yml b/api/.rubocop.yml index 5d5a3853a..df383fb88 100644 --- a/api/.rubocop.yml +++ b/api/.rubocop.yml @@ -12,4 +12,4 @@ Performance/MethodObjectAsBlock: Enabled: false Style/OneClassPerFile: Exclude: - - 'benchmarks/context_bench.rb' \ No newline at end of file + - 'benchmarks/context_bench.rb' diff --git a/api/lib/opentelemetry/trace/tracestate.rb b/api/lib/opentelemetry/trace/tracestate.rb index 8195edaee..783c542de 100644 --- a/api/lib/opentelemetry/trace/tracestate.rb +++ b/api/lib/opentelemetry/trace/tracestate.rb @@ -105,7 +105,7 @@ def set_value(key, value) return self end - h = @hash.to_h + h = @hash.to_h.dup h[key] = value self.class.create(h) end @@ -118,7 +118,7 @@ def set_value(key, value) def delete(key) return self unless @hash.key?(key) - h = @hash.to_h + h = @hash.to_h.dup h.delete(key) self.class.create(h) end diff --git a/common/lib/opentelemetry/common/utilities.rb b/common/lib/opentelemetry/common/utilities.rb index 1644bdcbd..86e1e710a 100644 --- a/common/lib/opentelemetry/common/utilities.rb +++ b/common/lib/opentelemetry/common/utilities.rb @@ -104,7 +104,7 @@ def truncate_attribute_value(value, limit) def untraced(context = Context.current) context = context.set_value(UNTRACED_KEY, true) if block_given? - Context.with_current(context) { |ctx| yield ctx } #rubocop:disable Style/ExplicitBlockArgument + Context.with_current(context) { |ctx| yield ctx } # rubocop:disable Style/ExplicitBlockArgument else context end diff --git a/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb b/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb index 11f642546..65fefc5f9 100644 --- a/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb +++ b/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb @@ -81,7 +81,7 @@ def initialize( @severity_text = severity_text @severity_number = severity_number @body = body - @attributes = attributes.nil? ? nil : attributes.to_h # We need a mutable copy of attributes + @attributes = attributes&.to_h # We need a mutable copy of attributes @event_name = event_name @trace_id = trace_id @span_id = span_id diff --git a/metrics_sdk/test/integration/periodic_metric_reader_test.rb b/metrics_sdk/test/integration/periodic_metric_reader_test.rb index 9f65221f6..2b25b0499 100644 --- a/metrics_sdk/test/integration/periodic_metric_reader_test.rb +++ b/metrics_sdk/test/integration/periodic_metric_reader_test.rb @@ -12,11 +12,11 @@ before do reset_metrics_sdk @original_temp = ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) - ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = 'delta' + ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = 'delta' end after do - ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = @original_temp + ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = @original_temp end # OTLP cannot export a metric without data points diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb index 81f2c3636..686822472 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb @@ -64,11 +64,11 @@ OpenTelemetry.meter_provider.add_metric_reader(metric_exporter) @original_temp = ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) - ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = 'delta' + ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = 'delta' end after do - ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) = @original_temp + ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = @original_temp end it 'create callback with multi asychronous instrument' do diff --git a/metrics_sdk/test/test_helper.rb b/metrics_sdk/test/test_helper.rb index bc6c0e8e8..865883196 100644 --- a/metrics_sdk/test/test_helper.rb +++ b/metrics_sdk/test/test_helper.rb @@ -34,8 +34,8 @@ def with_test_logger end def create_meter - ENV.fetch('OTEL_TRACES_EXPORTER', nil) = 'console' - ENV.fetch('OTEL_METRICS_EXPORTER', nil) = 'none' + ENV['OTEL_TRACES_EXPORTER'] = 'console' + ENV['OTEL_METRICS_EXPORTER'] = 'none' OpenTelemetry::SDK.configure OpenTelemetry.meter_provider.add_metric_reader(metric_exporter) OpenTelemetry.meter_provider.enable_exemplar_filter(exemplar_filter: OpenTelemetry::SDK::Metrics::Exemplar::AlwaysOnExemplarFilter) @@ -43,7 +43,7 @@ def create_meter end # Suppress warn-level logs about a missing OTLP exporter for traces -ENV.fetch('OTEL_TRACES_EXPORTER', nil) = 'none' +ENV['OTEL_TRACES_EXPORTER'] = 'none' MAX_NORMAL_EXPONENT = OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::IEEE754::MAX_NORMAL_EXPONENT MIN_NORMAL_EXPONENT = OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::IEEE754::MIN_NORMAL_EXPONENT diff --git a/sdk/lib/opentelemetry/sdk/trace/span.rb b/sdk/lib/opentelemetry/sdk/trace/span.rb index e77b6355e..010fa21af 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span.rb @@ -418,7 +418,7 @@ def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:di excess_link_count = valid_links.size - link_count_limit valid_links.pop(excess_link_count) if excess_link_count.positive? valid_links.map! do |link| - attrs = link.attributes.to_h # link.attributes is frozen, so we need an unfrozen copy to adjust. + attrs = link.attributes.to_h.dup # link.attributes is frozen, so we need an unfrozen copy to adjust. attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) } excess = attrs.size - link_attribute_count_limit excess.times { attrs.shift } if excess.positive? @@ -444,7 +444,7 @@ def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity, excess = event.attributes.size - event_attribute_count_limit if excess.positive? || !valid_attributes - attrs = event.attributes.to_h # event.attributes is frozen, so we need an unfrozen copy to adjust. + attrs = event.attributes.to_h.dup # event.attributes is frozen, so we need an unfrozen copy to adjust. attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) } excess = attrs.size - event_attribute_count_limit excess.times { attrs.shift } if excess.positive? From fb10396d69f62dabacb5087897b3423e94366cea Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 01:40:50 +1000 Subject: [PATCH 09/13] more fixes --- api/.rubocop.yml | 3 +++ api/benchmarks/context_bench.rb | 8 ++++---- .../metrics/aggregation/aggregation_temporality_test.rb | 8 ++++---- sdk/lib/opentelemetry/sdk.rb | 2 +- sdk/lib/opentelemetry/sdk/configurator.rb | 6 +++--- sdk/lib/opentelemetry/sdk/internal.rb | 2 +- .../sdk/trace/export/batch_span_processor.rb | 2 +- sdk/test/opentelemetry/sdk/trace/span_test.rb | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/api/.rubocop.yml b/api/.rubocop.yml index df383fb88..312602591 100644 --- a/api/.rubocop.yml +++ b/api/.rubocop.yml @@ -10,6 +10,9 @@ Minitest/RefutePredicate: Enabled: false Performance/MethodObjectAsBlock: Enabled: false +Style/EmptyClassDefinition: + Exclude: + - 'benchmarks/context_bench.rb' Style/OneClassPerFile: Exclude: - 'benchmarks/context_bench.rb' diff --git a/api/benchmarks/context_bench.rb b/api/benchmarks/context_bench.rb index 7e1d34945..7df6d8ee2 100644 --- a/api/benchmarks/context_bench.rb +++ b/api/benchmarks/context_bench.rb @@ -108,7 +108,7 @@ class FiberAttributeContext EMPTY_ENTRIES = {}.freeze private_constant :EMPTY_ENTRIES - DetachError = Class.new(StandardError) # rubocop:disable Style/EmptyClassDefinition + DetachError = Class.new(StandardError) class << self def current @@ -498,10 +498,10 @@ def initialize end def correct_owner! - if @owner != Fiber.current - Fiber[STACK_KEY] = self.class.new.replace(self) - else + if @owner == Fiber.current self + else + Fiber[STACK_KEY] = self.class.new.replace(self) end end end diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb index 17660814f..274a47be4 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/aggregation_temporality_test.rb @@ -250,7 +250,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to cumulative' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'cumulative') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :counter, default: :delta ) @@ -261,7 +261,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to delta' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'delta') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :histogram, default: :cumulative ) @@ -272,7 +272,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to lowmemory for non-observable counter' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'lowmemory') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :counter, default: :cumulative ) @@ -283,7 +283,7 @@ it 'respects OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE set to lowmemory for observable counter' do result = OpenTelemetry::TestHelpers.with_env('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE' => 'lowmemory') do OpenTelemetry::SDK::Metrics::Aggregation::AggregationTemporality.determine_temporality( - aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'], + aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil), instrument_kind: :observable_counter, default: :delta ) diff --git a/sdk/lib/opentelemetry/sdk.rb b/sdk/lib/opentelemetry/sdk.rb index 6447f18af..f2b07f206 100644 --- a/sdk/lib/opentelemetry/sdk.rb +++ b/sdk/lib/opentelemetry/sdk.rb @@ -23,7 +23,7 @@ module SDK # ConfigurationError is an exception type used to wrap configuration errors # passed to OpenTelemetry.error_handler. This can be used to distinguish # errors reported during SDK configuration. - ConfigurationError = Class.new(OpenTelemetry::Error) + ConfigurationError = Class.new(OpenTelemetry::Error) # rubocop:disable Style/EmptyClassDefinition # Configures SDK and instrumentation # diff --git a/sdk/lib/opentelemetry/sdk/configurator.rb b/sdk/lib/opentelemetry/sdk/configurator.rb index 94a5020eb..1b87f936a 100644 --- a/sdk/lib/opentelemetry/sdk/configurator.rb +++ b/sdk/lib/opentelemetry/sdk/configurator.rb @@ -190,11 +190,11 @@ def wrapped_exporters_from_env # rubocop:disable Metrics/CyclomaticComplexity when 'otlp' otlp_protocol = ENV['OTEL_EXPORTER_OTLP_TRACES_PROTOCOL'] || ENV['OTEL_EXPORTER_OTLP_PROTOCOL'] || 'http/protobuf' - if otlp_protocol != 'http/protobuf' + if otlp_protocol == 'http/protobuf' + fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter') + else OpenTelemetry.logger.warn "The #{otlp_protocol} transport protocol is not supported by the OTLP exporter, spans will not be exported." nil - else - fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter') end when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter') when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter') diff --git a/sdk/lib/opentelemetry/sdk/internal.rb b/sdk/lib/opentelemetry/sdk/internal.rb index fae806960..81f488e05 100644 --- a/sdk/lib/opentelemetry/sdk/internal.rb +++ b/sdk/lib/opentelemetry/sdk/internal.rb @@ -34,7 +34,7 @@ def valid_array_value?(value) case value.first when String - value.all? { |v| v.instance_of?(String) } + value.all?(String) when TrueClass, FalseClass value.all? { |v| boolean?(v) } when Numeric diff --git a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb index c689ea1ba..91f2b5b2d 100644 --- a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb @@ -209,7 +209,7 @@ def report_dropped_spans(dropped_spans, reason:, function: nil) @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: dropped_spans.size, labels: { 'reason' => reason, OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => function }) end - def lock + def lock(&) @mutex.synchronize do yield end diff --git a/sdk/test/opentelemetry/sdk/trace/span_test.rb b/sdk/test/opentelemetry/sdk/trace/span_test.rb index 396d9e3ee..f5c97c43f 100644 --- a/sdk/test/opentelemetry/sdk/trace/span_test.rb +++ b/sdk/test/opentelemetry/sdk/trace/span_test.rb @@ -631,6 +631,6 @@ def mock_gettime(monotonic:, realtime:) timestamps[clock_id] end - Process.stub(:clock_gettime, clock_gettime_mock) { yield } + Process.stub(:clock_gettime, clock_gettime_mock) { yield } # rubocop:disable Style/ExplicitBlockArgument end end From 85cd75e5f57eae1e1cbada8d4bf1d0ff7196a2fe Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 02:02:00 +1000 Subject: [PATCH 10/13] last round of fixes --- .../exemplar/aligned_histogram_bucket_exemplar_reservoir.rb | 4 +--- .../metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb | 4 +--- metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb | 2 +- .../sdk/metrics/export/console_metric_pull_exporter.rb | 2 +- metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb | 4 ++-- .../sdk/metrics/state/asynchronous_metric_stream.rb | 2 +- .../exponential_bucket_histogram_test.rb | 2 +- .../sdk/metrics/state/asynchronous_metric_stream_test.rb | 2 +- .../opentelemetry/sdk/trace/export/batch_span_processor.rb | 4 +++- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb index 4e24ce0c1..abde0fb72 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb @@ -44,9 +44,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil) # @return [Array] The collected exemplars def collect(attributes: nil, aggregation_temporality: nil) exemplars = [] - @exemplar_buckets.each do |bucket| - exemplars << bucket.collect(point_attributes: attributes) - end + @exemplar_buckets.map |bucket| { bucket.collect(point_attributes: attributes) } reset if aggregation_temporality == :delta exemplars.compact! exemplars 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..22c9c01f2 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 @@ -36,9 +36,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil) # Reset measurement counter on collection for delta temporality def collect(attributes: nil, aggregation_temporality: nil) exemplars = [] - @exemplar_buckets.each do |bucket| - exemplars << bucket.collect(point_attributes: attributes) - end + @exemplar_buckets.map |bucket| { bucket.collect(point_attributes: attributes) } reset if aggregation_temporality == :delta exemplars.compact! exemplars diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb index 782a75aae..05b6cfb48 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb @@ -8,7 +8,7 @@ module OpenTelemetry module SDK module Metrics module Export - ExportError = Class.new(OpenTelemetry::Error) + ExportError = Class.new(OpenTelemetry::Error) # rubocop:disable Style/EmptyClassDefinition # The operation finished successfully. SUCCESS = 0 diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb index 4adc440ea..b464f035c 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb @@ -13,7 +13,7 @@ module Export # Potentially useful for exploratory purposes. class ConsoleMetricPullExporter < MetricReader def initialize(aggregation_cardinality_limit: nil) - super(aggregation_cardinality_limit: aggregation_cardinality_limit) + super @stopped = false end diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb index 5f46516a1..d7ba111a8 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb @@ -177,9 +177,9 @@ def disable_exemplar_filter # # @return [nil] returns nil # - def add_view(name, **options) + def add_view(name, **) # TODO: add schema_url as part of options - @registered_views << View::RegisteredView.new(name, **options) + @registered_views << View::RegisteredView.new(name, **) nil end end diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb index 83dbde297..ccb3cc19a 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb @@ -46,7 +46,7 @@ def collect(start_time, end_time) invoke_callback(@timeout, @attributes) # Call parent collect method for the core collection logic - super(start_time, end_time) + super end def invoke_callback(timeout, attributes) 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 9136f1e09..3a908f0a1 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 @@ -314,7 +314,7 @@ def ascending_sequence_test(max_size, offset, init_scale) hdp = local_data_points[{}] # Simulate the effect of the mocked increment - hdp.instance_variable_set(:@count, hdp.count + increment - 1) if hdp.count > 0 + hdp.instance_variable_set(:@count, hdp.count + increment - 1) if hdp.any? hdp.instance_variable_set(:@sum, hdp.sum + (value * increment) - value) if hdp.sum > 0 end diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/state/asynchronous_metric_stream_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/state/asynchronous_metric_stream_test.rb index 4ce073a5e..bc7f46685 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/state/asynchronous_metric_stream_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/state/asynchronous_metric_stream_test.rb @@ -91,7 +91,7 @@ _(metric_data.data_points.first.attributes).must_equal(attributes) # Test empty collection when callback returns nil - empty_callback = [proc { nil }] + empty_callback = [proc {}] empty_stream = OpenTelemetry::SDK::Metrics::State::AsynchronousMetricStream.new( 'async_counter', 'description', 'unit', :observable_counter, meter_provider, instrumentation_scope, aggregation, diff --git a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb index 91f2b5b2d..822b6ef51 100644 --- a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb @@ -209,10 +209,12 @@ def report_dropped_spans(dropped_spans, reason:, function: nil) @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: dropped_spans.size, labels: { 'reason' => reason, OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => function }) end - def lock(&) + def lock + # rubocop:disable Style/ExplicitBlockArgument @mutex.synchronize do yield end + # rubocop:enable Style/ExplicitBlockArgument end end end From 97dc68a8a282986f1cee6c94951ee893dd4360cf Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 02:05:46 +1000 Subject: [PATCH 11/13] syntax fix --- .../exemplar/aligned_histogram_bucket_exemplar_reservoir.rb | 2 +- .../metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb index abde0fb72..d7d207054 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb @@ -44,7 +44,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil) # @return [Array] The collected exemplars def collect(attributes: nil, aggregation_temporality: nil) exemplars = [] - @exemplar_buckets.map |bucket| { bucket.collect(point_attributes: attributes) } + @exemplar_buckets.map { |bucket| bucket.collect(point_attributes: attributes) } reset if aggregation_temporality == :delta exemplars.compact! exemplars 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 22c9c01f2..9fc4495da 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 @@ -36,7 +36,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil) # Reset measurement counter on collection for delta temporality def collect(attributes: nil, aggregation_temporality: nil) exemplars = [] - @exemplar_buckets.map |bucket| { bucket.collect(point_attributes: attributes) } + @exemplar_buckets.map { |bucket| bucket.collect(point_attributes: attributes) } reset if aggregation_temporality == :delta exemplars.compact! exemplars From f496684f3cdd39a6c732272b1be7edd650a8a311 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 02:15:17 +1000 Subject: [PATCH 12/13] fix logic --- .../exemplar/aligned_histogram_bucket_exemplar_reservoir.rb | 3 +-- .../metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb index d7d207054..c646a46ca 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb @@ -43,8 +43,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil) # @param aggregation_temporality [Symbol] :delta or :cumulative # @return [Array] The collected exemplars def collect(attributes: nil, aggregation_temporality: nil) - exemplars = [] - @exemplar_buckets.map { |bucket| bucket.collect(point_attributes: attributes) } + exemplars = @exemplar_buckets.map { |bucket| bucket.collect(point_attributes: attributes) } reset if aggregation_temporality == :delta exemplars.compact! exemplars 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 9fc4495da..77629c5d2 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 @@ -35,8 +35,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil) # Reset measurement counter on collection for delta temporality def collect(attributes: nil, aggregation_temporality: nil) - exemplars = [] - @exemplar_buckets.map { |bucket| bucket.collect(point_attributes: attributes) } + exemplars = @exemplar_buckets.map { |bucket| bucket.collect(point_attributes: attributes) } reset if aggregation_temporality == :delta exemplars.compact! exemplars From a0662587e4dd2df1e5849dd6ea09cbc501a3aee6 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sat, 13 Jun 2026 02:19:08 +1000 Subject: [PATCH 13/13] final rubocop fix --- .../sdk/metrics/export/in_memory_metric_pull_exporter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb index 9701c904c..49a0922df 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb @@ -14,7 +14,7 @@ class InMemoryMetricPullExporter < MetricReader attr_reader :metric_snapshots def initialize(aggregation_cardinality_limit: nil) - super(aggregation_cardinality_limit: aggregation_cardinality_limit) + super @metric_snapshots = [] @mutex = Mutex.new end