Skip to content
14 changes: 4 additions & 10 deletions api/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ inherit_from: ../contrib/rubocop.yml

Gemspec/DevelopmentDependencies:
Enabled: false
Style/ExplicitBlockArgument:
Enabled: false
Lint/AmbiguousOperatorPrecedence:
Enabled: false
Minitest/AssertPredicate:
Expand All @@ -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'
6 changes: 3 additions & 3 deletions api/benchmarks/context_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/lib/opentelemetry/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/lib/opentelemetry/trace/trace_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(flags)
#
# @return [Boolean]
def sampled?
(@flags & 1) != 0
@flags.anybits?(1)
end

DEFAULT = from_byte(0)
Expand Down
2 changes: 1 addition & 1 deletion api/lib/opentelemetry/trace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
6 changes: 3 additions & 3 deletions api/lib/opentelemetry/trace/tracestate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions common/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
inherit_from: ../contrib/rubocop.yml

Style/ExplicitBlockArgument:
Enabled: false
Lint/AmbiguousRange:
Enabled: false
Minitest/AssertPredicate:
Expand Down
2 changes: 1 addition & 1 deletion common/lib/opentelemetry/common/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions exporter/otlp-common/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ Metrics/MethodLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false

Style/ObjectThen:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions exporter/otlp/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ Performance/MapCompact:
Enabled: false
Performance/MethodObjectAsBlock:
Enabled: false
Style/ObjectThen:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions exporter/zipkin/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Metrics/PerceivedComplexity:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Style/ExplicitBlockArgument:
Enabled: false
Lint/AmbiguousOperatorPrecedence:
Enabled: false
Lint/SuppressedExceptionInNumberConversion:
Expand Down
6 changes: 0 additions & 6 deletions exporter/zipkin/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions logs_api/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ Metrics/CyclomaticComplexity:

Lint/EmptyClass:
Enabled: false
Style/ReduceToHash:
Enabled: false
6 changes: 3 additions & 3 deletions logs_api/benchmarks/log_record_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion logs_sdk/lib/opentelemetry/sdk/logs/log_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions metrics_api/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ Metrics/CyclomaticComplexity:
Max: 20
Minitest/AssertKindOf:
Enabled: false
Style/EmptyClassDefinition:
Enabled: false
2 changes: 2 additions & 0 deletions metrics_api/lib/opentelemetry/metrics/meter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions metrics_sdk/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ def offer(value: nil, timestamp: nil, attributes: nil, context: nil)
# @param aggregation_temporality [Symbol] :delta or :cumulative
# @return [Array<Exemplar>] 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion metrics_sdk/lib/opentelemetry/sdk/metrics/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions metrics_sdk/lib/opentelemetry/sdk/metrics/meter_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ 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'
@exemplar_filter = Exemplar::TraceBasedExemplarFilter
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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Loading