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

Release 4.0.0.pre.4 #205

Merged
merged 6 commits into from
Jun 10, 2021
Merged

Release 4.0.0.pre.4 #205

merged 6 commits into from
Jun 10, 2021

Conversation

ChrisBAshton
Copy link
Contributor

@ChrisBAshton ChrisBAshton commented Jun 10, 2021

This fixes the Sentry client initialisation - see commits for details.

Tested by bumping the dependency in Whitehall and manually sending an exception and string to Sentry, both of which came through 🎉

Trello: https://trello.com/c/4JOuje6O/2546-fix-broken-data-sync-related-sentry-errors-not-being-ignored

The custom option `active_sentry_environments` was added in
#168.

However, it turns out there is already a native option for this:
`enabled_environments`. See
https://docs.sentry.io/platforms/ruby/configuration/options/

This allows us to simplify our code a fair bit.

I've also removed the stubbed `sending_allowed?` method as it was
interfering with some tests and giving a false sense of security.
We're now providing all of the necessary configuration for
the `Sentry::Configuration` instance to return `true` on its
`valid?` method, so no need for the hack.
Each config option is documented in an inline comment as otherwise
it can be quite obtuse.
This is required for sentry-ruby to work properly. We used to
proxy our `configure` method through to `Sentry.configure`, but
this method is deprecated as of v4 of the gem.

Moreover, the `Sentry.init` method clears any previous configuration,
rather than layering additional configuration on top. In
subsequent commits, we will re-architect GovukError to force only
one `configure` call.
The way we initialise the Sentry client has changed; Sentry now
takes an `init` method, which overwrites any previous configuration.
This means we can no longer have a 'default' `GovukError.configure`
that is called prior to the application's `GovukError.configure`,
nor can the application make multiple calls itself. To prevent
confusion, we're now raising an exception if any app attempts to
call the method twice.

Due to Sentry being global, and a singleton, and closed for
modification, unfortunately we can't split the test up into
smaller ones. However, the resulting test is still reasonably
concise.
If apps haven't provided their own custom configuration, then they
would not ever trigger the `GovukError.configure` call without
this Railtie.

Non-Rails apps will be required to call `GovukError.configure`
manually in order to initialise Sentry.
This is no longer possible when done via Sentry's
`capture_exception` call, which raises an `ArgumentError` if an
`Exception` is not passed:
https://github.com/getsentry/sentry-ruby/blob/2ccfcf3f93057f4f0a3c98dc5e3ace3868dca509/sentry-ruby/lib/sentry/hub.rb#L95
set_up_defaults
end

def set_up_defaults
Copy link
Contributor

Choose a reason for hiding this comment

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

It occured to me after I wrote the experimental code that this method could belong in govuk_error.rb, so we'd have something like this:

config = Configuration.new(sentry_config)
set_up_defaults(config)
yield config if block_given?

I think it's slightly nicer because it keeps the Configuration class responsible for just wrapping the Sentry class, but to be honest, I don't really mind either way.

Copy link
Contributor Author

@ChrisBAshton ChrisBAshton Jun 10, 2021

Choose a reason for hiding this comment

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

I think having it in Configuration is slightly nicer now, to be honest, because we can now only make one call to GovukError.configure. Under the hood, this is responsible for merging in custom before_send logic, including datasync-error-ignoring, etc. I think it's quite nice that there's just one file to look at all of the default configuration (including the logic above), so there's a little bit less poking around involved if you want to override something in your GovukError.configure call.

@ChrisBAshton ChrisBAshton marked this pull request as ready for review June 10, 2021 08:54
@ChrisBAshton ChrisBAshton changed the title Fix Sentry client initialisation Release 4.0.0.pre.4 Jun 10, 2021
@ChrisBAshton ChrisBAshton merged commit 87e445e into main Jun 10, 2021
@ChrisBAshton ChrisBAshton deleted the fix-error-reporting-new branch June 10, 2021 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants