sentry-rails 5.1.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -1
  4. data/Gemfile +44 -26
  5. data/README.md +1 -1
  6. data/Rakefile +13 -10
  7. data/app/jobs/sentry/send_event_job.rb +2 -1
  8. data/bin/console +1 -0
  9. data/bin/test +389 -0
  10. data/lib/generators/sentry_generator.rb +31 -0
  11. data/lib/sentry/rails/action_cable.rb +18 -7
  12. data/lib/sentry/rails/active_job.rb +118 -55
  13. data/lib/sentry/rails/background_worker.rb +13 -4
  14. data/lib/sentry/rails/backtrace_cleaner.rb +7 -7
  15. data/lib/sentry/rails/breadcrumb/active_support_logger.rb +5 -7
  16. data/lib/sentry/rails/capture_exceptions.rb +34 -15
  17. data/lib/sentry/rails/configuration.rb +171 -21
  18. data/lib/sentry/rails/controller_methods.rb +2 -0
  19. data/lib/sentry/rails/controller_transaction.rb +34 -2
  20. data/lib/sentry/rails/engine.rb +2 -0
  21. data/lib/sentry/rails/error_subscriber.rb +26 -12
  22. data/lib/sentry/rails/log_subscriber.rb +76 -0
  23. data/lib/sentry/rails/log_subscribers/action_controller_subscriber.rb +118 -0
  24. data/lib/sentry/rails/log_subscribers/action_mailer_subscriber.rb +92 -0
  25. data/lib/sentry/rails/log_subscribers/active_job_subscriber.rb +163 -0
  26. data/lib/sentry/rails/log_subscribers/active_record_subscriber.rb +164 -0
  27. data/lib/sentry/rails/log_subscribers/parameter_filter.rb +52 -0
  28. data/lib/sentry/rails/overrides/streaming_reporter.rb +2 -11
  29. data/lib/sentry/rails/railtie.rb +35 -13
  30. data/lib/sentry/rails/rescued_exception_interceptor.rb +12 -1
  31. data/lib/sentry/rails/structured_logging.rb +32 -0
  32. data/lib/sentry/rails/tracing/abstract_subscriber.rb +8 -10
  33. data/lib/sentry/rails/tracing/action_view_subscriber.rb +11 -2
  34. data/lib/sentry/rails/tracing/active_record_subscriber.rb +70 -6
  35. data/lib/sentry/rails/tracing/active_storage_subscriber.rb +17 -4
  36. data/lib/sentry/rails/tracing/active_support_subscriber.rb +63 -0
  37. data/lib/sentry/rails/tracing.rb +3 -1
  38. data/lib/sentry/rails/version.rb +3 -1
  39. data/lib/sentry/rails.rb +3 -0
  40. data/lib/sentry-rails.rb +2 -0
  41. data/sentry-rails.gemspec +16 -8
  42. metadata +26 -21
  43. data/CODE_OF_CONDUCT.md +0 -74
  44. data/lib/sentry/rails/breadcrumb/monotonic_active_support_logger.rb +0 -44
  45. data/lib/sentry/rails/instrument_payload_cleanup_helper.rb +0 -13
  46. data/lib/sentry/rails/tracing/action_controller_subscriber.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f45143dd79cff19a0e7338912f235cec728d9ceb81a37e7a50df78a1722ce1b8
4
- data.tar.gz: 7b5a8dec4f9b6875f6f42794911d30e7a75e0a8662e7d5e83584726066eb3fd4
3
+ metadata.gz: b63ec61238dbea2a3fee7cebbdcf72d1810dc50fe4863502ecdbc66b8da7b31e
4
+ data.tar.gz: 165e2974b74f63c062db1587c1852c151a5b350a15df13c408cea97476d6c10f
5
5
  SHA512:
6
- metadata.gz: 0dbdd5331da560f4bc67a84390bb1f3579fbe7e03da95758cc2e3b103540f407bb2efb153202070f57dc4e2e1b5044dd9dca7e237272460560531d160890211c
7
- data.tar.gz: 1163c26220a308aca6fe3f624e4358446f82d1919eda4daf0c38729f1977eba08b53c4f8bb65543adfc1df7a129ca4098af35060acb3d921d8ddf58025176633
6
+ metadata.gz: ec0d90eb1b44f1dfb45bb369586cb8ee22da1a79604679ec12f475e1916eefe646a34c1ab97de386a43e7a27c3e3999c684d61038571ad88c6e0dca667f23f45
7
+ data.tar.gz: fa67c7c00d3d9f71efd13fecb195ea945538f6535464e704115d5e1a8bf7f6c3cf65c3423369270809a6d49cb99ce4b7ab700cca0885756da673f39f99fac166
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /spec/support/test_rails_app/db
8
+ /spec/dummy/test_rails_app/db*
9
9
  /tmp/
10
10
 
11
11
  # rspec failure tracking
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/Gemfile CHANGED
@@ -1,44 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
4
+ git_source(:github) { |name| "https://github.com/#{name}.git" }
5
+
6
+ eval_gemfile "../Gemfile.dev"
2
7
 
3
8
  # Specify your gem's dependencies in sentry-ruby.gemspec
4
9
  gemspec
5
10
  gem "sentry-ruby", path: "../sentry-ruby"
6
11
 
7
- rails_version = ENV["RAILS_VERSION"]
8
- rails_version = "7.0.0" if rails_version.nil?
9
- rails_version = Gem::Version.new(rails_version)
12
+ platform :jruby do
13
+ gem "activerecord-jdbcmysql-adapter"
14
+ gem "jdbc-sqlite3"
15
+ end
10
16
 
11
- gem 'activerecord-jdbcmysql-adapter', platform: :jruby
12
- gem "jdbc-sqlite3", platform: :jruby
17
+ ruby_version = Gem::Version.new(RUBY_VERSION)
13
18
 
14
- if rails_version < Gem::Version.new("6.0.0")
15
- gem "sqlite3", "~> 1.3.0", platform: :ruby
16
- else
17
- gem "sqlite3", platform: :ruby
19
+ rails_version = ENV.fetch("RAILS_VERSION") do
20
+ if ruby_version >= Gem::Version.new("3.2")
21
+ "8.0"
22
+ elsif ruby_version >= Gem::Version.new("3.1")
23
+ "7.2"
24
+ else
25
+ "7.1"
26
+ end
18
27
  end
19
28
 
20
- if rails_version >= Gem::Version.new("7.0.0")
21
- gem "rails", github: "rails/rails", branch: "7-0-stable"
22
- else
23
- gem "rails", "~> #{rails_version}"
24
- end
29
+ rails_version = Gem::Version.new(rails_version)
25
30
 
26
- gem "sprockets-rails"
31
+ gem "rails", "~> #{rails_version}"
27
32
 
28
- gem "sidekiq"
33
+ if rails_version >= Gem::Version.new("8.1.0")
34
+ gem "rspec-rails", "~> 8.0.0"
35
+ gem "sqlite3", "~> 2.1.1", platform: :ruby
36
+ elsif rails_version >= Gem::Version.new("8.0.0")
37
+ gem "rspec-rails", "~> 8.0.0"
38
+ gem "sqlite3", "~> 2.1.1", platform: :ruby
39
+ elsif rails_version >= Gem::Version.new("7.1.0")
40
+ gem "psych", "~> 4.0.0"
41
+ gem "rspec-rails", "~> 7.0"
42
+ gem "sqlite3", "~> 1.7.3", platform: :ruby
43
+ elsif rails_version >= Gem::Version.new("6.1.0")
44
+ gem "rspec-rails", "~> 6.0"
45
+ gem "sqlite3", "~> 1.7.3", platform: :ruby
46
+ else
47
+ gem "psych", "~> 3.0.0"
48
+ gem "rspec-rails", "~> 4.0"
29
49
 
30
- gem "rspec", "~> 3.0"
31
- gem "rspec-retry"
32
- gem "rspec-rails", "~> 4.0"
33
- gem 'simplecov'
34
- gem "simplecov-cobertura", "~> 1.4"
35
- gem "rexml"
50
+ if rails_version >= Gem::Version.new("6.0.0")
51
+ gem "sqlite3", "~> 1.4.0", platform: :ruby
52
+ else
53
+ gem "sqlite3", "~> 1.3.0", platform: :ruby
54
+ end
55
+ end
36
56
 
37
- gem "rake", "~> 12.0"
57
+ gem "mini_magick"
38
58
 
39
- gem "object_tracer"
40
- gem "debug", github: "ruby/debug", platform: :ruby if RUBY_VERSION.to_f >= 2.6
41
- gem "pry"
59
+ gem "sprockets-rails"
42
60
 
43
61
  gem "benchmark-ips"
44
62
  gem "benchmark_driver"
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
  [![Gem Version](https://img.shields.io/gem/v/sentry-rails.svg)](https://rubygems.org/gems/sentry-rails)
14
- ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-rails%20Test/badge.svg)
14
+ ![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_rails_test.yml/badge.svg)
15
15
  [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
16
16
  [![Gem](https://img.shields.io/gem/dt/sentry-rails.svg)](https://rubygems.org/gems/sentry-rails/)
17
17
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-rails&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-rails&package-manager=bundler&version-scheme=semver)
data/Rakefile CHANGED
@@ -1,14 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
4
+ require_relative "../lib/sentry/test/rake_tasks"
3
5
 
4
- RSpec::Core::RakeTask.new(:spec).tap do |task|
5
- task.rspec_opts = "--order rand"
6
- end
6
+ Sentry::Test::RakeTasks.define_spec_tasks(
7
+ spec_pattern: "spec/sentry/**/*_spec.rb",
8
+ spec_rspec_opts: "--order rand --format progress",
9
+ isolated_specs_pattern: "spec/isolated/**/*_spec.rb",
10
+ isolated_rspec_opts: "--format progress"
11
+ )
7
12
 
8
- task :isolated_specs do
9
- Dir["spec/isolated/*"].each do |file|
10
- sh "bundle exec ruby #{file}"
11
- end
12
- end
13
+ Sentry::Test::RakeTasks.define_versioned_specs_task(
14
+ rspec_opts: "--order rand --format progress"
15
+ )
13
16
 
14
- task :default => [:spec, :isolated_specs]
17
+ task default: [:spec, :"spec:versioned", :"spec:isolated"]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(ActiveJob)
2
4
  module Sentry
3
5
  parent_job =
@@ -31,4 +33,3 @@ else
31
33
  class SendEventJob; end
32
34
  end
33
35
  end
34
-
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "sentry/ruby"
data/bin/test ADDED
@@ -0,0 +1,389 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ # Standalone CLI script to test sentry-rails against multiple Rails versions
6
+ #
7
+ # FEATURES:
8
+ # - Dedicated lock files for each Ruby/Rails version combination
9
+ # - Prevents dependency conflicts between different Rails versions
10
+ # - Automatic lock file management and restoration
11
+ # - Clean up functionality for old lock files
12
+ #
13
+ # LOCK FILE STRATEGY:
14
+ # Each Ruby/Rails combination gets its own lock file:
15
+ # - Ruby 3.4.5 + Rails 6.1 → Gemfile-ruby-3.4.5-rails-6.1.lock
16
+ # - Ruby 3.4.5 + Rails 7.0 → Gemfile-ruby-3.4.5-rails-7.0.lock
17
+ #
18
+ # Usage:
19
+ # ./bin/test --version 5.0
20
+ # ./bin/test --all
21
+ # ./bin/test --help
22
+
23
+ require 'optparse'
24
+ require 'fileutils'
25
+
26
+ class RailsVersionTester
27
+ SUPPORTED_VERSIONS = %w[5.2 6.0 6.1 7.0 7.1 7.2 8.0 8.1].freeze
28
+
29
+ def initialize
30
+ @options = {}
31
+ @failed_versions = []
32
+ @ruby_version = RUBY_VERSION
33
+ @spec_paths = []
34
+ end
35
+
36
+ def run(args)
37
+ parse_options(args)
38
+
39
+ case
40
+ when @options[:help]
41
+ show_help
42
+ when @options[:list]
43
+ list_versions
44
+ when @options[:clean]
45
+ clean_lock_files
46
+ when @options[:all]
47
+ test_all_versions
48
+ when @options[:version]
49
+ test_single_version(@options[:version])
50
+ else
51
+ puts "Error: No action specified. Use --help for usage information."
52
+ exit(1)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def parse_options(args)
59
+ OptionParser.new do |opts|
60
+ opts.banner = "Usage: #{$0} [options] [spec_paths...]"
61
+
62
+ opts.on("-v", "--version VERSION", "Test specific Rails version") do |version|
63
+ unless SUPPORTED_VERSIONS.include?(version)
64
+ puts "Error: Unsupported Rails version '#{version}'"
65
+ puts "Supported versions: #{SUPPORTED_VERSIONS.join(', ')}"
66
+ exit(1)
67
+ end
68
+ @options[:version] = version
69
+ end
70
+
71
+ opts.on("-a", "--all", "Test all supported Rails versions") do
72
+ @options[:all] = true
73
+ end
74
+
75
+ opts.on("-l", "--list", "List supported Rails versions and lock file status") do
76
+ @options[:list] = true
77
+ end
78
+
79
+ opts.on("-c", "--clean", "Clean up old lock files for current Ruby version") do
80
+ @options[:clean] = true
81
+ end
82
+
83
+ opts.on("-h", "--help", "Show this help message") do
84
+ @options[:help] = true
85
+ end
86
+ end.parse!(args)
87
+
88
+ # Remaining arguments are spec paths
89
+ @spec_paths = args
90
+ end
91
+
92
+ def show_help
93
+ puts <<~HELP
94
+ Rails Version Tester for sentry-rails
95
+
96
+ This script tests sentry-rails against different Rails versions by:
97
+ 1. Setting the RAILS_VERSION environment variable
98
+ 2. Managing bundle dependencies with dedicated lock files per Ruby/Rails combination
99
+ 3. Running the test suite in isolated processes
100
+ 4. Providing proper exit codes for CI/CD integration
101
+
102
+ Each Ruby/Rails version combination gets its own Gemfile.lock to prevent conflicts:
103
+ - Ruby #{@ruby_version} + Rails 6.1 → Gemfile-ruby-#{@ruby_version}-rails-6.1.lock
104
+ - Ruby #{@ruby_version} + Rails 7.0 → Gemfile-ruby-#{@ruby_version}-rails-7.0.lock
105
+
106
+ Usage:
107
+ #{$0} --version 6.1 # Test specific Rails version (all specs)
108
+ #{$0} --version 7.0 spec/sentry/rails/log_subscribers # Test specific Rails version with specific specs
109
+ #{$0} --all # Test all supported versions
110
+ #{$0} --list # List supported versions and lock file status
111
+ #{$0} --clean # Clean up old lock files for current Ruby version
112
+ #{$0} --help # Show this help
113
+
114
+ Supported Rails versions: #{SUPPORTED_VERSIONS.join(', ')}
115
+
116
+ Examples:
117
+ #{$0} -v 7.1 # Test Rails 7.1 (all specs)
118
+ #{$0} -v 7.0 spec/sentry/rails/log_subscribers # Test Rails 7.0 log subscriber specs only
119
+ #{$0} -v 7.0 spec/sentry/rails/tracing # Test Rails 7.0 tracing specs only
120
+ #{$0} -a # Test all versions
121
+ #{$0} -c # Clean up old lock files
122
+ HELP
123
+ end
124
+
125
+ def list_versions
126
+ puts "Supported Rails versions:"
127
+ SUPPORTED_VERSIONS.each do |version|
128
+ lock_file = generate_lock_file_name(version)
129
+ status = File.exist?(lock_file) ? "(has lock file)" : "(no lock file)"
130
+ puts " - #{version} #{status}"
131
+ end
132
+ puts
133
+ puts "Current Ruby version: #{@ruby_version}"
134
+ puts "Lock files are stored as: Gemfile-ruby-X.X.X-rails-Y.Y.lock"
135
+ end
136
+
137
+ def test_all_versions
138
+ puts "Testing sentry-rails against all supported Rails versions: #{SUPPORTED_VERSIONS.join(', ')}"
139
+ puts
140
+
141
+ SUPPORTED_VERSIONS.each do |version|
142
+ puts "=" * 60
143
+ puts "Testing Rails #{version}"
144
+ puts "=" * 60
145
+
146
+ exit_code = test_rails_version(version)
147
+
148
+ if exit_code == 0
149
+ puts "✓ Rails #{version} - PASSED"
150
+ else
151
+ puts "✗ Rails #{version} - FAILED (exit code: #{exit_code})"
152
+ @failed_versions << version
153
+ end
154
+ puts
155
+ end
156
+
157
+ print_summary
158
+ end
159
+
160
+ def test_single_version(version)
161
+ puts "Testing sentry-rails against Rails #{version}..."
162
+ exit_code = test_rails_version(version)
163
+ exit(exit_code) unless exit_code == 0
164
+ end
165
+
166
+ def test_rails_version(version)
167
+ puts "Setting up environment for Rails #{version}..."
168
+
169
+ # Generate dedicated lock file name for this Ruby/Rails combination
170
+ dedicated_lock_file = generate_lock_file_name(version)
171
+ current_lock_file = "Gemfile.lock"
172
+
173
+ # Set up environment variables
174
+ env = {
175
+ "RAILS_VERSION" => version,
176
+ "BUNDLE_GEMFILE" => File.expand_path("Gemfile", Dir.pwd)
177
+ }
178
+
179
+ puts "Using dedicated lock file: #{dedicated_lock_file}"
180
+
181
+ # Manage lock file switching
182
+ setup_lock_file(dedicated_lock_file, current_lock_file)
183
+
184
+ begin
185
+ # Check if bundle update is needed
186
+ if bundle_update_needed?(env, dedicated_lock_file)
187
+ puts "Dependencies need to be updated for Rails #{version}..."
188
+ unless update_bundle(env, dedicated_lock_file)
189
+ puts "✗ Failed to update bundle for Rails #{version}"
190
+ return 1
191
+ end
192
+ end
193
+
194
+ # Run the tests in a separate process
195
+ puts "Running test suite..."
196
+ run_tests(env, @spec_paths)
197
+ ensure
198
+ # Save the current lock file back to the dedicated location
199
+ save_lock_file(dedicated_lock_file, current_lock_file)
200
+ end
201
+ end
202
+
203
+ def generate_lock_file_name(rails_version)
204
+ # Create a unique lock file name for this Ruby/Rails combination
205
+ ruby_version_clean = @ruby_version.gsub(/[^\d\.]/, '')
206
+ rails_version_clean = rails_version.gsub(/[^\d\.]/, '')
207
+ "Gemfile-ruby-#{ruby_version_clean}-rails-#{rails_version_clean}.lock"
208
+ end
209
+
210
+ def setup_lock_file(dedicated_lock_file, current_lock_file)
211
+ # If we have a dedicated lock file, copy it to the current location
212
+ if File.exist?(dedicated_lock_file)
213
+ puts "Restoring lock file from #{dedicated_lock_file}"
214
+ FileUtils.cp(dedicated_lock_file, current_lock_file)
215
+ elsif File.exist?(current_lock_file)
216
+ # If no dedicated lock file exists but current one does, remove it
217
+ # so we get a fresh resolution
218
+ puts "Removing existing lock file for fresh dependency resolution"
219
+ File.delete(current_lock_file)
220
+ end
221
+ end
222
+
223
+ def save_lock_file(dedicated_lock_file, current_lock_file)
224
+ # Save the current lock file to the dedicated location
225
+ if File.exist?(current_lock_file)
226
+ puts "Saving lock file to #{dedicated_lock_file}"
227
+ FileUtils.cp(current_lock_file, dedicated_lock_file)
228
+ end
229
+ end
230
+
231
+ def bundle_update_needed?(env, dedicated_lock_file)
232
+ # Check if current Gemfile.lock exists
233
+ current_lock_file = "Gemfile.lock"
234
+ gemfile_path = env["BUNDLE_GEMFILE"] || "Gemfile"
235
+
236
+ return true unless File.exist?(current_lock_file)
237
+
238
+ # Check if Gemfile is newer than the current lock file
239
+ return true if File.mtime(gemfile_path) > File.mtime(current_lock_file)
240
+
241
+ # For Rails version changes, check if lockfile has incompatible Rails version
242
+ if env["RAILS_VERSION"] && lockfile_has_incompatible_rails_version?(current_lock_file, env["RAILS_VERSION"])
243
+ return true
244
+ end
245
+
246
+ # Check if bundle check passes
247
+ system(env, "bundle check > /dev/null 2>&1") == false
248
+ end
249
+
250
+ def lockfile_has_incompatible_rails_version?(lockfile_path, target_rails_version)
251
+ return false unless File.exist?(lockfile_path)
252
+
253
+ lockfile_content = File.read(lockfile_path)
254
+
255
+ # Extract Rails version from lockfile
256
+ if lockfile_content =~ /^\s*rails \(([^)]+)\)/
257
+ locked_rails_version = $1
258
+ target_major_minor = target_rails_version.split('.')[0..1].join('.')
259
+ locked_major_minor = locked_rails_version.split('.')[0..1].join('.')
260
+
261
+ # If major.minor versions don't match, we need to update
262
+ return target_major_minor != locked_major_minor
263
+ end
264
+
265
+ # If we can't determine the Rails version, assume update is needed
266
+ true
267
+ end
268
+
269
+ def update_bundle(env, dedicated_lock_file)
270
+ puts "Updating bundle for Rails #{env['RAILS_VERSION']}..."
271
+
272
+ current_lock_file = "Gemfile.lock"
273
+
274
+ # Try bundle update first
275
+ if system(env, "bundle update --quiet")
276
+ puts "Bundle updated successfully"
277
+ return true
278
+ end
279
+
280
+ puts "Bundle update failed, trying clean install..."
281
+
282
+ # Remove the current lockfile and try fresh install
283
+ File.delete(current_lock_file) if File.exist?(current_lock_file)
284
+
285
+ if system(env, "bundle install --quiet")
286
+ puts "Bundle installed successfully"
287
+ return true
288
+ end
289
+
290
+ puts "Bundle install failed"
291
+ false
292
+ end
293
+
294
+ def run_tests(env, spec_paths = [])
295
+ # Determine the command to run
296
+ if spec_paths.empty?
297
+ # Run all tests via rake
298
+ command = "bundle exec rake"
299
+ else
300
+ # Run specific specs via rspec
301
+ command = "bundle exec rspec #{spec_paths.join(' ')}"
302
+ end
303
+
304
+ puts "Executing: #{command}"
305
+
306
+ # Run the tests in a separate process with proper signal handling
307
+ pid = spawn(env, command,
308
+ out: $stdout,
309
+ err: $stderr,
310
+ pgroup: true)
311
+
312
+ begin
313
+ _, status = Process.wait2(pid)
314
+ status.exitstatus
315
+ rescue Interrupt
316
+ puts "\nInterrupted! Terminating test process..."
317
+ terminate_process_group(pid)
318
+ 130 # Standard exit code for SIGINT
319
+ end
320
+ end
321
+
322
+ def terminate_process_group(pid)
323
+ begin
324
+ Process.kill("TERM", -pid) # Kill the process group
325
+ sleep(2)
326
+ Process.kill("KILL", -pid) if process_running?(pid)
327
+ rescue Errno::ESRCH
328
+ # Process already terminated
329
+ end
330
+ end
331
+
332
+ def process_running?(pid)
333
+ Process.getpgid(pid)
334
+ true
335
+ rescue Errno::ESRCH
336
+ false
337
+ end
338
+
339
+ def clean_lock_files
340
+ puts "Cleaning up lock files for Ruby #{@ruby_version}..."
341
+
342
+ # Find all lock files matching our pattern
343
+ pattern = "Gemfile-ruby-#{@ruby_version.gsub(/[^\d\.]/, '')}-rails-*.lock"
344
+ lock_files = Dir.glob(pattern)
345
+
346
+ if lock_files.empty?
347
+ puts "No lock files found matching pattern: #{pattern}"
348
+ return
349
+ end
350
+
351
+ puts "Found #{lock_files.length} lock file(s):"
352
+ lock_files.each { |file| puts " - #{file}" }
353
+
354
+ print "Delete these files? [y/N]: "
355
+ response = $stdin.gets.chomp.downcase
356
+
357
+ if response == 'y' || response == 'yes'
358
+ lock_files.each do |file|
359
+ File.delete(file)
360
+ puts "Deleted: #{file}"
361
+ end
362
+ puts "Cleanup complete!"
363
+ else
364
+ puts "Cleanup cancelled."
365
+ end
366
+ end
367
+
368
+ def print_summary
369
+ puts "=" * 60
370
+ puts "SUMMARY"
371
+ puts "=" * 60
372
+
373
+ if @failed_versions.empty?
374
+ puts "✓ All Rails versions passed!"
375
+ exit(0)
376
+ else
377
+ puts "✗ Failed versions: #{@failed_versions.join(', ')}"
378
+ puts
379
+ puts "Some Rails versions failed. See output above for details."
380
+ exit(1)
381
+ end
382
+ end
383
+ end
384
+
385
+ # Run the script if called directly
386
+ if __FILE__ == $0
387
+ tester = RailsVersionTester.new
388
+ tester.run(ARGV)
389
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+
5
+ class SentryGenerator < ::Rails::Generators::Base
6
+ class_option :dsn, type: :string, desc: "Sentry DSN"
7
+
8
+ class_option :inject_meta, type: :boolean, default: true, desc: "Inject meta tag into layout"
9
+
10
+ def copy_initializer_file
11
+ dsn = options[:dsn] ? "'#{options[:dsn]}'" : "ENV['SENTRY_DSN']"
12
+
13
+ create_file "config/initializers/sentry.rb", <<~RUBY
14
+ # frozen_string_literal: true
15
+
16
+ Sentry.init do |config|
17
+ config.breadcrumbs_logger = [:active_support_logger]
18
+ config.dsn = #{dsn}
19
+ config.traces_sample_rate = 1.0
20
+ end
21
+ RUBY
22
+ end
23
+
24
+ def inject_code_into_layout
25
+ return unless options[:inject_meta]
26
+
27
+ inject_into_file "app/views/layouts/application.html.erb", before: "</head>\n" do
28
+ " <%= Sentry.get_trace_propagation_meta.html_safe %>\n "
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sentry
2
4
  module Rails
3
5
  module ActionCableExtensions
4
6
  class ErrorHandler
7
+ OP_NAME = "websocket.server"
8
+ SPAN_ORIGIN = "auto.http.rails.actioncable"
9
+
5
10
  class << self
6
11
  def capture(connection, transaction_name:, extra_context: nil, &block)
7
12
  return block.call unless Sentry.initialized?
@@ -13,13 +18,14 @@ module Sentry
13
18
  Sentry.with_scope do |scope|
14
19
  scope.set_rack_env(env)
15
20
  scope.set_context("action_cable", extra_context) if extra_context
16
- scope.set_transaction_name(transaction_name)
17
- transaction = start_transaction(env, scope.transaction_name)
21
+ scope.set_transaction_name(transaction_name, source: :view)
22
+ transaction = start_transaction(env, scope)
18
23
  scope.set_span(transaction) if transaction
19
24
 
20
25
  begin
21
- block.call
26
+ result = block.call
22
27
  finish_transaction(transaction, 200)
28
+ result
23
29
  rescue Exception => e # rubocop:disable Lint/RescueException
24
30
  Sentry::Rails.capture_exception(e)
25
31
  finish_transaction(transaction, 500)
@@ -29,10 +35,15 @@ module Sentry
29
35
  end
30
36
  end
31
37
 
32
- def start_transaction(env, transaction_name)
33
- sentry_trace = env["HTTP_SENTRY_TRACE"]
34
- options = { name: transaction_name, op: "rails.action_cable".freeze }
35
- transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
38
+ def start_transaction(env, scope)
39
+ options = {
40
+ name: scope.transaction_name,
41
+ source: scope.transaction_source,
42
+ op: OP_NAME,
43
+ origin: SPAN_ORIGIN
44
+ }
45
+
46
+ transaction = Sentry.continue_trace(env, **options)
36
47
  Sentry.start_transaction(transaction: transaction, **options)
37
48
  end
38
49