Skip to content

Commit

Permalink
Fix rubocop setup (for some envs) (#2377)
Browse files Browse the repository at this point in the history
* Fix rubocop setup (for some envs)

This makes it possible to use rubocop when working from inside a subdir.
It also fixes running rubocop from the root where it would actually use
the config that we have. Previously it would ignore it for some reason,
symlinking did the trick.

The rubocop-packaging was needed because something somewhere tries to
require it.

* [sentry-opentelemetry] rubocop -a --only Style/StringLiterals

* [sentry-rails] rubocop -a --only Style/StringLiterals

* [sentry-resque] rubocop -a --only Style/StringLiterals

* [sentry-sidekiq] rubocop -a --only Style/StringLiterals
  • Loading branch information
solnic authored Aug 16, 2024
1 parent ec70677 commit 5c26b9e
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Layout/SpaceInsideArrayLiteralBrackets:

AllCops:
Exclude:
- 'sentry-raven/**/*'
- "sentry-raven/**/*"
- "sentry-*/tmp/**/*"
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ gem "simplecov-cobertura", "~> 1.4"
gem "rexml"

gem "rubocop-rails-omakase"
gem "rubocop-packaging"
1 change: 1 addition & 0 deletions sentry-delayed_job/.rubocop.yml
1 change: 1 addition & 0 deletions sentry-opentelemetry/.rubocop.yml
8 changes: 4 additions & 4 deletions sentry-opentelemetry/lib/sentry/opentelemetry/propagator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module OpenTelemetry
class Propagator
FIELDS = [SENTRY_TRACE_HEADER_NAME, BAGGAGE_HEADER_NAME].freeze

SENTRY_TRACE_KEY = ::OpenTelemetry::Context.create_key('sentry-trace')
SENTRY_BAGGAGE_KEY = ::OpenTelemetry::Context.create_key('sentry-baggage')
SENTRY_TRACE_KEY = ::OpenTelemetry::Context.create_key("sentry-trace")
SENTRY_BAGGAGE_KEY = ::OpenTelemetry::Context.create_key("sentry-baggage")

def inject(
carrier,
Expand Down Expand Up @@ -41,8 +41,8 @@ def extract(
trace_id, span_id, _parent_sampled = sentry_trace_data

span_context = ::OpenTelemetry::Trace::SpanContext.new(
trace_id: [trace_id].pack('H*'),
span_id: [span_id].pack('H*'),
trace_id: [trace_id].pack("H*"),
span_id: [span_id].pack("H*"),
# we simulate a sampled trace on the otel side and leave the sampling to sentry
trace_flags: ::OpenTelemetry::Trace::TraceFlags::SAMPLED,
remote: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'singleton'
require "singleton"

module Sentry
module OpenTelemetry
Expand Down Expand Up @@ -151,14 +151,14 @@ def update_span_status(sentry_span, otel_span)
if (http_status_code = otel_span.attributes[SEMANTIC_CONVENTIONS::HTTP_STATUS_CODE])
sentry_span.set_http_status(http_status_code)
elsif (status_code = otel_span.status.code)
status = [0, 1].include?(status_code) ? 'ok' : 'unknown_error'
status = [0, 1].include?(status_code) ? "ok" : "unknown_error"
sentry_span.set_status(status)
end
end

def update_span_with_otel_data(sentry_span, otel_span)
update_span_status(sentry_span, otel_span)
sentry_span.set_data('otel.kind', otel_span.kind)
sentry_span.set_data("otel.kind", otel_span.kind)
otel_span.attributes&.each { |k, v| sentry_span.set_data(k, v) }

op, description = parse_span_description(otel_span)
Expand Down
1 change: 1 addition & 0 deletions sentry-rails/.rubocop.yml
2 changes: 1 addition & 1 deletion sentry-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemspec
gem "sentry-ruby", path: "../sentry-ruby"

platform :jruby do
gem 'activerecord-jdbcmysql-adapter'
gem "activerecord-jdbcmysql-adapter"
gem "jdbc-sqlite3"
end

Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Sentry
module Rails
class CaptureExceptions < Sentry::Rack::CaptureExceptions
RAILS_7_1 = Gem::Version.new(::Rails.version) >= Gem::Version.new("7.1.0.alpha")
SPAN_ORIGIN = 'auto.http.rails'.freeze
SPAN_ORIGIN = "auto.http.rails".freeze

def initialize(_)
super
Expand Down
28 changes: 14 additions & 14 deletions sentry-rails/lib/sentry/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ class Configuration

module Rails
IGNORE_DEFAULT = [
'AbstractController::ActionNotFound',
'ActionController::BadRequest',
'ActionController::InvalidAuthenticityToken',
'ActionController::InvalidCrossOriginRequest',
'ActionController::MethodNotAllowed',
'ActionController::NotImplemented',
'ActionController::ParameterMissing',
'ActionController::RoutingError',
'ActionController::UnknownAction',
'ActionController::UnknownFormat',
'ActionDispatch::Http::MimeNegotiation::InvalidType',
'ActionController::UnknownHttpMethod',
'ActionDispatch::Http::Parameters::ParseError',
'ActiveRecord::RecordNotFound'
"AbstractController::ActionNotFound",
"ActionController::BadRequest",
"ActionController::InvalidAuthenticityToken",
"ActionController::InvalidCrossOriginRequest",
"ActionController::MethodNotAllowed",
"ActionController::NotImplemented",
"ActionController::ParameterMissing",
"ActionController::RoutingError",
"ActionController::UnknownAction",
"ActionController::UnknownFormat",
"ActionDispatch::Http::MimeNegotiation::InvalidType",
"ActionController::UnknownHttpMethod",
"ActionDispatch::Http::Parameters::ParseError",
"ActiveRecord::RecordNotFound"
].freeze

ACTIVE_SUPPORT_LOGGER_SUBSCRIPTION_ITEMS_DEFAULT = {
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/controller_transaction.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Sentry
module Rails
module ControllerTransaction
SPAN_ORIGIN = 'auto.view.rails'.freeze
SPAN_ORIGIN = "auto.view.rails".freeze

def self.included(base)
base.prepend_around_action(:sentry_around_action)
Expand Down
4 changes: 2 additions & 2 deletions sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def patch_background_worker

def inject_breadcrumbs_logger
if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
require 'sentry/rails/breadcrumb/active_support_logger'
require "sentry/rails/breadcrumb/active_support_logger"
Sentry::Rails::Breadcrumb::ActiveSupportLogger.inject(Sentry.configuration.rails.active_support_logger_subscription_items)
end

if Sentry.configuration.breadcrumbs_logger.include?(:monotonic_active_support_logger)
return warn "Usage of `monotonic_active_support_logger` require a version of Rails >= 6.1, please upgrade your Rails version or use another logger" if ::Rails.version.to_f < 6.1

require 'sentry/rails/breadcrumb/monotonic_active_support_logger'
require "sentry/rails/breadcrumb/monotonic_active_support_logger"
Sentry::Rails::Breadcrumb::MonotonicActiveSupportLogger.inject
end
end
Expand Down
1 change: 1 addition & 0 deletions sentry-resque/.rubocop.yml
8 changes: 4 additions & 4 deletions sentry-resque/lib/sentry/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def record(queue, worker, payload, &block)

finish_transaction(transaction, 200)
rescue Exception => exception
klass = if payload['class'].respond_to?(:constantize)
payload['class'].constantize
klass = if payload["class"].respond_to?(:constantize)
payload["class"].constantize
else
Object.const_get(payload['class'])
Object.const_get(payload["class"])
end

raise if Sentry.configuration.resque.report_after_job_retries &&
defined?(::Resque::Plugins::Retry) == 'constant' &&
defined?(::Resque::Plugins::Retry) == "constant" &&
klass.is_a?(::Resque::Plugins::Retry) &&
!klass.retry_limit_reached?

Expand Down
1 change: 1 addition & 0 deletions sentry-sidekiq/.rubocop.yml
2 changes: 1 addition & 1 deletion sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'sentry/sidekiq/context_filter'
require "sentry/sidekiq/context_filter"

module Sentry
module Sidekiq
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'sentry/sidekiq/context_filter'
require "sentry/sidekiq/context_filter"

module Sentry
module Sidekiq
Expand Down

0 comments on commit 5c26b9e

Please sign in to comment.