Skip to content

Ignore frontend errors not originating from application script#10087

Merged
aduth merged 1 commit intomainfrom
aduth-frontend-error-non-js
Feb 15, 2024
Merged

Ignore frontend errors not originating from application script#10087
aduth merged 1 commit intomainfrom
aduth-frontend-error-non-js

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Feb 14, 2024

🛠 Summary of changes

Updates logic of isTrackableError to ignore any errors which occur from the same host, but which aren't from JavaScript files.

Following #10027, data for filename shows that errors are originating from filenames such as https://secure.login.gov/. The hypothesis is that app webviews or browser extensions may be injecting scripts evaluated on the page and throwing errors, which we want to ignore.

📜 Testing Plan

  1. echo "setTimeout(() => { throw new Error('example'); }, 100)" >> app/javascript/packages/analytics/index.ts
  2. NODE_ENV=production yarn build
  3. rails s
  4. Go to http://localhost:3000
  5. Validate NewRelic logging. Easiest way is to add a binding.pry at the notice_error call and check that it's triggered

changelog: Internal, Error Logging, Ignore frontend errors not originating from application script
try {
return new URL(event.filename).host === window.location.host;
const { host, pathname } = new URL(event.filename);
return host === window.location.host && pathname.endsWith('.js');
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 think it would make sense to add a similar check on the server? I guess we could always add later if it turns out to be too noisy

Copy link
Contributor Author

@aduth aduth Feb 15, 2024

Choose a reason for hiding this comment

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

do you think it would make sense to add a similar check on the server? I guess we could always add later if it turns out to be too noisy

That's a good question. I think generally yes, in the sense that we shouldn't trust any "validation" to occur exclusively in the client.

But it also sparks an idea that we could do this exclusively server-side, on which I'm conflicted:

  • Since this is a critical-path script, anything to reduce its size is a win. And doing it in one place is simpler to maintain.
  • But if we moved all validation to the server, it would put additional strain in handling X more requests, which could otherwise be filtered on the client

I'd probably lean toward keeping this as-is, and following-up with a pull request to perform the same validation server-side as a fallback.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense to me

@aduth aduth merged commit 5cc7504 into main Feb 15, 2024
@aduth aduth deleted the aduth-frontend-error-non-js branch February 15, 2024 17:51
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.

3 participants