gpt4 book ai didi

javascript - 如何在新的 @sentry/node API 中包含标签?

转载 作者:太空宇宙 更新时间:2023-11-03 21:51:41 24 4
gpt4 key购买 nike

在“@sentry/node”发布之前,我使用了 raven 模块。在我的所有错误中包含标签就像在配置 Raven 时在选项对象中包含标签属性一样简单。

Raven.config(DSN, {
tags: {...}
})

使用新 API 时如何包含标签?到目前为止我已经尝试过:

Sentry.init({
dsn: DSN,
tags: {
process_name: 'webserver',
},
})

Sentry.configureScope(scope => {
scope.setTag('process_name', 'webserver')
})

但这两种尝试都不起作用。

最佳答案

根据docs

您可以使用Sentry.configureScope来配置Sentry实例的范围,其中包括标签。

Sentry.configureScope((scope) => {
scope.setTag("my-tag", "my value");
scope.setUser({
id: 42,
email: "john.doe@example.com"
});
});

或者,如果您只想通过一个特定事件发送数据,则可以使用 Sentry.withScope

Sentry.withScope(scope => {
scope.setTag("my-tag", "my value");
scope.setLevel('warning');
// will be tagged with my-tag="my value"
Sentry.captureException(new Error('my error'));
});

// will not be tagged with my-tag
Sentry.captureException(new Error('my other error'));

关于javascript - 如何在新的 @sentry/node API 中包含标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52712615/

24 4 0