Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send browser JavaScript errors to Stackdriver Error Reporting

I have a client-side JavaScript application and I would like to report errors and exceptions to Stackdriver Error Reporting.

like image 961
Steren Avatar asked Nov 24 '16 13:11

Steren


1 Answers

Stackdriver Error Reporting can process errors coming from client-side JavaScript.

You need a Google Cloud Console project. Then enable the Stackdriver Error Reporting API and get an API key.

Reporting client-side error is done by calling the report API endpoint with an API key.


You can use this JavaScript module to normalize the exception stack traces, and send them to Stackdriver in the expected format: https://github.com/GoogleCloudPlatform/stackdriver-errors-js

Example:

<!-- Warning: This is an experimental library, do not use it on production environments -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/stackdriver-errors-concat.min.js"></script>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', function() {
  var errorHandler = new StackdriverErrorReporter();
  errorHandler.start({
    key: '<my-api-key>',
    projectId: '<my-project-id>'
  });
});
</script>
like image 195
Steren Avatar answered Oct 24 '22 02:10

Steren