Skip to content Skip to sidebar Skip to footer

Angular Errors Log Send To Elasticsearch

I have an angular project version 10.0.2 I want to log all errors on developer console to elastic search. When I catch an error on the global error handler my handler inside like t

Solution 1:

The @elastic/elasticsearch npm package is a NodeJS-only package so you won't be able to use it in your frontend Angular app. The reason being, it's not safe (and actually not even supported).

Giving public-ish access to your ES cluster such that people can inspect the ES queries is not recommended. Esp. something like

this.hbhttp.post(`${this.location}/hbizclient/_doc`...

because that looks like a live ES instance that may or may not be protected from malicious _search queries that could bring down your cluster, or even DELETE calls that may clear your logs altogether.

What you could do instead is to spin up a little nodejs backend log-forwarding service (GCP cloud function, AWS Lambda, Netlify, ...) which would utilize the @elastic/elasticsearch package but sit behind a gateway which you can control. You'd then send post your POST /../_doc to that service which'd forward the payload to ES.

Post a Comment for "Angular Errors Log Send To Elasticsearch"