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

Install Sentry #5

Merged
merged 6 commits into from
Dec 22, 2023
Merged

Install Sentry #5

merged 6 commits into from
Dec 22, 2023

Conversation

mike29736
Copy link
Contributor

@mike29736 mike29736 commented Dec 7, 2023

https://trello.com/c/jDSDGNyn/814-measure-and-record-our-publishing-latency-sli

  • Install the gem
  • No need for configuration since it uses the environment variables that we've set for it
  • Send exceptions to Sentry, choosing whether to stop them propagating any further in the code or to re-raise them and allow them to abort the process

I've tested this in integration (https://govuk.sentry.io/issues/?project=4506338071150592&query=is%3Aresolved&referrer=issue-list&statsPeriod=90d)

We'll still need to call `Sentry.init` somewhere, but I don't think the
right place to do that exists yet.
@mike29736
Copy link
Contributor Author

One Sentry-related thing I haven't done yet is add this repository's name to https://github.com/alphagov/govuk-infrastructure/blob/main/terraform/deployments/sentry/locals.tf. I'm not sure what it does exactly, but I've spotted it on my travels so, FWIW, it's on my list of things to look into.

end
end

describe ".report" do
Copy link
Contributor

@jkempster34 jkempster34 Dec 7, 2023

Choose a reason for hiding this comment

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

This might be better named propagate? I keep checking the difference between report and capture

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you that report and capture are bad names. And the more I look at them, probably also that ExceptionHandler.propagate and ExceptionHandler.capture are a better pair. But I hope we can do even better 😆

collect Outdated
require "govuk_sli_collector"

GovukSliCollector.call
ExceptionHandler.report { GovukSliCollector.call }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the report method needed at all? Unhandled errors should be logged in Sentry anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hoped that the Sentry gem might work that way but it didn't happen in my integration testing. Maybe I've missed a configuration option, but I haven't seen one in the docs so far.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's because you needed to Sentry.init somewhere first?

Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly just a call to Sentry.init underneath the requires in this file to see if that works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try that now. I thought I had already, but I can only find deploys featuring all the other combinations of Sentry.init and raising an exception on purpose 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need the DSN, where is that set? 😕

Sentry.init do |config|
  config.dsn = ''
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets that from the container's environment (I don't know if I did a good job of it, but I tried to explain this in the commit that calls Sentry.init: 074c091 in case it was a bit mysterious)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(BTW, I've only ever called Sentry.init without a config block on all versions of this branch, so we can see from the errors being in Sentry at all that the environment variables work.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, it reads them from the env vars if available.

It does say that unhandled errors should be logged, I can't see anything wrong with the install-sentry-test-handling-unhandled branch though https://docs.sentry.io/product/sentry-basics/integrate-backend/capturing-errors/#unhandled-errors

collect Outdated
require "govuk_sli_collector"

GovukSliCollector.call
ExceptionHandler.report { GovukSliCollector.call }
Copy link
Contributor

Choose a reason for hiding this comment

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

What kind of errors would not be swallowed i.e., raised outside of PublishingLatencySli?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Currently, without any code changes, there's nothing that can break that wouldn't already be broken.

Having this was useful while I was making recent changes, so I figured it makes sense to leave it to cover future changes, too. Does it feel too "future use case" to you?

For sending exceptions to Sentry. One method sends and silences the
exception, the other sends and re-raises it.

`Sentry.init` needed to be called before we used any Sentry methods, so
while it's a little bit gross, this ended up feeling like the right
place.

Our Helm chart already includes the SENTRY_DSN, SENTRY_CURRENT_ENV and
SENTRY_RELEASE in our job's environment, by the way, so Sentry should be
configured out-of-the-box. (Othewise, we'd supply configuration to
`Sentry.init`.)
Nothing's changed, I just spotted that this isn't needed
I might merge these commits later, but attempting to minimise noise in
the commits where I'm actually doing something
Send exceptions to Sentry and don't let them propagate any further.

I imagine this allowing us to add new SLI classes without any one class
preventing the others collecting their data.
But allow them to propagate so that they can result in a non-zero exit
code and so that they're also sent to Logit
Copy link
Contributor

@jkempster34 jkempster34 left a comment

Choose a reason for hiding this comment

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

Thank you for the renaming, as well as the well named commits, I'd still like to know why unhandled errors aren't logging but happy to approve!

mike29736 added a commit that referenced this pull request Dec 14, 2023
The container that this project is runs in now* uses the `latest`-tagged
image from ECR.

Our `build-and-push-image` action only tags its built image as `latest` if it's built from the latest commit on `main`**.

This does mean that we can't deploy an arbitrary branch or commit, but
since we only deploy to production, that _might not_ be a bad thing. At
least, there seems to be plenty we can test locally before needing to
deploy a change, we have tooling (#5)
for error handling and reporting and there's no reason we can't practice
something closer to trunk-based development going forward.

*https://github.com/alphagov/govuk-helm-charts/blob/456388977d052d7d50c26f550e24fc11166149a4/charts/govuk-sli-collector/values.yaml#L10
**https://github.com/alphagov/govuk-infrastructure/blob/a046a2c0da8f002e9e4507cd9d14310f2c1669a9/.github/workflows/build-and-push-image.yml#L76
mike29736 added a commit that referenced this pull request Dec 14, 2023
The container that this project is runs in now* uses the `latest`-tagged
image from ECR.

Our `build-and-push-image` action only tags its built image as `latest` if it's built from the latest commit on `main`**.

This does mean that we can't deploy an arbitrary branch or commit, but
since we only deploy to production, that _might not_ be a bad thing. At
least, there seems to be plenty we can test locally before needing to
deploy a change, we have tooling (#5)
for error handling and reporting and there's no reason we can't practice
something closer to trunk-based development going forward.

*https://github.com/alphagov/govuk-helm-charts/blob/456388977d052d7d50c26f550e24fc11166149a4/charts/govuk-sli-collector/values.yaml#L10
**https://github.com/alphagov/govuk-infrastructure/blob/a046a2c0da8f002e9e4507cd9d14310f2c1669a9/.github/workflows/build-and-push-image.yml#L76
mike29736 added a commit that referenced this pull request Dec 14, 2023
The container that this project is runs in now* uses the `latest`-tagged
image from ECR.

Our `build-and-push-image` action only tags its built image as `latest`
if it's built from the latest commit on `main`**.

This does mean that we can't deploy an arbitrary branch or commit, but
since we only deploy to production, that _might not_ be a bad thing. At
least, there seems to be plenty we can test locally before needing to
deploy a change, we have tooling (#5)
for error handling and reporting and there's no reason we can't practice
something closer to trunk-based development going forward.

*https://github.com/alphagov/govuk-helm-charts/blob/456388977d052d7d50c26f550e24fc11166149a4/charts/govuk-sli-collector/values.yaml#L10
**https://github.com/alphagov/govuk-infrastructure/blob/a046a2c0da8f002e9e4507cd9d14310f2c1669a9/.github/workflows/build-and-push-image.yml#L76
@mike29736 mike29736 merged commit 9a143fc into main Dec 22, 2023
2 checks passed
@mike29736 mike29736 deleted the install-sentry branch December 22, 2023 16:11
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