getsentry / getsentry/sentry-ruby

Custom transaction status code for exceptions

Đang mở
#2,333 2 bình luận 0 reaction 1 người được giao Xem trên GitHub

@sl0thentr0py đang làm issue này rồi.

Từ ngày 9/7/2024.

Improvement Ruby sentry-rails Spans
Ngôn ngữ chính
Ruby
Star
988
Fork
542
Merge trung bình
17 giờ 40 phút
Pull request đã merge (30 ngày)
19

Mô tả

Describe the idea

The idea is to allow us to set custom status code for when a exception occurs during a transaction, something like

Sentry.init do |config|
  config.exception_status_code = ->(exception) do
    case exception
    when ActiveRecord::RecordNotFound, ActionController::RoutingError
      404
    else
      500
    end
  end
end

Why do you think it's beneficial to most of the users

Sentry assumes status code 500 (internal error) for all of the exceptions during transactions. The problem is that in a production environment, by default Rails will raise ActionController::RoutingError whenever somebody tries to access a non-existing page, which will result in "internal error" transactions.

This feature allows the user to map different exceptions to different status codes, so they can ignore that without having to change the default Rails behavior.

Possible implementation

In the Sentry::Rack::CaptureExceptions we can replace the hardcoded 500 status code from the rescue Exception with a configurable lambda that returns the desired status code for the specific exception.

Another possibility, is to bake this rule into Sentry (404 for routing errors), but I think that would be a shift in the current behavior which might not be ideal

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.