Skip to content

Commit

Permalink
rubocop -a --only Style/StringLiterals (#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic authored Aug 16, 2024
1 parent fa0973a commit ec70677
Show file tree
Hide file tree
Showing 33 changed files with 143 additions and 143 deletions.
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def get_trace_propagation_headers
#
# @return [String]
def get_trace_propagation_meta
return '' unless initialized?
return "" unless initialized?
get_current_hub.get_trace_propagation_meta
end

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(bytes: nil, filename: nil, content_type: nil, path: nil)
end

def to_envelope_headers
{ type: 'attachment', filename: filename, content_type: content_type, length: payload.bytesize }
{ type: "attachment", filename: filename, content_type: content_type, length: payload.bytesize }
end

def payload
Expand Down
12 changes: 6 additions & 6 deletions sentry-ruby/lib/sentry/baggage.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'cgi'
require "cgi"

module Sentry
# A {https://www.w3.org/TR/baggage W3C Baggage Header} implementation.
class Baggage
SENTRY_PREFIX = 'sentry-'
SENTRY_PREFIX = "sentry-"
SENTRY_PREFIX_REGEX = /^sentry-/.freeze

# @return [Hash]
Expand All @@ -30,14 +30,14 @@ def self.from_incoming_header(header)
items = {}
mutable = true

header.split(',').each do |item|
header.split(",").each do |item|
item = item.strip
key, val = item.split('=')
key, val = item.split("=")

next unless key && val
next unless key =~ SENTRY_PREFIX_REGEX

baggage_key = key.split('-')[1]
baggage_key = key.split("-")[1]
next unless baggage_key

items[CGI.unescape(baggage_key)] = CGI.unescape(val)
Expand All @@ -64,7 +64,7 @@ def dynamic_sampling_context
# @return [String]
def serialize
items = @items.map { |k, v| "#{SENTRY_PREFIX}#{CGI.escape(k)}=#{CGI.escape(v)}" }
items.join(',')
items.join(",")
end
end
end
12 changes: 6 additions & 6 deletions sentry-ruby/lib/sentry/breadcrumb/sentry_logger.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require 'logger'
require "logger"

module Sentry
class Breadcrumb
module SentryLogger
LEVELS = {
::Logger::DEBUG => 'debug',
::Logger::INFO => 'info',
::Logger::WARN => 'warn',
::Logger::ERROR => 'error',
::Logger::FATAL => 'fatal'
::Logger::DEBUG => "debug",
::Logger::INFO => "info",
::Logger::WARN => "warn",
::Logger::ERROR => "error",
::Logger::FATAL => "fatal"
}.freeze

def add(*args, &block)
Expand Down
8 changes: 4 additions & 4 deletions sentry-ruby/lib/sentry/check_in_event.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'securerandom'
require 'sentry/cron/monitor_config'
require "securerandom"
require "sentry/cron/monitor_config"

module Sentry
class CheckInEvent < Event
TYPE = 'check_in'
TYPE = "check_in"

# uuid to identify this check-in.
# @return [String]
Expand Down Expand Up @@ -43,7 +43,7 @@ def initialize(
self.status = status
self.duration = duration
self.monitor_config = monitor_config
self.check_in_id = check_in_id || SecureRandom.uuid.delete('-')
self.check_in_id = check_in_id || SecureRandom.uuid.delete("-")
end

# @return [Hash]
Expand Down
18 changes: 9 additions & 9 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def initialize(configuration)
else
@transport =
case configuration.dsn&.scheme
when 'http', 'https'
when "http", "https"
HTTPTransport.new(configuration)
else
DummyTransport.new(configuration)
Expand All @@ -49,7 +49,7 @@ def capture_event(event, scope, hint = {})
return unless configuration.sending_allowed?

if event.is_a?(ErrorEvent) && !configuration.sample_allowed?
transport.record_lost_event(:sample_rate, 'error')
transport.record_lost_event(:sample_rate, "error")
return
end

Expand All @@ -64,19 +64,19 @@ def capture_event(event, scope, hint = {})
if event.nil?
log_debug("Discarded event because one of the event processors returned nil")
transport.record_lost_event(:event_processor, data_category)
transport.record_lost_event(:event_processor, 'span', num: spans_before + 1) if is_transaction
transport.record_lost_event(:event_processor, "span", num: spans_before + 1) if is_transaction
return
elsif is_transaction
spans_delta = spans_before - event.spans.size
transport.record_lost_event(:event_processor, 'span', num: spans_delta) if spans_delta > 0
transport.record_lost_event(:event_processor, "span", num: spans_delta) if spans_delta > 0
end

if async_block = configuration.async
dispatch_async_event(async_block, event, hint)
elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true)
unless dispatch_background_event(event, hint)
transport.record_lost_event(:queue_overflow, data_category)
transport.record_lost_event(:queue_overflow, 'span', num: spans_before + 1) if is_transaction
transport.record_lost_event(:queue_overflow, "span", num: spans_before + 1) if is_transaction
end
else
send_event(event, hint)
Expand Down Expand Up @@ -195,13 +195,13 @@ def send_event(event, hint = nil)

if event.nil?
log_debug("Discarded event because before_send_transaction returned nil")
transport.record_lost_event(:before_send, 'transaction')
transport.record_lost_event(:before_send, 'span', num: spans_before + 1)
transport.record_lost_event(:before_send, "transaction")
transport.record_lost_event(:before_send, "span", num: spans_before + 1)
return
else
spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
spans_delta = spans_before - spans_after
transport.record_lost_event(:before_send, 'span', num: spans_delta) if spans_delta > 0
transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0
end
end

Expand All @@ -212,7 +212,7 @@ def send_event(event, hint = nil)
rescue => e
log_error("Event sending failed", e, debug: configuration.debug)
transport.record_lost_event(:network_error, data_category)
transport.record_lost_event(:network_error, 'span', num: spans_before + 1) if event.is_a?(TransactionEvent)
transport.record_lost_event(:network_error, "span", num: spans_before + 1) if event.is_a?(TransactionEvent)
raise
end

Expand Down
22 changes: 11 additions & 11 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "concurrent/utility/processor_counter"

require "sentry/utils/exception_cause_chain"
require 'sentry/utils/custom_inspection'
require "sentry/utils/custom_inspection"
require "sentry/dsn"
require "sentry/release_detector"
require "sentry/transport/configuration"
Expand Down Expand Up @@ -302,18 +302,18 @@ def capture_exception_frame_locals=(value)
# But they are mostly considered as noise and should be ignored by default
# Please see https://github.com/getsentry/sentry-ruby/pull/2026 for more information
PUMA_IGNORE_DEFAULT = [
'Puma::MiniSSL::SSLError',
'Puma::HttpParserError',
'Puma::HttpParserError501'
"Puma::MiniSSL::SSLError",
"Puma::HttpParserError",
"Puma::HttpParserError501"
].freeze

# Most of these errors generate 4XX responses. In general, Sentry clients
# only automatically report 5xx responses.
IGNORE_DEFAULT = [
'Mongoid::Errors::DocumentNotFound',
'Rack::QueryParser::InvalidParameterError',
'Rack::QueryParser::ParameterTypeError',
'Sinatra::NotFound'
"Mongoid::Errors::DocumentNotFound",
"Rack::QueryParser::InvalidParameterError",
"Rack::QueryParser::ParameterTypeError",
"Sinatra::NotFound"
].freeze

RACK_ENV_WHITELIST_DEFAULT = %w[
Expand Down Expand Up @@ -376,7 +376,7 @@ def initialize
self.auto_session_tracking = true
self.enable_backpressure_handling = false
self.trusted_proxies = []
self.dsn = ENV['SENTRY_DSN']
self.dsn = ENV["SENTRY_DSN"]
self.spotlight = false
self.server_name = server_name_from_env
self.instrumenter = :sentry
Expand Down Expand Up @@ -632,12 +632,12 @@ def valid?
end

def environment_from_env
ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
ENV["SENTRY_CURRENT_ENV"] || ENV["SENTRY_ENVIRONMENT"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
end

def server_name_from_env
if running_on_heroku?
ENV['DYNO']
ENV["DYNO"]
else
# Try to resolve the hostname to an FQDN, but fall back to whatever
# the load name is.
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return if Object.method_defined?(:deep_dup)

require 'sentry/core_ext/object/duplicable'
require "sentry/core_ext/object/duplicable"

#########################################
# This file was copied from Rails 5.2 #
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/cron/monitor_check_ins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def sentry_monitor_check_ins(slug: nil, monitor_config: nil)

def sentry_monitor_slug(name: self.name)
@sentry_monitor_slug ||= begin
slug = name.gsub('::', '-').downcase
slug = name.gsub("::", "-").downcase
slug[-MAX_SLUG_LENGTH..-1] || slug
end
end
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/cron/monitor_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'sentry/cron/monitor_schedule'
require "sentry/cron/monitor_schedule"

module Sentry
module Cron
Expand Down
6 changes: 3 additions & 3 deletions sentry-ruby/lib/sentry/dsn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Sentry
class DSN
PORT_MAP = { 'http' => 80, 'https' => 443 }.freeze
PORT_MAP = { "http" => 80, "https" => 443 }.freeze
REQUIRED_ATTRIBUTES = %w[host path public_key project_id].freeze

attr_reader :scheme, :secret_key, :port, *REQUIRED_ATTRIBUTES
Expand All @@ -13,7 +13,7 @@ def initialize(dsn_string)
@raw_value = dsn_string

uri = URI.parse(dsn_string)
uri_path = uri.path.split('/')
uri_path = uri.path.split("/")

if uri.user
# DSN-style string
Expand All @@ -25,7 +25,7 @@ def initialize(dsn_string)
@scheme = uri.scheme
@host = uri.host
@port = uri.port if uri.port
@path = uri_path.join('/')
@path = uri_path.join("/")
end

def valid?
Expand Down
16 changes: 8 additions & 8 deletions sentry-ruby/lib/sentry/envelope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ def initialize(headers, payload)
end

def type
@headers[:type] || 'event'
@headers[:type] || "event"
end

# rate limits and client reports use the data_category rather than envelope item type
def self.data_category(type)
case type
when 'session', 'attachment', 'transaction', 'profile', 'span' then type
when 'sessions' then 'session'
when 'check_in' then 'monitor'
when 'statsd', 'metric_meta' then 'metric_bucket'
when 'event' then 'error'
when 'client_report' then 'internal'
else 'default'
when "session", "attachment", "transaction", "profile", "span" then type
when "sessions" then "session"
when "check_in" then "monitor"
when "statsd", "metric_meta" then "metric_bucket"
when "event" then "error"
when "client_report" then "internal"
else "default"
end
end

Expand Down
14 changes: 7 additions & 7 deletions sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'socket'
require 'securerandom'
require 'sentry/interface'
require 'sentry/backtrace'
require 'sentry/utils/real_ip'
require 'sentry/utils/request_id'
require 'sentry/utils/custom_inspection'
require "socket"
require "securerandom"
require "sentry/interface"
require "sentry/backtrace"
require "sentry/utils/real_ip"
require "sentry/utils/request_id"
require "sentry/utils/custom_inspection"

module Sentry
# This is an abstract class that defines the shared attributes of an event.
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
if defined?(::GraphQL::Schema) && defined?(::GraphQL::Tracing::SentryTrace) && ::GraphQL::Schema.respond_to?(:trace_with)
::GraphQL::Schema.trace_with(::GraphQL::Tracing::SentryTrace, set_transaction_name: true)
else
config.logger.warn(Sentry::LOGGER_PROGNAME) { 'You tried to enable the GraphQL integration but no GraphQL gem was detected. Make sure you have the `graphql` gem (>= 2.2.6) in your Gemfile.' }
config.logger.warn(Sentry::LOGGER_PROGNAME) { "You tried to enable the GraphQL integration but no GraphQL gem was detected. Make sure you have the `graphql` gem (>= 2.2.6) in your Gemfile." }
end
end
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/interfaces/mechanism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Mechanism < Interface
# @return [Boolean]
attr_accessor :handled

def initialize(type: 'generic', handled: true)
def initialize(type: "generic", handled: true)
@type = type
@handled = handled
end
Expand Down
10 changes: 5 additions & 5 deletions sentry-ruby/lib/sentry/interfaces/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(env:, send_default_pii:, rack_env_whitelist:)
self.query_string = request.query_string
end

self.url = request.scheme && request.url.split('?').first
self.url = request.scheme && request.url.split("?").first
self.method = request.request_method

self.headers = filter_and_format_headers(env, send_default_pii)
Expand All @@ -85,14 +85,14 @@ def filter_and_format_headers(env, send_default_pii)
env.each_with_object({}) do |(key, value), memo|
begin
key = key.to_s # rack env can contain symbols
next memo['X-Request-Id'] ||= Utils::RequestId.read_from(env) if Utils::RequestId::REQUEST_ID_HEADERS.include?(key)
next memo["X-Request-Id"] ||= Utils::RequestId.read_from(env) if Utils::RequestId::REQUEST_ID_HEADERS.include?(key)
next if is_server_protocol?(key, value, env["SERVER_PROTOCOL"])
next if is_skippable_header?(key)
next if key == "HTTP_AUTHORIZATION" && !send_default_pii

# Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
key = key.sub(/^HTTP_/, "")
key = key.split('_').map(&:capitalize).join('-')
key = key.split("_").map(&:capitalize).join("-")

memo[key] = Utils::EncodingHelper.encode_to_utf_8(value.to_s)
rescue StandardError => e
Expand All @@ -108,7 +108,7 @@ def filter_and_format_headers(env, send_default_pii)
def is_skippable_header?(key)
key.upcase != key || # lower-case envs aren't real http headers
key == "HTTP_COOKIE" || # Cookies don't go here, they go somewhere else
!(key.start_with?('HTTP_') || CONTENT_HEADERS.include?(key))
!(key.start_with?("HTTP_") || CONTENT_HEADERS.include?(key))
end

# In versions < 3, Rack adds in an incorrect HTTP_VERSION key, which causes downstream
Expand All @@ -120,7 +120,7 @@ def is_server_protocol?(key, value, protocol_version)
rack_version = Gem::Version.new(::Rack.release)
return false if rack_version >= Gem::Version.new("3.0")

key == 'HTTP_VERSION' && value == protocol_version
key == "HTTP_VERSION" && value == protocol_version
end

def filter_and_format_env(env, rack_env_whitelist)
Expand Down
Loading

0 comments on commit ec70677

Please sign in to comment.