-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Try catching JS errors and sending them to the API #1949
Conversation
On a related note, I just found http://yellerapp.com |
// POST to the API | ||
xhr.open( 'POST', 'https://public-api.wordpress.com/js-error', true ); | ||
xhr.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' ); | ||
xhr.send( 'message=' + error.message + '&type=' + error.constructor && error.constructor.name + '&userAgent=' + navigator.userAgent + '&stack=' + error.stack ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should call encodeURIComponent on each of these parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it not also make some sense to just send this all as structured data in the POST body? something like a JSON export or just the plain message from the exception?
Maybe we can try the service @dmsnell found? (also for 1%) |
Apparently there are other similar services: |
I made a PR connecting to one of these services. |
d40c1e2
to
12847b7
Compare
@scruffian What's the status of this one? |
@apeatling it's on my list for this week... |
👌 |
12847b7
to
3bffe59
Compare
@blowery would appreciate your thoughts on this... |
@@ -148,12 +149,15 @@ build: install build-$(CALYPSO_ENV) | |||
|
|||
build-css: public/style.css public/style-rtl.css public/style-debug.css public/editor.css | |||
|
|||
build-development: build-server $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js build-css | |||
build-inline-js: | |||
@$(UGLIFYJS) -o public/catch-js-errors.js catch-js-errors.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a separate build process for this one file? Can we fit into the current build process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current build process puts the files into one bundle. This needs to be a separate file for the reasons @blowery mentions here: #1868 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even then, our current process supports building different chunks or we can make it build a separate file. The idea is to use the same process and tools like webpack, instead of using uglify on its own.
Have you looked at the Sentry client for inspiration and probably some tricks? |
localStorage.setItem( 'log-errors', true ); | ||
|
||
// set up handler to POST errors | ||
window.onerror = debounce( function( message, scriptUrl, lineNumber, columnNumber, error ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to check to see if window.onerror was already set and call the previous version after doing our work
Yep this is golden https://github.com/getsentry/raven-js/blob/master/src/raven.js#L635 I have noticed that |
Wow. That's.... wow. Much wow. Such danger. The noise must be incredible. To elaborate, that code is replacing methods on Host objects. I would not screw with host objects, as the behavior of host objects is entirely undefined. https://es5.github.io/ has a lot of good info on all the crazy things host objects are allowed to do. TL;DR: They can do anything they want. Though I guess it's working for Raven? Just gives me the willies. |
One other thing we would want, but it can come separately if it doesn't make sense here, is some frequency of error events. I understand the extended mobile endpoint will do some throttling for us, so we would get a skewed reporting for frequency. But can we also hook into the analytics module somehow? |
xhr.open( 'POST', 'https://public-api.wordpress.com/rest/v1.1/js-error?http_envelope=1', true ); | ||
xhr.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' ); | ||
|
||
params = 'client_id=39911&client_secret=cOaYKdrkgXz8xY7aysv4fU6wL6sK5J8a6ojReEIAPwggsznj4Cb6mW0nffTxtYT8&error=' + stringifyErrorForUrlParams( error ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to be able to get these from the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sure. When you do the set, you should set the value to either true or false, depending on which way the 1% falls. When you come back in, if it's already set, you don't bother recalculating it. That way it isn't a 1% chance per visit and it doesn't walk up. |
var now = Date.now(); | ||
|
||
if ( ( now - lastCall ) < delay ) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably want to stash the error we would have logged in an array or stack so we don't lose errors to the debouncer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to do this, but I'd like to get this PR merged. Can we handle this better in the future if we find we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will we know we're missing events? :)
3d880f9
to
992f49a
Compare
This is what I did, but I did like the idea of it walking up over time, so that we catch more and more errors. I agree that it's better to control that ourselves though. |
Maybe we could run this for all users on the wpcalypso/horizon environment first? |
LGTM, 👍 for enabling only in horizon/staging first. |
I'm happy to get this out the door to staging as is |
Thanks, I added a commit to exclude from production. Good to 🚢 ? |
🚢 |
This required a change in how the module entries are built. Before that, webpack module system was included into the `vendor` module. Since we want to load `catch-js-errors` first, we need to load the module system before that so it is now extracted into a `common.js` file. For the next changes, I think it would be probably better to exclude this file from webpack's build and simply include it like third party services (olark...) in the page.
…eadable, and only assign 1% of users
3170866
to
644553c
Compare
Try catching JS errors and sending them to the API
🎉 👍 💯 |
This will catch JS errors in production and send them to the API.
TODOs
To test, edit some code so it throws a JS error. You should see the API request happen in the Network tab.
To make sure you are included in logging add this to your local storage:
localStorage.setItem('log-errors', true);
props @drewblaisdell and @Tug.