Closed knapo closed 5 months ago
Merging #2269 (9a84215) into master (b05afd9) will not change coverage. The diff coverage is
100.00%
.
Still getting this error on Ruby-3.3:
NoMethodError:
undefined method `add_session' for nil
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry/hub.rb:244:in `end_session'
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry/hub.rb:253:in `with_session_tracking'
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry-ruby.rb:403:in `with_session_tracking'
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry/rack/capture_exceptions.rb:19:in `block in call'
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry/hub.rb:59:in `with_scope'
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry-ruby.rb:383:in `with_scope'
# /home/ixti/.gem/ruby/3.3.0/gems/sentry-ruby-5.17.1/lib/sentry/rack/capture_exceptions.rb:18:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/rails_semantic_logger-4.14.0/lib/rails_semantic_logger/rack/logger.rb:45:in `call_app'
# /home/ixti/.gem/ruby/3.3.0/gems/rails_semantic_logger-4.14.0/lib/rails_semantic_logger/rack/logger.rb:26:in `block in call'
# /home/ixti/.gem/ruby/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/base.rb:190:in `block in tagged'
# /home/ixti/.gem/ruby/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/semantic_logger.rb:395:in `named_tagged'
# /home/ixti/.gem/ruby/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/base.rb:197:in `tagged'
# /home/ixti/.gem/ruby/3.3.0/gems/rails_semantic_logger-4.14.0/lib/rails_semantic_logger/rack/logger.rb:26:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/rack-3.0.9.1/lib/rack/method_override.rb:28:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/rack-3.0.9.1/lib/rack/runtime.rb:24:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/rack-3.0.9.1/lib/rack/sendfile.rb:114:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/ddtrace-1.21.0/lib/datadog/tracing/contrib/rack/middlewares.rb:113:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/railties-7.1.3.2/lib/rails/engine.rb:536:in `call'
# /home/ixti/.gem/ruby/3.3.0/gems/rack-test-2.1.0/lib/rack/test.rb:360:in `process_request'
# /home/ixti/.gem/ruby/3.3.0/gems/rack-test-2.1.0/lib/rack/test.rb:153:in `request'
# ./spec/support/helpers/request_helpers.rb:7:in `login'
# ./spec/requests/onboardings_controller_spec.rb:55:in `block (4 levels) in <top (required)>'
# /home/ixti/.gem/ruby/3.3.0/gems/webmock-3.23.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <top (required)>'
UPDATE: I believe that's due to my misconfiguration, as this error only occurs during specific order of specs execution.
Figured out the reason for https://github.com/getsentry/sentry-ruby/pull/2269#issuecomment-2002596748
It happens when we do in specs:
require "sentry/test_helper"
RSpec.configure do |config|
config.include Sentry::TestHelper, sentry_test: true
config.before(sentry_test: true) { setup_sentry_test }
config.after(sentry_test: true) { teardown_sentry_test }
end
Okay. Found how to reproduce the error:
Sentry.init do |config|
# ...
config.enabled_environments = %w[staging production]
# ...
end
Then using in specs:
require "sentry/test_helper"
RSpec.configure do |config|
config.include Sentry::TestHelper
end
RSpec.describe "..." do
before { setup_sentry_test }
after { teardown_sentry_test }
# ...
end
setup_sentry_test
injects "test"
into environments
Description
https://github.com/getsentry/sentry-ruby/pull/2245 (cc @st0012 ) introduced changes around checking if session_tracking is enabled or not.. However, it wasn't updated in all necessary places and make it inconsistent within the codebase. As result, when not
enabled_in_current_env?
we're getting a following error:Affected version:
sentry-ruby 5.17.0