Skip to content

Commit 5d990bc

Browse files
committed
Early return in rack middleware for HTTP OPTIONS requests
1 parent ff66f7b commit 5d990bc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sentry-ruby/lib/sentry/rack/capture_exceptions.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@ def capture_exception(exception, env)
6363
end
6464

6565
def start_transaction(env, scope)
66+
# Tell Sentry to not sample this transaction if this is an HTTP OPTIONS or HEAD request.
67+
# Return early to avoid extra work that's not useful anyway, because this
68+
# transaction won't be sampled.
69+
# If we return nil here, it'll be passed to `finish_transaction` later, which is safe.
70+
return nil if IGNORED_HTTP_METHODS.include?(env["REQUEST_METHOD"])
71+
6672
options = {
6773
name: scope.transaction_name,
6874
source: scope.transaction_source,
6975
op: transaction_op
7076
}
71-
72-
# Tell Sentry to not sample this transaction if this is an HTTP OPTIONS or HEAD request.
73-
if IGNORED_HTTP_METHODS.include?(env["REQUEST_METHOD"])
74-
options.merge!(sampled: false)
75-
end
7677

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

0 commit comments

Comments
 (0)