简体   繁体   中英

How to log errors full stack trace with google cloud functions

There is a backend service I found in some codebase I'm recently working on and would like to log all the errors with their respective Http statuses if possible get the full stack trace of the errors. Most likely log the errors from this backend service. The next code snippet shows an example of how the backend service is used. This is my first time working with cloud functions

backend.service.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) 
  }

}

Using backend service

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);
  }
}

You can check error stack under Trace list (under Stackdriver Trace ). You can view detailed information, such as timestamp, the HTTP method and status, its labels, a link to the corresponding log entry, and any subsequent RPC call that the Cloud Function makes. For more information you can check this codelab

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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