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

Centralise frontend error reporting (and suppress unactionable Sentry errors) #3850

Merged
merged 12 commits into from Mar 21, 2024

Conversation

sarayourfriend
Copy link
Contributor

Fixes

Fixes #3468 by @krysal

Superceeds #3721 after rebasing the branch to include #3811.

Description

Introduces a new plugin to centralise network error handling. This allows us to make large-scale changes to how we handle certain classes of networking errors under certain conditions. To resolve the problems in the issue, this PR ignores the types of errors mentioned there, or sends information about them to a place we can better understand them (Plausible). For many ignored errors, we have other mechanisms to inspect and understand them, like API logs, or Cloudflare traffic analysis.

Testing Instructions

Confirm the new tests sufficiently verify the behaviour of the plugin.

Run the app locally, and visit a search page. Open your browser dev tools network tab, and navigate to a single result. Find the "Related" request for the result, and block it using your dev tools (in Firefox you right click and "Block this URL" from the context menu). Navigate back to search, reload to clear the pinia cache of the related request, then go back to the same single result page. Confirm that the dev console has a log event for an analytics event, NETWORK_ERROR, and that no Sentry event was sent. You can confirm the sentry events by adding a console log at that line so you can see it in your nuxt dev console.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • [N/A] I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Feb 29, 2024
@github-actions github-actions bot added 🧱 stack: documentation Related to Sphinx documentation 🧱 stack: frontend Related to the Nuxt frontend labels Feb 29, 2024
@obulat obulat removed the 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work label Feb 29, 2024
@sarayourfriend
Copy link
Contributor Author

I'm leaving this as a draft intentionally. I'll work on the Playwright tests we discussed in the original PR tomorrow.

@sarayourfriend sarayourfriend marked this pull request as ready for review March 19, 2024 23:29
@sarayourfriend sarayourfriend requested a review from a team as a code owner March 19, 2024 23:29
@sarayourfriend sarayourfriend removed the 🧱 stack: documentation Related to Sphinx documentation label Mar 19, 2024
Copy link

Full-stack documentation: https://docs.openverse.org/_preview/3850

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

I've tested this PR locally, and it seems to work really well.

// Only match the search requests, rather than any other API request the search page makes
return Boolean(
url.pathname.match(/v1\/(audio|images)/) &&
url.searchParams.has("q", "galah")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice way of matching by params!

/**
* Record network errors using the appropriate tool, as needed,
* based on response code, status, and request kind.
* @param error - The error to record
Copy link
Contributor

Choose a reason for hiding this comment

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

This docstring needs to be updated.

Comment on lines +65 to +67
{
id,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{
id,
}
{ id }

Nit

Comment on lines +506 to +508
{
searchTerm: queryParams.q ?? "",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{
searchTerm: queryParams.q ?? "",
}
{ searchTerm: queryParams.q ?? "" }

Nit: these seem more readable when on a single line

* implementation or configuration error suddenly causing malformed
* identifiers to be used. Neither Sentry nor Plausible are the right tool
* for that task. If the 404s are caused by an API issue, we'd see that in
* API response code monitoring, where we can more easily trace the cause
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* API response code monitoring, where we can more easily trace the cause
* API response code monitoring, where we can more easily trace the cause.

Comment on lines +116 to +121
} else {
context.$sentry.captureException(originalError, {
extra: { fetchingError },
})
}
}
Copy link
Member

Choose a reason for hiding this comment

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

``

Suggested change
} else {
context.$sentry.captureException(originalError, {
extra: { fetchingError },
})
}
}
return
}
// Send all other errors to Sentry
context.$sentry.captureException(originalError, {
extra: { fetchingError },
})
}

Style nit: perhaps this would make adding future additional cases less error-prone, or avoid confusion if folks think there's some special relationship between the process.client && fetchingError.code === "ERR_NETWORK" errors and Sentry specifically.

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 went back and forth many times on this, and ultimately found both just as confusing, and went with a coin toss. I'll switch this, as any actual preference is better than my 50/50 non-choice!

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

This is really, really nice! Wow. Great code and works perfectly. Unit tests passed locally, failed correctly when modified, and I was able to produce a NETWORK_ERROR analytics event using the instructions. I left a minor typo and code style suggestion but LGTM.

@sarayourfriend sarayourfriend merged commit ee3caaa into main Mar 21, 2024
53 checks passed
@sarayourfriend sarayourfriend deleted the fix/prevent-axios-error-sentry branch March 21, 2024 23:21
@sarayourfriend
Copy link
Contributor Author

I merged this, forgetting that the reason I didn't do so earlier was because of some outstanding minor feedback. Apologies! I am not intentionally disregarding them. If any of those pieces feel critical enough to make issues for, please let me know which ones and I can create the issues @zackkrida @obulat.

Some of them are things ESlint should be able to catch: early return vs else? And object/brace formatting.

@zackkrida
Copy link
Member

Looks fine as-is for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Avoid AxiosError when requesting bad image links
4 participants