From a4f41aaf69444ca444bf59479b4c9a198e85fef3 Mon Sep 17 00:00:00 2001 From: Richard Simko <1245031+richardsimko@users.noreply.github.com> Date: Thu, 25 May 2023 09:39:32 +0200 Subject: [PATCH] fix(express) strip query and fragment from tracing URLs (#6586) --- .../tracing-internal/src/node/integrations/express.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/tracing-internal/src/node/integrations/express.ts b/packages/tracing-internal/src/node/integrations/express.ts index 8b3bcb52fcf4..165494563eb7 100644 --- a/packages/tracing-internal/src/node/integrations/express.ts +++ b/packages/tracing-internal/src/node/integrations/express.ts @@ -1,6 +1,12 @@ /* eslint-disable max-lines */ import type { Hub, Integration, PolymorphicRequest, Transaction } from '@sentry/types'; -import { extractPathForTransaction, getNumberOfUrlSegments, isRegExp, logger } from '@sentry/utils'; +import { + extractPathForTransaction, + getNumberOfUrlSegments, + isRegExp, + logger, + stripUrlQueryAndFragment, +} from '@sentry/utils'; import { shouldDisableAutoInstrumentation } from './utils/node-utils'; @@ -335,7 +341,7 @@ function instrumentRouter(appOrRouter: ExpressRouter): void { if (urlLength === routeLength) { if (!req._hasParameters) { if (req._reconstructedRoute !== req.originalUrl) { - req._reconstructedRoute = req.originalUrl; + req._reconstructedRoute = req.originalUrl ? stripUrlQueryAndFragment(req.originalUrl) : req.originalUrl; } }