next.js - 从 Sentry 事件中排除 nextjs api url

标签 next.js sentry

我有带有 Sentry 的 nextjs 应用程序。我想添加新的 api 路由,例如 api/status,但我想将其排除在发送到 Sentry 之外,因为它会很快使日志变得困惑并使用我的 qouta。

我做了一个小研究,似乎有一系列网址可以排除在跟踪之外。它称为denyUrlsRead 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/

相关文章:

reactjs - Next.js 模块未找到 : Can't resolve 'tls'

reactjs - 继承ReasonReact中的Nextjs App组件(pages/_app.js)

azure - 如何使用 NextJS API 将图像上传到 Azure Blob 存储?

java - Sentry:我需要使用Sentry.capture()吗?

django - 如何从对 django 的前端响应中捕获错误和异常数据以添加更多上下文

next.js - Next Js中的Bootstrap无法解析

cookies - 使用 NextAuth 跨多个域 (CORS) 进行身份验证

Sentry 问题 "Large Render Blocking Asset"和 "Uncompressed Asset"突然出现

python-3.x - 使用 Python 3 的 Sentry

sentry - Sentry 中的客户端 key 在哪里