From ec7067790062786f4877400f6d18b54ed50669f2 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Fri, 16 Aug 2024 13:01:12 +0200 Subject: [PATCH] rubocop -a --only Style/StringLiterals (#2373) --- sentry-ruby/lib/sentry-ruby.rb | 2 +- sentry-ruby/lib/sentry/attachment.rb | 2 +- sentry-ruby/lib/sentry/baggage.rb | 12 ++++---- .../lib/sentry/breadcrumb/sentry_logger.rb | 12 ++++---- sentry-ruby/lib/sentry/check_in_event.rb | 8 ++--- sentry-ruby/lib/sentry/client.rb | 18 +++++------ sentry-ruby/lib/sentry/configuration.rb | 22 +++++++------- .../lib/sentry/core_ext/object/deep_dup.rb | 2 +- .../lib/sentry/cron/monitor_check_ins.rb | 2 +- sentry-ruby/lib/sentry/cron/monitor_config.rb | 2 +- sentry-ruby/lib/sentry/dsn.rb | 6 ++-- sentry-ruby/lib/sentry/envelope.rb | 16 +++++----- sentry-ruby/lib/sentry/event.rb | 14 ++++----- sentry-ruby/lib/sentry/graphql.rb | 2 +- .../lib/sentry/interfaces/mechanism.rb | 2 +- sentry-ruby/lib/sentry/interfaces/request.rb | 10 +++---- .../lib/sentry/interfaces/single_exception.rb | 2 +- sentry-ruby/lib/sentry/logger.rb | 2 +- sentry-ruby/lib/sentry/metrics.rb | 30 +++++++++---------- sentry-ruby/lib/sentry/metrics/aggregator.rb | 24 +++++++-------- sentry-ruby/lib/sentry/metrics/set_metric.rb | 4 +-- sentry-ruby/lib/sentry/profiler.rb | 30 +++++++++---------- sentry-ruby/lib/sentry/rack.rb | 4 +-- .../lib/sentry/rack/capture_exceptions.rb | 2 +- sentry-ruby/lib/sentry/rake.rb | 4 +-- sentry-ruby/lib/sentry/release_detector.rb | 8 ++--- sentry-ruby/lib/sentry/session_flusher.rb | 2 +- sentry-ruby/lib/sentry/test_helper.rb | 2 +- sentry-ruby/lib/sentry/transaction.rb | 4 +-- sentry-ruby/lib/sentry/transaction_event.rb | 2 +- sentry-ruby/lib/sentry/transport.rb | 8 ++--- .../lib/sentry/transport/http_transport.rb | 24 +++++++-------- sentry-ruby/lib/sentry/utils/real_ip.rb | 2 +- 33 files changed, 143 insertions(+), 143 deletions(-) diff --git a/sentry-ruby/lib/sentry-ruby.rb b/sentry-ruby/lib/sentry-ruby.rb index 358a7c329..734bc2cc9 100644 --- a/sentry-ruby/lib/sentry-ruby.rb +++ b/sentry-ruby/lib/sentry-ruby.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/attachment.rb b/sentry-ruby/lib/sentry/attachment.rb index f40971599..71a2b2b76 100644 --- a/sentry-ruby/lib/sentry/attachment.rb +++ b/sentry-ruby/lib/sentry/attachment.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/baggage.rb b/sentry-ruby/lib/sentry/baggage.rb index d766e999d..2b375a846 100644 --- a/sentry-ruby/lib/sentry/baggage.rb +++ b/sentry-ruby/lib/sentry/baggage.rb @@ -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] @@ -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) @@ -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 diff --git a/sentry-ruby/lib/sentry/breadcrumb/sentry_logger.rb b/sentry-ruby/lib/sentry/breadcrumb/sentry_logger.rb index 455535f01..4d94e513a 100644 --- a/sentry-ruby/lib/sentry/breadcrumb/sentry_logger.rb +++ b/sentry-ruby/lib/sentry/breadcrumb/sentry_logger.rb @@ -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) diff --git a/sentry-ruby/lib/sentry/check_in_event.rb b/sentry-ruby/lib/sentry/check_in_event.rb index 7a10872b5..91ae17dc3 100644 --- a/sentry-ruby/lib/sentry/check_in_event.rb +++ b/sentry-ruby/lib/sentry/check_in_event.rb @@ -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] @@ -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] diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 6176508b7..9d48ee301 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -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) @@ -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 @@ -64,11 +64,11 @@ 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 @@ -76,7 +76,7 @@ def capture_event(event, scope, 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) @@ -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 @@ -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 diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index 480172a88..44ea574b4 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -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" @@ -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[ @@ -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 @@ -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. diff --git a/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb b/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb index d1141f128..2cc0d47f6 100644 --- a/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb +++ b/sentry-ruby/lib/sentry/core_ext/object/deep_dup.rb @@ -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 # diff --git a/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb b/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb index b7eee3f5f..ac7e35d81 100644 --- a/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb +++ b/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/cron/monitor_config.rb b/sentry-ruby/lib/sentry/cron/monitor_config.rb index 68b8c709c..dfd28a4bd 100644 --- a/sentry-ruby/lib/sentry/cron/monitor_config.rb +++ b/sentry-ruby/lib/sentry/cron/monitor_config.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'sentry/cron/monitor_schedule' +require "sentry/cron/monitor_schedule" module Sentry module Cron diff --git a/sentry-ruby/lib/sentry/dsn.rb b/sentry-ruby/lib/sentry/dsn.rb index b05ace531..3877b57fb 100644 --- a/sentry-ruby/lib/sentry/dsn.rb +++ b/sentry-ruby/lib/sentry/dsn.rb @@ -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 @@ -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 @@ -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? diff --git a/sentry-ruby/lib/sentry/envelope.rb b/sentry-ruby/lib/sentry/envelope.rb index 51220a062..4e1d8acb2 100644 --- a/sentry-ruby/lib/sentry/envelope.rb +++ b/sentry-ruby/lib/sentry/envelope.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/event.rb b/sentry-ruby/lib/sentry/event.rb index 7fbd6172c..154452599 100644 --- a/sentry-ruby/lib/sentry/event.rb +++ b/sentry-ruby/lib/sentry/event.rb @@ -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. diff --git a/sentry-ruby/lib/sentry/graphql.rb b/sentry-ruby/lib/sentry/graphql.rb index 17bb792c6..645481a4d 100644 --- a/sentry-ruby/lib/sentry/graphql.rb +++ b/sentry-ruby/lib/sentry/graphql.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/interfaces/mechanism.rb b/sentry-ruby/lib/sentry/interfaces/mechanism.rb index 95179a77a..df672e7d9 100644 --- a/sentry-ruby/lib/sentry/interfaces/mechanism.rb +++ b/sentry-ruby/lib/sentry/interfaces/mechanism.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/interfaces/request.rb b/sentry-ruby/lib/sentry/interfaces/request.rb index 519f7859a..4647e6562 100644 --- a/sentry-ruby/lib/sentry/interfaces/request.rb +++ b/sentry-ruby/lib/sentry/interfaces/request.rb @@ -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) @@ -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 @@ -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 @@ -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) diff --git a/sentry-ruby/lib/sentry/interfaces/single_exception.rb b/sentry-ruby/lib/sentry/interfaces/single_exception.rb index d35491206..f7126e702 100644 --- a/sentry-ruby/lib/sentry/interfaces/single_exception.rb +++ b/sentry-ruby/lib/sentry/interfaces/single_exception.rb @@ -26,7 +26,7 @@ def initialize(exception:, mechanism:, stacktrace: nil) @value = Utils::EncodingHelper.encode_to_utf_8(exception_message.byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES)) - @module = exception.class.to_s.split('::')[0...-1].join('::') + @module = exception.class.to_s.split("::")[0...-1].join("::") @thread_id = Thread.current.object_id @stacktrace = stacktrace @mechanism = mechanism diff --git a/sentry-ruby/lib/sentry/logger.rb b/sentry-ruby/lib/sentry/logger.rb index 7f910d86e..b0e65f442 100644 --- a/sentry-ruby/lib/sentry/logger.rb +++ b/sentry-ruby/lib/sentry/logger.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'logger' +require "logger" module Sentry class Logger < ::Logger diff --git a/sentry-ruby/lib/sentry/metrics.rb b/sentry-ruby/lib/sentry/metrics.rb index 99bd9f7f1..bcab324f4 100644 --- a/sentry-ruby/lib/sentry/metrics.rb +++ b/sentry-ruby/lib/sentry/metrics.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'sentry/metrics/metric' -require 'sentry/metrics/counter_metric' -require 'sentry/metrics/distribution_metric' -require 'sentry/metrics/gauge_metric' -require 'sentry/metrics/set_metric' -require 'sentry/metrics/timing' -require 'sentry/metrics/aggregator' +require "sentry/metrics/metric" +require "sentry/metrics/counter_metric" +require "sentry/metrics/distribution_metric" +require "sentry/metrics/gauge_metric" +require "sentry/metrics/set_metric" +require "sentry/metrics/timing" +require "sentry/metrics/aggregator" module Sentry module Metrics @@ -14,32 +14,32 @@ module Metrics INFORMATION_UNITS = %w[bit byte kilobyte kibibyte megabyte mebibyte gigabyte gibibyte terabyte tebibyte petabyte pebibyte exabyte exbibyte] FRACTIONAL_UNITS = %w[ratio percent] - OP_NAME = 'metric.timing' - SPAN_ORIGIN = 'auto.metric.timing' + OP_NAME = "metric.timing" + SPAN_ORIGIN = "auto.metric.timing" class << self - def increment(key, value = 1.0, unit: 'none', tags: {}, timestamp: nil) + def increment(key, value = 1.0, unit: "none", tags: {}, timestamp: nil) Sentry.metrics_aggregator&.add(:c, key, value, unit: unit, tags: tags, timestamp: timestamp) end - def distribution(key, value, unit: 'none', tags: {}, timestamp: nil) + def distribution(key, value, unit: "none", tags: {}, timestamp: nil) Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp) end - def set(key, value, unit: 'none', tags: {}, timestamp: nil) + def set(key, value, unit: "none", tags: {}, timestamp: nil) Sentry.metrics_aggregator&.add(:s, key, value, unit: unit, tags: tags, timestamp: timestamp) end - def gauge(key, value, unit: 'none', tags: {}, timestamp: nil) + def gauge(key, value, unit: "none", tags: {}, timestamp: nil) Sentry.metrics_aggregator&.add(:g, key, value, unit: unit, tags: tags, timestamp: timestamp) end - def timing(key, unit: 'second', tags: {}, timestamp: nil, &block) + def timing(key, unit: "second", tags: {}, timestamp: nil, &block) return unless block_given? return yield unless DURATION_UNITS.include?(unit) result, value = Sentry.with_child_span(op: OP_NAME, description: key, origin: SPAN_ORIGIN) do |span| - tags.each { |k, v| span.set_tag(k, v.is_a?(Array) ? v.join(', ') : v.to_s) } if span + tags.each { |k, v| span.set_tag(k, v.is_a?(Array) ? v.join(", ") : v.to_s) } if span start = Timing.send(unit.to_sym) result = yield diff --git a/sentry-ruby/lib/sentry/metrics/aggregator.rb b/sentry-ruby/lib/sentry/metrics/aggregator.rb index 45ffbd687..12ad54f69 100644 --- a/sentry-ruby/lib/sentry/metrics/aggregator.rb +++ b/sentry-ruby/lib/sentry/metrics/aggregator.rb @@ -41,8 +41,8 @@ def initialize(configuration, client) @stacktrace_builder = configuration.stacktrace_builder @default_tags = {} - @default_tags['release'] = configuration.release if configuration.release - @default_tags['environment'] = configuration.environment if configuration.environment + @default_tags["release"] = configuration.release if configuration.release + @default_tags["environment"] = configuration.environment if configuration.environment @mutex = Mutex.new @@ -59,7 +59,7 @@ def initialize(configuration, client) def add(type, key, value, - unit: 'none', + unit: "none", tags: {}, timestamp: nil, stacklevel: nil) @@ -98,7 +98,7 @@ def flush(force: false) unless flushable_buckets.empty? payload = serialize_buckets(flushable_buckets) envelope.add_item( - { type: 'statsd', length: payload.bytesize }, + { type: "statsd", length: payload.bytesize }, payload ) end @@ -107,7 +107,7 @@ def flush(force: false) code_locations.each do |timestamp, locations| payload = serialize_locations(timestamp, locations) envelope.add_item( - { type: 'metric_meta', content_type: 'application/json' }, + { type: "metric_meta", content_type: "application/json" }, payload ) end @@ -161,8 +161,8 @@ def serialize_buckets(buckets) buckets.map do |timestamp, timestamp_buckets| timestamp_buckets.map do |metric_key, metric| type, key, unit, tags = metric_key - values = metric.serialize.join(':') - sanitized_tags = tags.map { |k, v| "#{sanitize_tag_key(k)}:#{sanitize_tag_value(v)}" }.join(',') + values = metric.serialize.join(":") + sanitized_tags = tags.map { |k, v| "#{sanitize_tag_key(k)}:#{sanitize_tag_value(v)}" }.join(",") "#{sanitize_key(key)}@#{sanitize_unit(unit)}:#{values}|#{type}|\##{sanitized_tags}|T#{timestamp}" end @@ -175,22 +175,22 @@ def serialize_locations(timestamp, locations) mri = "#{type}:#{sanitize_key(key)}@#{sanitize_unit(unit)}" # note this needs to be an array but it really doesn't serve a purpose right now - [mri, [location.merge(type: 'location')]] + [mri, [location.merge(type: "location")]] end.to_h { timestamp: timestamp, mapping: mapping } end def sanitize_key(key) - key.gsub(KEY_SANITIZATION_REGEX, '_') + key.gsub(KEY_SANITIZATION_REGEX, "_") end def sanitize_unit(unit) - unit.gsub(UNIT_SANITIZATION_REGEX, '') + unit.gsub(UNIT_SANITIZATION_REGEX, "") end def sanitize_tag_key(key) - key.gsub(TAG_KEY_SANITIZATION_REGEX, '') + key.gsub(TAG_KEY_SANITIZATION_REGEX, "") end def sanitize_tag_value(value) @@ -209,7 +209,7 @@ def get_updated_tags(tags) updated_tags = @default_tags.merge(tags) transaction_name = get_transaction_name - updated_tags['transaction'] = transaction_name if transaction_name + updated_tags["transaction"] = transaction_name if transaction_name updated_tags end diff --git a/sentry-ruby/lib/sentry/metrics/set_metric.rb b/sentry-ruby/lib/sentry/metrics/set_metric.rb index 02c5c26a6..b38af2743 100644 --- a/sentry-ruby/lib/sentry/metrics/set_metric.rb +++ b/sentry-ruby/lib/sentry/metrics/set_metric.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'set' -require 'zlib' +require "set" +require "zlib" module Sentry module Metrics diff --git a/sentry-ruby/lib/sentry/profiler.rb b/sentry-ruby/lib/sentry/profiler.rb index 949a9aecb..cec7c70ce 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'securerandom' +require "securerandom" module Sentry class Profiler - VERSION = '1' - PLATFORM = 'ruby' + VERSION = "1" + PLATFORM = "ruby" # 101 Hz in microseconds DEFAULT_INTERVAL = 1e6 / 101 MICRO_TO_NANO_SECONDS = 1e3 @@ -14,7 +14,7 @@ class Profiler attr_reader :sampled, :started, :event_id def initialize(configuration) - @event_id = SecureRandom.uuid.delete('-') + @event_id = SecureRandom.uuid.delete("-") @started = false @sampled = nil @@ -33,7 +33,7 @@ def start raw: true, aggregate: false) - @started ? log('Started') : log('Not started since running elsewhere') + @started ? log("Started") : log("Not started since running elsewhere") end def stop @@ -41,7 +41,7 @@ def stop return unless @started StackProf.stop - log('Stopped') + log("Stopped") end # Sets initial sampling decision of the profile. @@ -54,14 +54,14 @@ def set_initial_sample_decision(transaction_sampled) unless transaction_sampled @sampled = false - log('Discarding profile because transaction not sampled') + log("Discarding profile because transaction not sampled") return end case @profiles_sample_rate when 0.0 @sampled = false - log('Discarding profile because sample_rate is 0') + log("Discarding profile because sample_rate is 0") return when 1.0 @sampled = true @@ -70,7 +70,7 @@ def set_initial_sample_decision(transaction_sampled) @sampled = Random.rand < @profiles_sample_rate end - log('Discarding profile due to sampling decision') unless @sampled + log("Discarding profile due to sampling decision") unless @sampled end def to_hash @@ -130,7 +130,7 @@ def to_hash num_seen << results[:raw][idx + len] idx += len + 1 - log('Unknown frame in stack') if stack.size != len + log("Unknown frame in stack") if stack.size != len end idx = 0 @@ -155,16 +155,16 @@ def to_hash # Till then, on multi-threaded servers like puma, we will get frames from other active threads when the one # we're profiling is idle/sleeping/waiting for IO etc. # https://bugs.ruby-lang.org/issues/10602 - thread_id: '0', + thread_id: "0", elapsed_since_start_ns: elapsed_since_start_ns.to_s } end end - log('Some samples thrown away') if samples.size != results[:samples] + log("Some samples thrown away") if samples.size != results[:samples] if samples.size <= MIN_SAMPLES_REQUIRED - log('Not enough samples, discarding profiler') + log("Not enough samples, discarding profiler") record_lost_event(:insufficient_data) return {} end @@ -219,7 +219,7 @@ def compute_filename(abs_path, in_app) def split_module(name) # last module plus class/instance method - i = name.rindex('::') + i = name.rindex("::") function = i ? name[(i + 2)..-1] : name mod = i ? name[0...i] : nil @@ -227,7 +227,7 @@ def split_module(name) end def record_lost_event(reason) - Sentry.get_current_client&.transport&.record_lost_event(reason, 'profile') + Sentry.get_current_client&.transport&.record_lost_event(reason, "profile") end end end diff --git a/sentry-ruby/lib/sentry/rack.rb b/sentry-ruby/lib/sentry/rack.rb index 03bff096c..ab565c6d1 100644 --- a/sentry-ruby/lib/sentry/rack.rb +++ b/sentry-ruby/lib/sentry/rack.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'rack' +require "rack" -require 'sentry/rack/capture_exceptions' +require "sentry/rack/capture_exceptions" diff --git a/sentry-ruby/lib/sentry/rack/capture_exceptions.rb b/sentry-ruby/lib/sentry/rack/capture_exceptions.rb index 653188e10..5bb8eda67 100644 --- a/sentry-ruby/lib/sentry/rack/capture_exceptions.rb +++ b/sentry-ruby/lib/sentry/rack/capture_exceptions.rb @@ -50,7 +50,7 @@ def call(env) private def collect_exception(env) - env['rack.exception'] || env['sinatra.error'] + env["rack.exception"] || env["sinatra.error"] end def transaction_op diff --git a/sentry-ruby/lib/sentry/rake.rb b/sentry-ruby/lib/sentry/rake.rb index 0e3e6e8c7..243113023 100644 --- a/sentry-ruby/lib/sentry/rake.rb +++ b/sentry-ruby/lib/sentry/rake.rb @@ -8,10 +8,10 @@ module Rake module Application # @api private def display_error_message(ex) - mechanism = Sentry::Mechanism.new(type: 'rake', handled: false) + mechanism = Sentry::Mechanism.new(type: "rake", handled: false) Sentry.capture_exception(ex, hint: { mechanism: mechanism }) do |scope| - task_name = top_level_tasks.join(' ') + task_name = top_level_tasks.join(" ") scope.set_transaction_name(task_name, source: :task) scope.set_tag("rake_task", task_name) end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration diff --git a/sentry-ruby/lib/sentry/release_detector.rb b/sentry-ruby/lib/sentry/release_detector.rb index a975520eb..c71b216a5 100644 --- a/sentry-ruby/lib/sentry/release_detector.rb +++ b/sentry-ruby/lib/sentry/release_detector.rb @@ -13,12 +13,12 @@ def detect_release(project_root:, running_on_heroku:) def detect_release_from_heroku(running_on_heroku) return unless running_on_heroku - ENV['HEROKU_SLUG_COMMIT'] + ENV["HEROKU_SLUG_COMMIT"] end def detect_release_from_capistrano(project_root) - revision_file = File.join(project_root, 'REVISION') - revision_log = File.join(project_root, '..', 'revisions.log') + revision_file = File.join(project_root, "REVISION") + revision_log = File.join(project_root, "..", "revisions.log") if File.exist?(revision_file) File.read(revision_file).strip @@ -32,7 +32,7 @@ def detect_release_from_git end def detect_release_from_env - ENV['SENTRY_RELEASE'] + ENV["SENTRY_RELEASE"] end end end diff --git a/sentry-ruby/lib/sentry/session_flusher.rb b/sentry-ruby/lib/sentry/session_flusher.rb index 5971cfc59..f992a3b20 100644 --- a/sentry-ruby/lib/sentry/session_flusher.rb +++ b/sentry-ruby/lib/sentry/session_flusher.rb @@ -44,7 +44,7 @@ def init_aggregates(aggregation_key) def pending_envelope envelope = Envelope.new - header = { type: 'sessions' } + header = { type: "sessions" } payload = { attrs: attrs, aggregates: @pending_aggregates.values } envelope.add_item(header, payload) diff --git a/sentry-ruby/lib/sentry/test_helper.rb b/sentry-ruby/lib/sentry/test_helper.rb index 7db34cbd2..212c35db5 100644 --- a/sentry-ruby/lib/sentry/test_helper.rb +++ b/sentry-ruby/lib/sentry/test_helper.rb @@ -1,6 +1,6 @@ module Sentry module TestHelper - DUMMY_DSN = 'http://12345:67890@sentry.localdomain/sentry/42' + DUMMY_DSN = "http://12345:67890@sentry.localdomain/sentry/42" # Alters the existing SDK configuration with test-suitable options. Mainly: # - Sets a dummy DSN instead of `nil` or an actual DSN. diff --git a/sentry-ruby/lib/sentry/transaction.rb b/sentry-ruby/lib/sentry/transaction.rb index 89d169512..ac6256555 100644 --- a/sentry-ruby/lib/sentry/transaction.rb +++ b/sentry-ruby/lib/sentry/transaction.rb @@ -265,8 +265,8 @@ def finish(hub: nil, end_timestamp: nil) else is_backpressure = Sentry.backpressure_monitor&.downsample_factor&.positive? reason = is_backpressure ? :backpressure : :sample_rate - hub.current_client.transport.record_lost_event(reason, 'transaction') - hub.current_client.transport.record_lost_event(reason, 'span') + hub.current_client.transport.record_lost_event(reason, "transaction") + hub.current_client.transport.record_lost_event(reason, "span") end end diff --git a/sentry-ruby/lib/sentry/transaction_event.rb b/sentry-ruby/lib/sentry/transaction_event.rb index d2e39dc1f..4136ac6aa 100644 --- a/sentry-ruby/lib/sentry/transaction_event.rb +++ b/sentry-ruby/lib/sentry/transaction_event.rb @@ -75,7 +75,7 @@ def populate_profile(transaction) name: transaction.name, trace_id: transaction.trace_id, # TODO-neel-profiler stubbed for now, see thread_id note in profiler.rb - active_thead_id: '0' + active_thead_id: "0" } ) diff --git a/sentry-ruby/lib/sentry/transport.rb b/sentry-ruby/lib/sentry/transport.rb index 39a993fe5..d446387f2 100644 --- a/sentry-ruby/lib/sentry/transport.rb +++ b/sentry-ruby/lib/sentry/transport.rb @@ -5,7 +5,7 @@ module Sentry class Transport - PROTOCOL_VERSION = '7' + PROTOCOL_VERSION = "7" USER_AGENT = "sentry-ruby/#{Sentry::VERSION}" CLIENT_REPORT_INTERVAL = 30 @@ -134,13 +134,13 @@ def envelope_from_event(event) envelope = Envelope.new(envelope_headers) envelope.add_item( - { type: item_type, content_type: 'application/json' }, + { type: item_type, content_type: "application/json" }, event_payload ) if event.is_a?(TransactionEvent) && event.profile envelope.add_item( - { type: 'profile', content_type: 'application/json' }, + { type: "profile", content_type: "application/json" }, event.profile ) end @@ -185,7 +185,7 @@ def fetch_pending_client_report(force: false) { reason: reason, category: category, quantity: val } end - item_header = { type: 'client_report' } + item_header = { type: "client_report" } item_payload = { timestamp: Sentry.utc_now.iso8601, discarded_events: discarded_events_hash diff --git a/sentry-ruby/lib/sentry/transport/http_transport.rb b/sentry-ruby/lib/sentry/transport/http_transport.rb index 4a9ee620f..e79bd0634 100644 --- a/sentry-ruby/lib/sentry/transport/http_transport.rb +++ b/sentry-ruby/lib/sentry/transport/http_transport.rb @@ -7,7 +7,7 @@ module Sentry class HTTPTransport < Transport GZIP_ENCODING = "gzip" GZIP_THRESHOLD = 1024 * 30 - CONTENT_TYPE = 'application/x-sentry-envelope' + CONTENT_TYPE = "application/x-sentry-envelope" DEFAULT_DELAY = 60 RETRY_AFTER_HEADER = "retry-after" @@ -38,13 +38,13 @@ def send_data(data) end headers = { - 'Content-Type' => CONTENT_TYPE, - 'Content-Encoding' => encoding, - 'User-Agent' => USER_AGENT + "Content-Type" => CONTENT_TYPE, + "Content-Encoding" => encoding, + "User-Agent" => USER_AGENT } auth_header = generate_auth_header - headers['X-Sentry-Auth'] = auth_header if auth_header + headers["X-Sentry-Auth"] = auth_header if auth_header response = conn.start do |http| request = ::Net::HTTP::Post.new(endpoint, headers) @@ -60,7 +60,7 @@ def send_data(data) else error_info = "the server responded with status #{response.code}" error_info += "\nbody: #{response.body}" - error_info += " Error in headers is: #{response['x-sentry-error']}" if response['x-sentry-error'] + error_info += " Error in headers is: #{response['x-sentry-error']}" if response["x-sentry-error"] raise Sentry::ExternalError, error_info end @@ -78,13 +78,13 @@ def generate_auth_header now = Sentry.utc_now.to_i fields = { - 'sentry_version' => PROTOCOL_VERSION, - 'sentry_client' => USER_AGENT, - 'sentry_timestamp' => now, - 'sentry_key' => @dsn.public_key + "sentry_version" => PROTOCOL_VERSION, + "sentry_client" => USER_AGENT, + "sentry_timestamp" => now, + "sentry_key" => @dsn.public_key } - fields['sentry_secret'] = @dsn.secret_key if @dsn.secret_key - 'Sentry ' + fields.map { |key, value| "#{key}=#{value}" }.join(', ') + fields["sentry_secret"] = @dsn.secret_key if @dsn.secret_key + "Sentry " + fields.map { |key, value| "#{key}=#{value}" }.join(", ") end def conn diff --git a/sentry-ruby/lib/sentry/utils/real_ip.rb b/sentry-ruby/lib/sentry/utils/real_ip.rb index d470051d7..08085bf19 100644 --- a/sentry-ruby/lib/sentry/utils/real_ip.rb +++ b/sentry-ruby/lib/sentry/utils/real_ip.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'ipaddr' +require "ipaddr" # Based on ActionDispatch::RemoteIp. All security-related precautions from that # middleware have been removed, because the Event IP just needs to be accurate,