Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt Rails 7.1's new BroadcastLogger #2120

Merged
merged 2 commits into from Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
### Features

- Record client reports for profiles [#2107](https://github.com/getsentry/sentry-ruby/pull/2107)
- Adopt Rails 7.1's new BroadcastLogger [#2120](https://github.com/getsentry/sentry-ruby/pull/2120)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/.gitignore
Expand Up @@ -5,7 +5,7 @@
/doc/
/pkg/
/spec/reports/
/spec/dummy/test_rails_app/db
/spec/dummy/test_rails_app/db*
/tmp/

# rspec failure tracking
Expand Down
7 changes: 6 additions & 1 deletion sentry-rails/lib/sentry/rails/configuration.rb
Expand Up @@ -12,7 +12,12 @@
@excluded_exceptions = @excluded_exceptions.concat(Sentry::Rails::IGNORE_DEFAULT)

if ::Rails.logger
@logger = ::Rails.logger.dup
if ::Rails.logger.respond_to?(:broadcasts)
dupped_broadcasts = ::Rails.logger.broadcasts.map(&:dup)
@logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts)
else
@logger = ::Rails.logger.dup

Check warning on line 19 in sentry-rails/lib/sentry/rails/configuration.rb

View check run for this annotation

Codecov / codecov/patch

sentry-rails/lib/sentry/rails/configuration.rb#L19

Added line #L19 was not covered by tests
end
else
@logger.warn(Sentry::LOGGER_PROGNAME) do
<<~MSG
Expand Down
29 changes: 24 additions & 5 deletions sentry-rails/spec/sentry/rails_spec.rb
Expand Up @@ -14,6 +14,12 @@
make_basic_app
end

after do
# We need to cleanup Rails.logger because after https://github.com/rails/rails/pull/49417
# Rails.logger could get recreated with the previous logger value and become deeply nested broadcast logger
Rails.logger = nil
end

it "has version set" do
expect(described_class::VERSION).to be_a(String)
end
Expand All @@ -36,11 +42,24 @@

describe "logger detection" do
it "sets a duplicated Rails logger as the SDK's logger" do
expect(Sentry.configuration.logger).to be_a(ActiveSupport::Logger)
Sentry.configuration.logger.level = ::Logger::WARN
# Configuring the SDK's logger should not affect the Rails logger
expect(Rails.logger.level).to eq(::Logger::DEBUG)
expect(Sentry.configuration.logger.level).to eq(::Logger::WARN)
if Gem::Version.new(Rails.version) > Gem::Version.new("7.1.0.beta")
expect(Sentry.configuration.logger).to be_a(ActiveSupport::BroadcastLogger)

Sentry.configuration.logger.level = ::Logger::WARN

# Configuring the SDK's logger should not affect the Rails logger
expect(Rails.logger.broadcasts.first).to be_a(ActiveSupport::Logger)
expect(Rails.logger.broadcasts.first.level).to eq(::Logger::DEBUG)
expect(Sentry.configuration.logger.level).to eq(::Logger::WARN)
else
expect(Sentry.configuration.logger).to be_a(ActiveSupport::Logger)

Sentry.configuration.logger.level = ::Logger::WARN

# Configuring the SDK's logger should not affect the Rails logger
expect(Rails.logger.level).to eq(::Logger::DEBUG)
expect(Sentry.configuration.logger.level).to eq(::Logger::WARN)
end
end

it "respects the logger set by user" do
Expand Down