From 85408af250d8c3054e2a2a6e5177efbddd3d87ac Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 8 Apr 2024 22:19:05 +0100 Subject: [PATCH] feat(remix): Skip span creation for `OPTIONS` and `HEAD` requests. (#11149) Fixes: https://github.com/getsentry/sentry-javascript/issues/11105 Skips span creation for `OPTIONS` and `HEAD` requests in `wrapRequestHandler`, which apparently are the unwanted requests mentioned in #11105. We can also implement a more precise filtering but this seems to resolve it on my local test application. --- packages/remix/src/utils/instrumentServer.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/remix/src/utils/instrumentServer.ts b/packages/remix/src/utils/instrumentServer.ts index 1283f98fec1a..f51e857c59d0 100644 --- a/packages/remix/src/utils/instrumentServer.ts +++ b/packages/remix/src/utils/instrumentServer.ts @@ -446,6 +446,13 @@ function wrapRequestHandler(origRequestHandler: RequestHandler, build: ServerBui return origRequestHandler.call(this, request, loadContext); } + const upperCaseMethod = request.method.toUpperCase(); + + // We don't want to wrap OPTIONS and HEAD requests + if (upperCaseMethod === 'OPTIONS' || upperCaseMethod === 'HEAD') { + return origRequestHandler.call(this, request, loadContext); + } + return runWithAsyncContext(async () => { // eslint-disable-next-line deprecation/deprecation const hub = getCurrentHub();