目前,我看到所有身份验证错误的错误状态,感觉总错误图表中有很多额外的噪音。我查看了 https://github.com/DataDog/dd-trace-js/pull/909
并尝试使用为 graphql 提供的自定义执行
import ddTrace from 'dd-trace'
let tracer = ddTrace.init({
debug: false
}) // initialized in a different file to avoid hoisting.
tracer.use('graphql', {
hooks: {
execute: (span, args, res) => {
if (res && res.errors && res.errors[0] && res.errors[0].status !== 403) {
span?.setTag('error', res.errors)
}
}
}
})
export default tracer
但是,只有 403 错误的 res 会进入错误状态。请帮助我如何实现这一目标。
答案 0 :(得分:0)
更新:我在跟踪客户端存储库中发现了这段代码:
tracer.use('graphql', {
hooks: {
execute: (span, args, res) => {
if (res?.errors?.[0]?.status === 403) { // assuming "status" is a number
span?.setTag('error', null) // remove any error set by the tracer
}
}
}
})
https://github.com/DataDog/dd-trace-js/issues/1249
也许会有帮助
旧消息:
没关系。似乎我的解决方案仅适用于 express,graphql 不支持该属性
您可能只想修改 http 模块中的 validateStatus 属性:
回调函数来确定是否有错误。它应该以状态码作为唯一参数,成功时返回真,错误时返回假
https://datadoghq.dev/dd-trace-js/interfaces/plugins.http.html#validatestatus
例如,您应该能够将 403 标记为不是错误,如下所示:
const tracer = require('dd-trace').init();
tracer.use('express', {
validateStatus: code => code < 400 && code != 403
})