diff --git a/api/.rubocop.yml b/api/.rubocop.yml index c1ecf94c70..312602591f 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,9 @@ Minitest/RefutePredicate: Enabled: false Performance/MethodObjectAsBlock: Enabled: false -Style/BitwisePredicate: - Enabled: false Style/EmptyClassDefinition: - Enabled: false -Style/HashConversion: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false + Exclude: + - 'benchmarks/context_bench.rb' Style/OneClassPerFile: - Enabled: false + Exclude: + - 'benchmarks/context_bench.rb' diff --git a/api/benchmarks/context_bench.rb b/api/benchmarks/context_bench.rb index 59444da24f..7df6d8ee20 100644 --- a/api/benchmarks/context_bench.rb +++ b/api/benchmarks/context_bench.rb @@ -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/api/lib/opentelemetry/context.rb b/api/lib/opentelemetry/context.rb index c118f1cd07..722a157c6a 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 eaf26c4695..8d56b8deb9 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 23998ca043..4442e75637 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 3739941619..651d3af5fc 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 8f206760d5..783c542dee 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.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[@hash] + h = @hash.to_h.dup h.delete(key) self.class.create(h) end diff --git a/common/.rubocop.yml b/common/.rubocop.yml index 25da94a3a4..c57c5369a8 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/common/lib/opentelemetry/common/utilities.rb b/common/lib/opentelemetry/common/utilities.rb index af8759a41a..86e1e710a6 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/exporter/otlp-common/.rubocop.yml b/exporter/otlp-common/.rubocop.yml index 859b15d9dd..5401c3f32f 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-common/lib/opentelemetry/exporter/otlp/common.rb b/exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb index 26c2cffe46..07e63a46ad 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/.rubocop.yml b/exporter/otlp/.rubocop.yml index 6bda33fa6d..15997074bc 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/otlp/lib/opentelemetry/exporter/otlp/exporter.rb b/exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb index 30655f901a..7f4c7b8181 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/.rubocop.yml b/exporter/zipkin/.rubocop.yml index 586eb0141b..a4dae929ab 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 d1a173295f..be76a8852e 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/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/exporter.rb index f032bb7977..ecd93852f4 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 - OpenTelemetry::Common::Utilities.untraced { yield } + OpenTelemetry::Common::Utilities.untraced { yield } # rubocop:disable Style/ExplicitBlockArgument 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 0a53199423..b035e65055 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/.rubocop.yml b/logs_api/.rubocop.yml index 543da68f84..8292473868 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/logs_api/benchmarks/log_record_bench.rb b/logs_api/benchmarks/log_record_bench.rb index c1e24b54b6..684179b919 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/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb b/logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb index 355db31c87..65fefc5f97 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&.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_api/.rubocop.yml b/metrics_api/.rubocop.yml index 2a189d2822..29c769651b 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/metrics_api/lib/opentelemetry/metrics/meter.rb b/metrics_api/lib/opentelemetry/metrics/meter.rb index 56df0e5827..f32311e794 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/metrics_sdk/.rubocop.yml b/metrics_sdk/.rubocop.yml index cb3ec2d264..9de5d2629c 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/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 4e24ce0c16..c646a46ca6 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,10 +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.each do |bucket| - exemplars << bucket.collect(point_attributes: attributes) - end + 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 97ec2959ce..77629c5d24 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,10 +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.each do |bucket| - exemplars << bucket.collect(point_attributes: attributes) - end + 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/export.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb index 782a75aae4..05b6cfb485 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 4adc440ea3..b464f035c8 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/export/in_memory_metric_pull_exporter.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb index 9701c904c9..49a0922df0 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 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 fe139da345..af0cfc29f0 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 5510b5a428..d7ba111a8c 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 @@ -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 83dbde297e..ccb3cc19a3 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/integration/periodic_metric_reader_test.rb b/metrics_sdk/test/integration/periodic_metric_reader_test.rb index 199eabc98f..2b25b04997 100644 --- a/metrics_sdk/test/integration/periodic_metric_reader_test.rb +++ b/metrics_sdk/test/integration/periodic_metric_reader_test.rb @@ -11,7 +11,7 @@ describe '#periodic_metric_reader' do before do reset_metrics_sdk - @original_temp = ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] + @original_temp = ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = 'delta' 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 dfd123500e..274a47be45 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', 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['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['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['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/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 9136f1e09d..3a908f0a14 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/meter_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb index 2b010fa8ce..6868224728 100644 --- a/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/meter_test.rb @@ -63,7 +63,7 @@ OpenTelemetry::SDK.configure OpenTelemetry.meter_provider.add_metric_reader(metric_exporter) - @original_temp = ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] + @original_temp = ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', nil) ENV['OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'] = 'delta' 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 4ce073a5ec..bc7f466856 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/propagator/jaeger/.rubocop.yml b/propagator/jaeger/.rubocop.yml index 71dd9e7902..bfe3b19f75 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 51b68e3b39..56519add47 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/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb b/propagator/jaeger/lib/opentelemetry/propagator/jaeger/text_map_propagator.rb index a366be0005..2c44b77663 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/.rubocop.yml b/sdk/.rubocop.yml index 71de374ed7..29e6651cba 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 diff --git a/sdk/.rubocop_todo.yml b/sdk/.rubocop_todo.yml index c587c5557b..66265e21b5 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/lib/opentelemetry/sdk.rb b/sdk/lib/opentelemetry/sdk.rb index 6447f18af5..f2b07f206c 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 94a5020ebf..1b87f936a2 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/forwarding_logger.rb b/sdk/lib/opentelemetry/sdk/forwarding_logger.rb index 2bb467a343..1326bbd3e4 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/internal.rb b/sdk/lib/opentelemetry/sdk/internal.rb index fae806960c..81f488e056 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 c689ea1bae..822b6ef517 100644 --- a/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +++ b/sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb @@ -210,9 +210,11 @@ def report_dropped_spans(dropped_spans, reason:, function: nil) end def lock + # rubocop:disable Style/ExplicitBlockArgument @mutex.synchronize do yield end + # rubocop:enable Style/ExplicitBlockArgument end end end diff --git a/sdk/lib/opentelemetry/sdk/trace/span.rb b/sdk/lib/opentelemetry/sdk/trace/span.rb index 5a3e69cb7a..010fa21afe 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.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 = Hash[event.attributes] # 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? 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 3adf093c41..6d698d8fc8 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 @@ -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 diff --git a/sdk/test/opentelemetry/sdk/trace/span_test.rb b/sdk/test/opentelemetry/sdk/trace/span_test.rb index 396d9e3ee4..f5c97c43f9 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 diff --git a/sdk_experimental/.rubocop.yml b/sdk_experimental/.rubocop.yml index b7134a71b8..35ba360032 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 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 f6b8333426..1624373780 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