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

Add missing initialized? checks to sentry-rails #1919

Merged
merged 1 commit into from
Oct 21, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- `Sentry::BackgroundWorker` will release `ActiveRecord` connection pool only when the `ActiveRecord` connection is established
- Remove bad encoding arguments in redis span descriptions [#1914](https://github.com/getsentry/sentry-ruby/pull/1914)
- Fixes [#1911](https://github.com/getsentry/sentry-ruby/issues/1911)
- Add missing `initialized?` checks to `sentry-rails` [#1919](https://github.com/getsentry/sentry-ruby/pull/1919)
- Fixes [#1885](https://github.com/getsentry/sentry-ruby/issues/1885)

## 5.5.0

Expand Down
1 change: 1 addition & 0 deletions sentry-rails/lib/sentry/rails/controller_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Rails
module ControllerTransaction
def self.included(base)
base.prepend_before_action do |controller|
return unless Sentry.initialized?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code generates a LocalJumpError: unexpected return error in my install. I'm pulling sentry-ruby from source to try and mitigate the same problem as in #1885, which shows up in our test environments. (It shows up even though we're not using guard, so the workaround from that issue didn't work for us)

I'm using Rails 6.1.6 with Ruby 2.7.6p219

Instead, using a basic conditional like this was enough to make our tests pass:

          if Sentry.initialized?
            Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}", source: :view)
          end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof my bad, thx @gareth

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}", source: :view)
end
end
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def instrument(name, payload = {}, &block)
end

def self.get_current_transaction
Sentry.get_current_scope.get_transaction
Sentry.get_current_scope.get_transaction if Sentry.initialized?
end

# it's just a container for the extended method
Expand Down