繁体   English   中英

如何使用谷歌云功能记录错误完整堆栈跟踪

[英]How to log errors full stack trace with google cloud functions

我在最近正在处理的一些代码库中发现了一个后端服务,如果可能的话,我想用它们各自的 Http 状态记录所有错误,以获得错误的完整堆栈跟踪。 最有可能记录来自该后端服务的错误。 下一个代码片段显示了如何使用后端服务的示例。 这是我第一次使用云功能

后端服务.ts

import { Injectable } from '@angular/core';

import { AngularFireFunctions } from '@angular/fire/compat/functions';

/**
 * Interface with the firebase backend.
 */
@Injectable({ providedIn: 'root' })
export class BackendService
{
  constructor(private _fns: AngularFireFunctions) { }

  /**
   * Call Firebase Cloud Function
   *
   * @param fName:  Function Name
   * @param params: Function Parameter Object
   */
  callFunction(fName: string, params: any) {
    const toCall = this._fns.httpsCallable(fName);

     // log errors here 
    return toCall(params) 
  }

}

使用后端服务

import { Injectable } from '@angular/core';

import { Provision, WriteProvisionCommand } from '@s4y/model/accounting/provisions';

import { BackendService } from '@bxy/utils/ngxfm/angular';
import { DbMethods } from '@bxy/model/data/db';


@Injectable()
export class RequestWithSettlementService
{
  constructor(private _backend: BackendService
              )
  {}


  deleteBill = (propId: string, tr: FTransactionRequest) => this.deleteProvision(propId, tr as any as Provision);

  deleteProvision(propId: string, tr: FTransactionRequest)
  {
    const call: WriteProvisionCommand = {
      provision: tr,
      propId,
      method: DbMethods.DELETE
    };

    return this._backend.callFunction('writeProvision', call);
  }
}

您可以在Trace 列表(在Stackdriver Trace下)检查错误堆栈。 您可以查看详细信息,例如时间戳、HTTP 方法和状态、其标签、指向相应日志条目的链接以及 Cloud Function 进行的任何后续 RPC 调用。 有关更多信息,您可以查看此代码实验室

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM