From 3bbc1a57676a90296e483d312113fbfd9f9d7eb8 Mon Sep 17 00:00:00 2001 From: Richard Simko <1245031+richardsimko@users.noreply.github.com> Date: Tue, 30 May 2023 17:08:05 +0200 Subject: [PATCH] fix(node): Strip query and fragment from request URLs without route parameters (#8213) Fix transaction names having query params or fragments attached when request URLs without any route parameters were encountered under [certain conditions](https://github.com/getsentry/sentry-javascript/pull/8213#issuecomment-1564243501), Fixes #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; } }