Skip to content

Commit

Permalink
Early return in rack middleware for HTTP OPTIONS requests
Browse files Browse the repository at this point in the history
  • Loading branch information
natikgadzhi committed Nov 30, 2023
1 parent ff66f7b commit 5d990bc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sentry-ruby/lib/sentry/rack/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ def capture_exception(exception, env)
end

def start_transaction(env, scope)
# Tell Sentry to not sample this transaction if this is an HTTP OPTIONS or HEAD request.
# Return early to avoid extra work that's not useful anyway, because this
# transaction won't be sampled.
# If we return nil here, it'll be passed to `finish_transaction` later, which is safe.
return nil if IGNORED_HTTP_METHODS.include?(env["REQUEST_METHOD"])

options = {
name: scope.transaction_name,
source: scope.transaction_source,
op: transaction_op
}

# Tell Sentry to not sample this transaction if this is an HTTP OPTIONS or HEAD request.
if IGNORED_HTTP_METHODS.include?(env["REQUEST_METHOD"])
options.merge!(sampled: false)
end

transaction = Sentry.continue_trace(env, **options)
Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
Expand Down

0 comments on commit 5d990bc

Please sign in to comment.