我有带有 Sentry 的 nextjs 应用程序。我想添加新的 api 路由,例如 api/status
,但我想将其排除在发送到 Sentry 之外,因为它会很快使日志变得困惑并使用我的 qouta。
我做了一个小研究,似乎有一系列网址可以排除在跟踪之外。它称为denyUrls
。 Read more 。我尝试将我的 url 添加到此数组,但它仍然跟踪此 url 作为事件的一部分:
Sentry.init({
...
denyUrls: [
/api\/status/i,
],
...
});
我是否配置错误,或者该数组不是用于过滤事件的目的。
如果是这样,过滤这些内容的最佳方法是什么?我发现接下来要尝试的其他选项是 beforeSend
但简单地排除 url 感觉有点矫枉过正。 denyUrls
感觉更适合我想要实现的目标
最佳答案
我遇到了同样的问题并联系了支持人员。我在这里直接引用支持。
The BeforeSend and DenyUrl are options to filter error events, not transactions. For transaction events, please use the tracesSampler function as described on the page: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/sampling/#setting-a-sampling-function. Here is an example to drop all transactions that match a certain name:
tracesSampler: samplingContext => {
if(samplingContext.transactionContext.name == "GET /api/health"){
return 0.0 // never send transactions with name GET /api/health
}
return 0.2 // sampling for all other transactions
}
Note that you might need to customise the function above to better match your scenario.
希望对你有帮助;) 祝你有美好的一天。
关于next.js - 从 Sentry 事件中排除 nextjs api url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73195764/