Skip to content

Commit

Permalink
Safe Rubocop performance autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Nov 22, 2023
1 parent cc8b3c0 commit f50ce57
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 23 deletions.
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 @@ -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 @@ -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
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
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 @@ -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 @@ -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 @@ -346,7 +346,7 @@
client.query('SELECT 1')

_(span.attributes['net.peer.name']).must_equal host
_(span.attributes['net.peer.port']).must_equal port.to_i if PG.const_defined?('DEF_PORT')
_(span.attributes['net.peer.port']).must_equal port.to_i if PG.const_defined?(:DEF_PORT)
end
end
end unless ENV['OMIT_SERVICES']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def self.call(job, &block)
OpenTelemetry::Context.with_current(extracted_context) do
if otel_config[:propagation_style] == :child
tracer.in_span(span_name, attributes: attributes, kind: :consumer) do |span|
block.call
yield
enhance_span_after_job_completion(span, job)
end
else
span_links = otel_config[:propagation_style] == :link ? prepare_span_links(extracted_context) : []

root_span = tracer.start_root_span(span_name, attributes: attributes, links: span_links, kind: :consumer)
OpenTelemetry::Trace.with_span(root_span) do |span|
block.call
yield
enhance_span_after_job_completion(span, job)
ensure
root_span.finish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

before do
# simulate a fresh install:
instrumentation.instance_variable_set('@installed', false)
instrumentation.instance_variable_set(:@installed, false)
instrumentation.config.clear
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
exporter.reset

# simulate a fresh install:
instrumentation.instance_variable_set('@installed', false)
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(config)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
exporter.reset

# simulate a fresh install:
instrumentation.instance_variable_set('@installed', false)
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(config)

# clear out cached config:
Expand All @@ -49,7 +49,7 @@

after do
# installation is 'global', so it should be reset:
instrumentation.instance_variable_set('@installed', false)
instrumentation.instance_variable_set(:@installed, false)
instrumentation.install(default_config)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class OpenTelemetry::Instrumentation::Rails::RailtieTest < ActiveSupport::TestCa
include OpenTelemetry::SemanticConventions

setup do
OpenTelemetry::Instrumentation.registry.instance_variable_get('@instrumentation').each do |i|
i.instance_variable_set('@instance', nil)
OpenTelemetry::Instrumentation.registry.instance_variable_get(:@instrumentation).each do |i|
i.instance_variable_set(:@instance, nil)
end
OpenTelemetry::SDK::Resources::Resource.instance_variable_set('@default', nil)
OpenTelemetry::SDK::Resources::Resource.instance_variable_set(:@default, nil)
OpenTelemetry.tracer_provider = OpenTelemetry::Internal::ProxyTracerProvider.new
end

test 'configures a default instance of the SDK' do
OpenTelemetry::TestHelpers.with_env('OTEL_SERVICE_NAME' => nil) do
run_initializer
assert_instance_of(OpenTelemetry::SDK::Trace::TracerProvider, OpenTelemetry.tracer_provider)
assert_same(Rails.logger, OpenTelemetry.logger.instance_variable_get('@logger'))
assert_same(Rails.logger, OpenTelemetry.logger.instance_variable_get(:@logger))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def set_baggage(carrier:, context:, getter:)
getter.keys(carrier).each do |carrier_key|
baggage_key = carrier_key.start_with?(prefix) && carrier_key[prefix.length..-1]
next unless baggage_key
next unless VALID_BAGGAGE_HEADER_NAME_CHARS =~ baggage_key
next unless VALID_BAGGAGE_HEADER_NAME_CHARS.match?(baggage_key)

value = getter.get(carrier, carrier_key)
next unless INVALID_BAGGAGE_HEADER_VALUE_CHARS !~ value
next if INVALID_BAGGAGE_HEADER_VALUE_CHARS.match?(value)

builder.set_value(baggage_key, value)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def to_trace_flags(sampling_state)
def to_trace_state(trace_state)
return nil unless trace_state

Trace::Tracestate.from_string(trace_state.gsub(';', ','))
Trace::Tracestate.from_string(trace_state.tr(';', ','))
end
end
end
Expand Down

0 comments on commit f50ce57

Please sign in to comment.