I'd like to be able to view client side errors in Google Cloud Log viewer. Is it possible to create log entries from an AngularJS application and if so how?
Stackdriver Error Reporting is specifically designed for application errors, I encourage you to use it rather than Stackdriver Logging to report errors.
For client-side error reporting, you will need to use the HTTP report
API with an API key.
I wrote an JavaScript library to help you call this endpoint from a client: https://github.com/GoogleCloudPlatform/stackdriver-errors-js
I did not test it yet with an Angular app (but there is a tracking issue for this). It is flagged as experimental, but should already be quite stable. Your contributions are welcome if you encounter issues or would like to help
If you really want to see the errors in the Logs Viewer, the way to do this on GCE or AWS EC2 is to install the Stackdriver Logging agent and either
or
The forwarding port is already pre-configured in the agent. If you choose to go with log files, you would have to write your own configuration pointing the agent at your log files.
Both of the above are server-side, so your client code would need to transfer the errors to the server somehow. It's also possible to expose the forwarding port to the client, but see below.
Another alternative is to use the Stackdriver Error Reporting API and post there either from the server or directly from your client code. That way the errors will appear in the Stackdriver Error Reporting console rather than the Logs Viewer.
Keep in mind that having the client write directly to either the agent port or the Error Reporting API is inherently insecure, as the relevant port/API key would have to be exposed to the internet (so entries can be spoofed and an attacker can, e.g., use up your quota).
Thank you for using Google Stackdriver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With