diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c0bcb28a..0ad988113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ - Pick up config.cron.default_timezone from Rails config ([#2213](https://github.com/getsentry/sentry-ruby/pull/2213)) +### Bug Fixes + +- Sentry will not record traces of HTTP OPTIONS and HEAD requests in Rack and Rails apps [#2181](https://github.com/getsentry/sentry-ruby/pull/2181) + ## 5.15.2 ### Bug Fixes @@ -65,7 +69,6 @@ ### Bug Fixes - Network errors raised in `Sentry::HTTPTransport` will no longer be reported to Sentry [#2178](https://github.com/getsentry/sentry-ruby/pull/2178) -- Sentry will not record traces of HTTP OPTIONS and HEAD requests in Rack and Rails apps [#2181](https://github.com/getsentry/sentry-ruby/pull/2181) ## 5.14.0 diff --git a/sentry-rails/lib/sentry/rails/action_cable.rb b/sentry-rails/lib/sentry/rails/action_cable.rb index 155377466..b8dd51a1b 100644 --- a/sentry-rails/lib/sentry/rails/action_cable.rb +++ b/sentry-rails/lib/sentry/rails/action_cable.rb @@ -3,6 +3,7 @@ module Rails module ActionCableExtensions class ErrorHandler OP_NAME = "websocket.server".freeze + IGNORED_HTTP_METHODS = ["HEAD", "OPTIONS"].freeze class << self def capture(connection, transaction_name:, extra_context: nil, &block) @@ -33,6 +34,8 @@ def capture(connection, transaction_name:, extra_context: nil, &block) end def start_transaction(env, scope) + return nil if IGNORED_HTTP_METHODS.include?(env["REQUEST_METHOD"]) + options = { name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME } transaction = Sentry.continue_trace(env, **options) Sentry.start_transaction(transaction: transaction, **options) diff --git a/sentry-rails/lib/sentry/rails/capture_exceptions.rb b/sentry-rails/lib/sentry/rails/capture_exceptions.rb index 8d93784ed..5b7c28abe 100644 --- a/sentry-rails/lib/sentry/rails/capture_exceptions.rb +++ b/sentry-rails/lib/sentry/rails/capture_exceptions.rb @@ -2,6 +2,7 @@ module Sentry module Rails class CaptureExceptions < Sentry::Rack::CaptureExceptions RAILS_7_1 = Gem::Version.new(::Rails.version) >= Gem::Version.new("7.1.0.alpha") + IGNORED_HTTP_METHODS = ["HEAD", "OPTIONS"].freeze def initialize(_) super @@ -32,6 +33,8 @@ def capture_exception(exception, env) end def start_transaction(env, scope) + return nil if IGNORED_HTTP_METHODS.include?(env["REQUEST_METHOD"]) + options = { name: scope.transaction_name, source: scope.transaction_source, op: transaction_op } if @assets_regexp && scope.transaction_name.match?(@assets_regexp)