Skip to content

Commit

Permalink
Consistent string freezing (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored Oct 7, 2024
1 parent 8dc3d2d commit 5b1b558
Show file tree
Hide file tree
Showing 199 changed files with 431 additions and 41 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ inherit_gem:
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false

Layout/EmptyLineAfterMagicComment:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true

Style/RedundantFreeze:
Enabled: true

AllCops:
Exclude:
- "sentry-raven/**/*"
- "sentry-*/tmp/**/*"
- "sentry-*/examples/**/*"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Internal

- Profile items have bigger size limit now ([#2421](https://github.com/getsentry/sentry-ruby/pull/2421))
- Consistent string freezing ([#2422](https://github.com/getsentry/sentry-ruby/pull/2422))

## 5.20.1

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |name| "https://github.com/#{name}.git" }

Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |name| "https://github.com/#{name}.git" }

Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

Expand Down
1 change: 1 addition & 0 deletions sentry-delayed_job/bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sentry/ruby"
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/example/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails"
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/example/app.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_job"
require "active_record"
require "delayed_job"
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/lib/sentry-delayed_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "delayed_job"
require "sentry-ruby"
require "sentry/integrable"
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/lib/sentry/delayed_job/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
class Configuration
attr_reader :delayed_job
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/lib/sentry/delayed_job/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module DelayedJob
VERSION = "5.20.1"
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/sentry-delayed_job.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "lib/sentry/delayed_job/version"

Gem::Specification.new do |spec|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Sentry::DelayedJob::Configuration do
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/spec/sentry/delayed_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Sentry::DelayedJob do
Expand Down
2 changes: 2 additions & 0 deletions sentry-delayed_job/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/setup"
begin
require "debug/prelude"
Expand Down
2 changes: 2 additions & 0 deletions sentry-opentelemetry/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |name| "https://github.com/#{name}.git" }

Expand Down
2 changes: 2 additions & 0 deletions sentry-opentelemetry/Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
git_source(:github) { |name| "https://github.com/#{name}.git" }

Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/app/jobs/sentry/send_event_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

if defined?(ActiveJob)
module Sentry
parent_job =
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/benchmarks/allocation_comparison.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'benchmark/memory'
require "sentry-ruby"
require "sentry/benchmarks/benchmark_transport"
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/benchmarks/allocation_report.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'benchmark/ipsa'
require "sentry-ruby"
require "sentry/benchmarks/benchmark_transport"
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/benchmarks/application.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support/all"
require "action_controller"
require_relative "../spec/support/test_rails_app/app"
Expand Down
1 change: 1 addition & 0 deletions sentry-rails/bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sentry/ruby"
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/generators/sentry_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails/generators/base"

class SentryGenerator < ::Rails::Generators::Base
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry-rails.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

require "sentry/rails/version"
require "sentry/rails"
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails"
require "sentry-ruby"
require "sentry/integrable"
Expand Down
4 changes: 3 additions & 1 deletion sentry-rails/lib/sentry/rails/action_cable.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

module Sentry
module Rails
module ActionCableExtensions
class ErrorHandler
OP_NAME = "websocket.server".freeze
OP_NAME = "websocket.server"
SPAN_ORIGIN = "auto.http.rails.actioncable"

class << self
Expand Down
6 changes: 4 additions & 2 deletions sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module ActiveJobExtensions
Expand All @@ -16,8 +18,8 @@ def already_supported_by_sentry_integration?
end

class SentryReporter
OP_NAME = "queue.active_job".freeze
SPAN_ORIGIN = "auto.queue.active_job".freeze
OP_NAME = "queue.active_job"
SPAN_ORIGIN = "auto.queue.active_job"

class << self
def record(job, &block)
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/background_worker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
class BackgroundWorker
def _perform(&block)
Expand Down
6 changes: 4 additions & 2 deletions sentry-rails/lib/sentry/rails/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require "active_support/backtrace_cleaner"
require "active_support/core_ext/string/access"

module Sentry
module Rails
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/.freeze
RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/.freeze
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/
RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/

def initialize
super
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module Breadcrumb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sentry/rails/instrument_payload_cleanup_helper"

module Sentry
Expand Down
6 changes: 4 additions & 2 deletions sentry-rails/lib/sentry/rails/capture_exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

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"

def initialize(_)
super
Expand All @@ -20,7 +22,7 @@ def collect_exception(env)
end

def transaction_op
"http.server".freeze
"http.server"
end

def capture_exception(exception, env)
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sentry/rails/tracing/action_controller_subscriber"
require "sentry/rails/tracing/action_view_subscriber"
require "sentry/rails/tracing/active_record_subscriber"
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/controller_methods.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module ControllerMethods
Expand Down
4 changes: 3 additions & 1 deletion sentry-rails/lib/sentry/rails/controller_transaction.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module Sentry
module Rails
module ControllerTransaction
SPAN_ORIGIN = "auto.view.rails".freeze
SPAN_ORIGIN = "auto.view.rails"

def self.included(base)
base.prepend_around_action(:sentry_around_action)
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
class Engine < ::Rails::Engine
isolate_namespace Sentry
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/error_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
# This is not a user-facing class. You should use it with Rails 7.0's error reporter feature and its interfaces.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module InstrumentPayloadCleanupHelper
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/overrides/streaming_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module Overrides
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sentry/rails/capture_exceptions"
require "sentry/rails/rescued_exception_interceptor"
require "sentry/rails/backtrace_cleaner"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
class RescuedExceptionInterceptor
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/tracing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module Tracing
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/tracing/abstract_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
module Tracing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sentry/rails/tracing/abstract_subscriber"
require "sentry/rails/instrument_payload_cleanup_helper"

Expand All @@ -8,8 +10,8 @@ class ActionControllerSubscriber < AbstractSubscriber
extend InstrumentPayloadCleanupHelper

EVENT_NAMES = ["process_action.action_controller"].freeze
OP_NAME = "view.process_action.action_controller".freeze
SPAN_ORIGIN = "auto.view.rails".freeze
OP_NAME = "view.process_action.action_controller"
SPAN_ORIGIN = "auto.view.rails"

def self.subscribe!
Sentry.logger.warn <<~MSG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

require "sentry/rails/tracing/abstract_subscriber"

module Sentry
module Rails
module Tracing
class ActionViewSubscriber < AbstractSubscriber
EVENT_NAMES = ["render_template.action_view"].freeze
SPAN_PREFIX = "template.".freeze
SPAN_ORIGIN = "auto.template.rails".freeze
SPAN_PREFIX = "template."
SPAN_ORIGIN = "auto.template.rails"

def self.subscribe!
subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "sentry/rails/tracing/abstract_subscriber"

module Sentry
Expand All @@ -19,12 +21,12 @@ class ActiveStorageSubscriber < AbstractSubscriber
analyze.active_storage
].freeze

SPAN_ORIGIN = "auto.file.rails".freeze
SPAN_ORIGIN = "auto.file.rails"

def self.subscribe!
subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
record_on_current_span(
op: "file.#{event_name}".freeze,
op: "file.#{event_name}",
origin: SPAN_ORIGIN,
start_timestamp: payload[START_TIMESTAMP_NAME],
description: payload[:service],
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/lib/sentry/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Sentry
module Rails
VERSION = "5.20.1"
Expand Down
2 changes: 2 additions & 0 deletions sentry-rails/sentry-rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "lib/sentry/rails/version"

Gem::Specification.new do |spec|
Expand Down
Loading

0 comments on commit 5b1b558

Please sign in to comment.