Skip to content

Commit

Permalink
chore(dev-deps): Add and enable rubocop-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Nov 22, 2023
1 parent 2ec7b82 commit d6166a0
Show file tree
Hide file tree
Showing 82 changed files with 132 additions and 43 deletions.
1 change: 1 addition & 0 deletions .instrumentation_generator/templates/gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.48.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.7.6'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require: rubocop-performance

AllCops:
TargetRubyVersion: '3.0'
NewCops: enable
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ source 'https://rubygems.org'

gem 'rake', '~> 13.0'
gem 'rubocop', '~> 1.57.1'
gem 'rubocop-performance', '~> 1.19.1'
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rails', '>= 6.1'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rails', '>= 6.1'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def require_dependencies
end

def patch_activejob
::ActiveJob::Base.prepend(Patches::Base) unless ::ActiveJob::Base.ancestors.include?(Patches::Base)
::ActiveJob::Base.prepend(Patches::Base) unless ::ActiveJob::Base <= Patches::Base

Handlers.subscribe
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ def start(name, id, payload)
token = OpenTelemetry::Context.attach(
OpenTelemetry::Trace.context_with_span(span)
)
payload.merge!(
__opentelemetry_span: span,
__opentelemetry_ctx_token: token
)
payload[:__opentelemetry_span] = span
payload[:__opentelemetry_ctx_token] = token

[span, token]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rails', '>= 6.1'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/all/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gemspec
group :test do
Dir.entries('../')
.select { |entry| File.directory?(File.join('../', entry)) }
.reject { |entry| %w[. .. all].include?(entry) }
.reject { |entry| %w[. .. all].include?(entry) } # rubocop:disable Performance/CollectionLiteralInLoop
.sort
.each { |dir| gem "opentelemetry-instrumentation-#{dir}", path: "../#{dir}" }
end
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'yard', '~> 0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry-byebug' unless RUBY_ENGINE == 'jruby'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def coerce_env_var(env_var, validation_type)
when :array
env_var.split(',').map(&:strip)
when :boolean
env_var.to_s.strip.downcase == 'true'
env_var.to_s.strip.casecmp('true').zero?
when :integer
env_var.to_i
when :string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.57.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.22.0'
spec.add_development_dependency 'yard', '~> 0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'yard', '~> 0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def post(*args, **kwargs, &task)

super(*args, **kwargs) do
OpenTelemetry::Context.with_current(context) do
task.call(*args, **kwargs)
yield(*args, **kwargs)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'yard', '~> 0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
after do
# Force re-install of instrumentation
Concurrent.send(:remove_const, :ThreadPoolExecutor)
Concurrent.const_set('ThreadPoolExecutor', unmodified_future)
Concurrent.const_set(:ThreadPoolExecutor, unmodified_future)
instrumentation.instance_variable_set(:@installed, false)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'yard', '~> 0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Plugins
class TracerPlugin < Delayed::Plugin
class << self
def instrument_enqueue(job, &block)
return block.call(job) unless enabled?
return yield(job) unless enabled?

attributes = build_attributes(job)
attributes['messaging.operation'] = 'publish'
Expand All @@ -28,7 +28,7 @@ def instrument_enqueue(job, &block)
end

def instrument_invoke(job, &block)
return block.call(job) unless enabled?
return yield(job) unless enabled?

attributes = build_attributes(job)
attributes['messaging.delayed_job.attempts'] = job.attempts if job.attempts
Expand Down Expand Up @@ -83,8 +83,10 @@ def job_queue(job)
end

callbacks do |lifecycle|
# rubocop:disable Performance/MethodObjectAsBlock
lifecycle.around(:enqueue, &method(:instrument_enqueue))
lifecycle.around(:invoke_job, &method(:instrument_invoke))
# rubocop:enable Performance/MethodObjectAsBlock
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'webmock', '~> 3.19'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def complete
@otel_span.status = OpenTelemetry::Trace::Status.error("Request has failed: #{message}")
else
@otel_span.set_attribute('http.status_code', response_code)
@otel_span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(response_code.to_i)
@otel_span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response_code.to_i)
end
ensure
@otel_span&.finish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'yard', '~> 0.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def handle_response(datum)
if datum.key?(:response)
response = datum[:response]
span.set_attribute('http.status_code', response[:status])
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(response[:status].to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response[:status].to_i)
end

span.status = OpenTelemetry::Trace::Status.error("Request has failed: #{datum[:error]}") if datum.key?(:error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def tracer

def trace_response(span, response)
span.set_attribute('http.status_code', response.status)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(response.status.to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response.status.to_i)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def handle_payload_exception(span, exception)
# Only record exceptions if they were not raised (i.e. do not have a status code in Grape)
# or do not have a 5xx status code. These exceptions are recorded by Rack.
# See instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb#L155
return unless exception.respond_to?('status') && ::Rack::Utils.status_code(exception.status) < 500
return unless exception.respond_to?(:status) && ::Rack::Utils.status_code(exception.status) < 500

span.record_exception(exception)
span.status = OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{exception.class}")
Expand Down Expand Up @@ -108,7 +108,7 @@ def formatter_type(formatter)
end

def built_in_grape_formatter?(formatter)
formatter.respond_to?('name') && formatter.name.include?('Grape::Formatter')
formatter.respond_to?(:name) && formatter.name.include?('Grape::Formatter')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/grape/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Helper functions
def uninstall_and_cleanup
instrumentation.instance_variable_set('@installed', false)
instrumentation.instance_variable_set(:@installed, false)
unsubscribe
EXPORTER.reset
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
describe 'compatibility with other tracers' do
let(:config) { { enable_platform_field: true } }

if GraphQL::Tracing.const_defined?('PlatformTrace')
if GraphQL::Tracing.const_defined?(:PlatformTrace)
module CustomPlatformTracer
include ::GraphQL::Tracing::PlatformTrace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers'
spec.add_development_dependency 'rake', '~> 12.3.3'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def annotate_span_with_response!(span, response)

status_code = response.status.to_i
span.set_attribute('http.status_code', status_code)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(status_code.to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(status_code.to_i)
end

def create_request_span_name(request_method, request_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
propagator = OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator
OpenTelemetry.propagation = propagator
# simulate a fresh install:
instrumentation.instance_variable_set('@installed', false)
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(config)
stub_request(:get, 'http://example.com/success').to_return(status: 200)
stub_request(:post, 'http://example.com/failure').to_return(status: 500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def annotate_span_with_response!(span, response)
status_code = response.status_code.to_i

span.set_attribute('http.status_code', status_code)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(status_code.to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(status_code.to_i)
end

def tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(request)
end

def call
@request.on(:response, &method(:finish))
@request.on(:response, &method(:finish)) # rubocop:disable Performance/MethodObjectAsBlock

uri = @request.uri
request_method = @request.verb
Expand Down Expand Up @@ -54,7 +54,7 @@ def finish(response)
@span.status = Trace::Status.error("Unhandled exception of type: #{response.error.class}")
else
@span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, response.status)
@span.status = Trace::Status.error unless (100..399).include?(response.status)
@span.status = Trace::Status.error unless (100..399).cover?(response.status)
end

OpenTelemetry::Context.detach(@trace_token) if @trace_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec-mocks'
spec.add_development_dependency 'rubocop', '~> 1.56.1'
spec.add_development_dependency 'rubocop-performance', '~> 1.19.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'webmock', '~> 3.19'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
Loading

0 comments on commit d6166a0

Please sign in to comment.