角度误差日志发送到elasticsearch [英] angular errors log send to elasticsearch

查看:67
本文介绍了角度误差日志发送到elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角度项目版本10.0.2我想在开发者控制台上记录所有错误以进行弹性搜索.当我在全局错误处理程序上捕获到错误时,我的处理程序会像这样.

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 this.

export class GlobalErrorHandlerService extends ErrorHandler {
    constructor(private log: LogService) {
        super();
    }
    handleError(error: any) {
        var client = new Client();
        if (error instanceof HttpErrorResponse) {
            this.log.level = LogLevel.Error;
            this.log.error("API/Back-End Proccess request error   " + JSON.stringify(error), JSON.stringify(error));
        }
        else {
            this.log.level = LogLevel.Warn;
            this.log.warn("Client side error " + JSON.stringify(error), JSON.stringify(error));
        }
        this.log.publishers.push(error);
    }
} 

LogService是我的自定义日志服务.但是我可以更改它以捕获错误我像这样寄给我弹性的.

LogService is my custom log service. But I can change it to catch errors i send it elastic like this.

条目:包含错误信息

log(entry: LogEntry): Observable<boolean> {

        var headers = new HttpHeaders();
        const date = moment();

        let body = {
            "@timestamp": date,
            "index": "clientapplication",
            "body": {
                "entry": entry,
                "date": date
            },
            "user": {
                "fullname": "ahmetu",
                "userrecordno": "190909"
            }
        }

        headers.append('Content-Type', 'application/json');
        headers.append('Accept', 'application/json');
        return this.hbhttp.post(`${this.location}/hbizclient/_doc`, body, headers)
    }

我在 log.elastic.ts 中执行了此操作我写了自定义的日志记录操作.我的文件夹结构如下

i did this operation in log.elastic.ts i writen custom a logging operation. my folder stracture as below

实际上,我可以记录所有错误,但我只是想学习.我如何使用Elasticsearch自己的npm软件包,然后将所有错误从角度发送到弹性,然后我可以在kibana上看到所有这些错误

Actually i can logging all errors but i just want to learn. how can i use Elasticsearch own npm package then send all error from angular to elastic then i can see all of these on kibana

感谢建议

推荐答案

@ elastic/elasticsearch npm软件包是一个仅NodeJS 软件包,因此您将无法在前端Angular应用中使用它.原因是,这是不安全的(实际上甚至不受支持).

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).

不建议授予公众对您的ES群集的访问权限,以便人们可以检查ES查询.Esp.像

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`...

因为它看起来像是一个实时ES实例,可能受到或可能不受恶意的 _search 查询的攻击,这些查询可能会导致群集崩溃,甚至可能清除的 DELETE 调用您的日志一共.

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.

您可以做的是启动一个小的Node.js后端日志转发服务(GCP云功能,AWS Lambda,Netlify等),该服务将使用 @ elastic/elasticsearch 包但要坐在您可以控制的网关后面.然后,将您的 POST/../_ doc 发送到该服务,该服务会将有效负载转发给ES.

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.

这篇关于角度误差日志发送到elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆