【问题标题】:Sentry on Symfony: how to exclude `NotFoundHttpException`Symfony 上的哨兵:如何排除 `NotFoundHttpException`
【发布时间】:2021-01-13 19:58:10
【问题描述】:

我正在使用 SentryBundle 将 Sentry 集成到我的 Symfony 应用程序中。

我不想记录“NotFoundExceptions”,所以我这样配置捆绑包:

sentry:
    dsn: '%env(SENTRY_DSN)%'
    register_error_listener: false # Disables the ErrorListener
    monolog:
        error_handler:
            enabled: true
            level: error
    messenger:
        enabled: true # flushes Sentry messages at the end of each message handling
        capture_soft_fails: true # captures exceptions marked for retry too
    options:
        environment: '%kernel.environment%'
#        release: '%env(VERSION)%' #your app version
        excluded_exceptions:
            - Symfony\Component\HttpKernel\Exception\NotFoundHttpException

不幸的是,这似乎还不够,因为异常继续记录在 Sentry 中。

我做错了什么?

【问题讨论】:

  • 你是否按照doc 中的说明在独白配置中设置了哨兵处理程序?您也可以在那里排除特定的 http 错误代码:excluded_http_codes: [403, 404, { 400: ['^/foo', '^/bar'] }]
  • 是的,深入分析 Sentry 中的日志,我注意到了这一点,我怀疑它是由 Monolog 记录的。奇怪的是,在 Monolog 中我已经排除了 404 错误...我再看一下:谢谢!
  • 您好,您找到其他解决方案了吗?
  • 我没有进一步调查这个...我会在接下来的几天里做...我会试试这个:```独白:处理程序:哨兵:类型:服务ID:哨兵\ Monolog\Handler exclude_http_codes: [404, 405] ```
  • 对不起格式错误... 基本上我会在 Monolog config 的 Sentry 配置中直接添加键 exclude_http_codes

标签: php symfony logging sentry


【解决方案1】:

由于 excluded_exceptions 在 bundle / sdk 中不再可用,而且您不知道例如“NotFoundHttpException”。您可以简单地将 excluded_http_codes 与包装的独白处理程序一起使用。

完整示例

sentry:
  register_error_listener: false # custom monolog handler: Disables the ErrorListener to avoid duplicated log in sentry
  dsn: 'FOOBAR_DNS'
  options:
    traces_sample_rate: 0.1
  tracing:
    enabled: true
    dbal:
      enabled: true
      connection: 'default'
    cache:
      enabled: true
    twig:
      enabled: true

# sentry: log also error logs when there is no request exception
monolog:
  handlers:
    sentry:
      type: fingers_crossed
      action_level: error
      handler: sentry_main
      excluded_http_codes: [ 404, 405 ]
      buffer_size: 50
    sentry_main:
      type: sentry
      level: error
      hub_id: Sentry\State\HubInterface

【讨论】:

    猜你喜欢
    • 2022-08-23
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 2021-11-14
    • 1970-01-01
    • 2023-01-20
    相关资源
    最近更新 更多