Skip to content

Add logging of errors reported by console.error #13

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nahall
Copy link

@nahall nahall commented Sep 9, 2024

Some scripts log errors to the console with console.error(). These errors normally go unnoticed once a website is in production. This change makes these errors also get logged to the backend where they can be reviewed.

Copy link
Owner

@fredden fredden left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. I like the idea. I've left some feedback around duplication of code, but otherwise this looks good. We should be able to get a new version with this change released this week.

Comment on lines +39 to +45
if (sendQueue.length > 100) {
// That's a lot of errors! Let's not overwhelm the server with more.
return;
}
if (!sendQueue.length) {
sendTimer = window.setTimeout(sendError, sendDelay);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Can we perhaps move this into a shared function instead of duplicating this logic?

Maybe we can pass in { colno: event.colno, filename: event.filename, lineno: event.lineno, message: event.message, stack: event.error && event.error.stack } in the original and { message: Array.from(args).join(' ') } (or whatever is appropriate here) in this new feature, and then the shared function can add the timer key and send this as the event object to the sendQueue.push() call?

Comment on lines +47 to +51
browser: {
height: window.innerHeight,
url: window.location.href,
width: window.innerWidth,
},
Copy link
Owner

Choose a reason for hiding this comment

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

This block (and event.timer) below could be part of the shared-functionality function.

width: window.innerWidth,
},
event: {
type: type,
Copy link
Owner

@fredden fredden Sep 10, 2024

Choose a reason for hiding this comment

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

Is there a column that this (type) maps to in the PHP/database side? I don't see this key in the original object below.

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