1

我已按照此处的 Node.js 说明进行操作

我有一个快速服务器部署到 Cloud Run。如果我使用 express 中间件并将错误发送到next(),如文档中所述,它会显示在错误报告中。

但是,如果我以report如下各种形式使用该方法,则不会报告任何内容。

// Report an Error object
errors.report(new Error('My error message'), () => {
  console.log('Done reporting Error object!');
});

// Report an error by provided just a string
errors.report('My error message', () => {
  console.log('Done reporting error string!');
});

// Use the error message builder to customize all fields ...
const errorEvent = errors.event();

// Add error information
errorEvent.setMessage('My error message');
errorEvent.setUser('root@nexus');

// Report the error event
errors.report(errorEvent, () => {
  console.log('Done reporting error event!');
});

我尝试将 IAM 角色“Error Reporter Writer”添加到我用于部署到 Cloud Run 的(AppEngine 默认)服务帐户中,但它仍然不起作用。

TS 编译器也不接受示例中使用的回调函数,因此要么示例已过时,要么 TS 类型定义错误。

有任何想法吗?

4

1 回答 1

0

我试图重现你的错误并发现了一些事情,比如这个警告:

WARN:@google-cloud/error-reporting:当且仅当 NODE_ENV 环境变量设置为“生产”时,stackdriver 错误报告客户端配置为报告错误。不会报告错误。要始终报告错误,无论 NODE_ENV 的值如何,请将 reportMode 配置选项设置为“always”。

要使错误报告客户端库与 Cloud Run 一起使用,请确保:

  1. Stackdriver 错误报告 API 已启用。
  2. Cloud Run 服务必须有一个 名为的环境变量NODE_ENV,其中包含 value production或者reportMode 在实例化客户端时添加:
const errors = new ErrorReporting({
    projectId: 'my-project-id',
    reportMode: 'always',
    }

这是我能够使用report()方法提交到错误报告的示例:

在此处输入图像描述

于 2022-01-03T09:59:13.247 回答