Skip to content

Commit

Permalink
Unsafe Rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Nov 22, 2023
1 parent f50ce57 commit 19e3370
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 16 deletions.
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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -78,7 +78,7 @@ def annotate_span_with_response!(span, response)
status_code = response.code.to_i

span.set_attribute(OpenTelemetry::SemanticConventions::Trace::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 @@ -150,7 +150,7 @@ def create_request_span_name(request_uri_or_path_info, env)
end

def set_attributes_after_request(span, status, headers, _response)
span.status = OpenTelemetry::Trace::Status.error unless (100..499).include?(status.to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..499).cover?(status.to_i)
span.set_attribute('http.status_code', status)

# NOTE: if data is available, it would be good to do this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def trace_request
# If so, add additional attributes.
if response.is_a?(::RestClient::Response)
span.set_attribute('http.status_code', response.code)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(response.code.to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response.code.to_i)
end
end
rescue ::RestClient::ExceptionWithResponse => e
span.set_attribute('http.status_code', e.http_code)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(e.http_code.to_i)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(e.http_code.to_i)

raise e
ensure
Expand Down

0 comments on commit 19e3370

Please sign in to comment.