問題:當(dāng)我嘗試使用錯誤報告功能記錄錯誤時,它不會發(fā)送到錯誤報告器。這是文檔我這樣實例化:const projectID = "correct-project-id"var ErrorClient *errorreporting.Clientfunc MakeErrorReporter() { var err error ctx := context.Background() ErrorClient, err = errorreporting.NewClient(ctx, projectID, errorreporting.Config{ ServiceName: "easyLanding", OnError: func(err error) { log.Printf("Could not log error: %v", err) }, }) if err != nil { msg := fmt.Sprintf("this is the fatal err", err.Error()) log.Fatal(msg) } defer ErrorClient.Close()}然后我這樣稱呼它:func LogErr(err error, location string, userId uint) string { errCode := RandStringRunes(4) msg := fmt.Sprintf("Code: %v | Error: %v | Location: %v", errCode, err.Error(), location) var email string if userId == 0 { email = "system" } else { email, _ = GetUserEmail(userId) } if viper.GetString("debug") == "false" { logger.Logger.Error().Msgf("Just ran the error with client %v", errorReporting.ErrorClient.Report) if errorReporting.ErrorClient == nil { logger.Logger.Error().Msg("Error client is nil") } else { logger.Logger.Error().Msg("Error client is NOT nil") } email = fmt.Sprintf("%s - %s", email, location) errorReporting.ErrorClient.Report(errorreporting.Entry{ Error: err, User: email, }) label := map[string]string{} label["key"] = "simpleMessage" logger.InfoLogger.Log(logging.Entry{ Severity: logging.Info, Payload: msg, Labels: label, InsertID: "", }) } else { logger.Logger.Error().Msg(msg) logger.Logger.Error().Msg(email) } return errCode}日志Error client is NOT nil運行,所以我知道它已經(jīng)啟動,但沒有出現(xiàn)任何警報。我還通過一個特殊的 URL 端點觸發(fā)它,該端點在每次點擊時記錄一個錯誤(或應(yīng)該)。
1 回答

寶慕林4294392
TA貢獻(xiàn)2021條經(jīng)驗 獲得超8個贊
我在我這邊使用了你的代碼,一切都按預(yù)期工作,如果你在 GCP 控制臺上看不到任何錯誤,這表明錯誤報告 API 未啟用,因此你看不到任何錯誤。
- 1 回答
- 0 關(guān)注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消