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?
-
Not sure why Google hasn't ported the nodejs stackdriver plugin to the client. If anyone gets a browserify node stackdriver working with webpack, and typescript, please comment! – Josh Hibschman Aug 30 '17 at 15:41
2 Answers
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

- 7,311
- 3
- 31
- 51
-
What is the difference between reporting errors through stackdriver logs and "Stackdriver Error Reporting"? – Josh Hibschman Aug 30 '17 at 15:44
-
1@y3sh Stackdriver Error Reporting is a crash reporting solution: it is not just a list of entries, but it groups errors meaningfully and track the counts of each group. – Steren Aug 30 '17 at 16:08
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
- Write your log messages as JSON to port 24224 (see the in_forward documentation)
or
- Write your logs to disk and tell the agent to watch those files (see the in_tail documentation).
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.

- 727
- 4
- 12
-
Thanks for your answer. I went with a server solution where I created a REST API for logging, deployed to a node.js AppEngine instance where the agent already is running. Then it's just a matter of writing to /var/log/app_engine/custom_logs/client.log.json in the Stackdriver JSON log entry format. – Jonas K Aug 28 '16 at 22:23
-
You are correct, this is a solution. I posted an alternate answer to your question that might help you getting rid of this proxy AppEngine instance. – Steren Sep 06 '16 at 11:37