Skip to content

fix(tracing-internal): Fix case when originalURL contain query params #9531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/tracing-internal/src/node/integrations/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ export function preventDuplicateSegments(
reconstructedRoute?: string,
layerPath?: string,
): string | undefined {
const originalUrlSplit = originalUrl?.split('/').filter(v => !!v);
// filter query params
const normalizeURL = stripUrlQueryAndFragment(originalUrl || '');
const originalUrlSplit = normalizeURL?.split('/').filter(v => !!v);
let tempCounter = 0;
const currentOffset = reconstructedRoute?.split('/').filter(v => !!v).length || 0;
const result = layerPath
Expand Down
16 changes: 16 additions & 0 deletions packages/tracing-internal/test/node/express.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ describe('unit Test for preventDuplicateSegments', () => {
const result1 = preventDuplicateSegments(originalUrl, reconstructedRoute, layerPath);
expect(result1).toBe('1234');
});

it('should prevent duplicate segment v1 originalUrl with query param without trailing slash', () => {
const originalUrl = '/api/v1/1234?queryParam=123';
const reconstructedRoute = '/api/v1';
const layerPath = '/v1/1234';
const result1 = preventDuplicateSegments(originalUrl, reconstructedRoute, layerPath);
expect(result1).toBe('1234');
});

it('should prevent duplicate segment v1 originalUrl with query param with trailing slash', () => {
const originalUrl = '/api/v1/1234/?queryParam=123';
const reconstructedRoute = '/api/v1';
const layerPath = '/v1/1234';
const result1 = preventDuplicateSegments(originalUrl, reconstructedRoute, layerPath);
expect(result1).toBe('1234');
});
});
describe('preventDuplicateSegments should handle empty input gracefully', () => {
it('Empty input values', () => {
Expand Down