-
Notifications
You must be signed in to change notification settings - Fork 682
fix: Normalize uppercase trace ids to lowercase in URL #3485
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
yurishkuro
merged 12 commits into
jaegertracing:main
from
samar-703:fix/uppercase-traceId-normalization
Mar 9, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d42165
fix: normalize uppercase trace IDs to lowercase in URL
samar-703 b90225b
fix: preserve location.state during URL normalization
samar-703 7e514d0
fix: using relative path for URL normalization
samar-703 bc9a634
fix: addressed copilot feedback
samar-703 332eb86
fix: used getUrl function that already exists
samar-703 d1ea8d3
refactor: simplify URL construction for better readability
samar-703 edb1b4c
test: added integration test for tracePage uppercase to lowercase tra…
samar-703 77ab8b7
fix: normalize uppercase trace IDs in URL to prevent double-fetch
samar-703 7180889
fix: addressed all copilot suggestions
samar-703 f9fc70f
fix: extract trace ID normalization into custom hook
samar-703 9097997
refactor: use React namespace for useEffect in useNormalizeTraceId
samar-703 bc356ee
fix: address review feedback on useNormalizeTraceId hook
samar-703 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/jaeger-ui/src/components/TracePage/useNormalizeTraceId.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) 2026 The Jaeger Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const mockNavigate = jest.fn(); | ||
| let mockLocation: { search: string; state: unknown } = { search: '', state: null }; | ||
|
|
||
| jest.mock('react-router-dom-v5-compat', () => ({ | ||
| ...jest.requireActual('react-router-dom-v5-compat'), | ||
| useNavigate: () => mockNavigate, | ||
| useLocation: () => mockLocation, | ||
| })); | ||
|
|
||
| // Simplified mock sufficient for testing normalization logic; | ||
| // URL prefix handling is tested separately in url/index.test.js | ||
| jest.mock('./url', () => ({ | ||
| getUrl: (id: string) => `/trace/${id}`, | ||
| })); | ||
|
|
||
| import { renderHook } from '@testing-library/react'; | ||
|
|
||
| import { useNormalizeTraceId } from './useNormalizeTraceId'; | ||
|
|
||
| describe('useNormalizeTraceId', () => { | ||
| beforeEach(() => { | ||
| mockNavigate.mockClear(); | ||
| mockLocation = { search: '', state: null }; | ||
| }); | ||
|
|
||
| it('normalizes uppercase trace IDs to lowercase in the URL', () => { | ||
| const uppercaseTraceId = 'ABC123DEF456'; | ||
| const lowercaseTraceId = uppercaseTraceId.toLowerCase(); | ||
|
|
||
| const { result } = renderHook(() => useNormalizeTraceId(uppercaseTraceId)); | ||
|
|
||
| expect(result.current).toBe(lowercaseTraceId); | ||
| expect(mockNavigate).toHaveBeenCalledWith(`/trace/${lowercaseTraceId}`, { | ||
| replace: true, | ||
| state: null, | ||
| }); | ||
| }); | ||
|
|
||
| it('preserves query parameters during trace ID normalization', () => { | ||
| const uppercaseTraceId = 'ABC123DEF456'; | ||
| const lowercaseTraceId = uppercaseTraceId.toLowerCase(); | ||
| const searchParams = '?uiFind=foo&x=1'; | ||
|
|
||
| mockLocation = { search: searchParams, state: null }; | ||
|
|
||
| const { result } = renderHook(() => useNormalizeTraceId(uppercaseTraceId)); | ||
|
|
||
| expect(result.current).toBe(lowercaseTraceId); | ||
| expect(mockNavigate).toHaveBeenCalledWith(`/trace/${lowercaseTraceId}${searchParams}`, { | ||
| replace: true, | ||
| state: null, | ||
| }); | ||
| }); | ||
|
|
||
| it('does not redirect when trace ID is already lowercase', () => { | ||
| const lowercaseTraceId = 'abc123def456'; | ||
|
|
||
| const { result } = renderHook(() => useNormalizeTraceId(lowercaseTraceId)); | ||
|
|
||
| expect(result.current).toBe(lowercaseTraceId); | ||
| expect(mockNavigate).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
24 changes: 24 additions & 0 deletions
24
packages/jaeger-ui/src/components/TracePage/useNormalizeTraceId.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright (c) 2026 The Jaeger Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import * as React from 'react'; | ||
| import { useNavigate, useLocation } from 'react-router-dom-v5-compat'; | ||
|
|
||
| import { getUrl } from './url'; | ||
|
|
||
| // Custom hook that normalizes a trace ID to lowercase in the URL | ||
| export function useNormalizeTraceId(traceID: string): string { | ||
| const normalizedTraceID = traceID.toLowerCase(); | ||
| const navigate = useNavigate(); | ||
| const location = useLocation(); | ||
|
|
||
| React.useEffect(() => { | ||
| if (traceID && traceID !== normalizedTraceID) { | ||
| const url = getUrl(normalizedTraceID); | ||
| navigate(`${url}${location.search}`, { replace: true, state: location.state }); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [traceID, normalizedTraceID]); | ||
|
|
||
| return normalizedTraceID; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL-normalization behavior is implemented in the functional
TracePagewrapper (hook call + passing a normalizedparams.id), but the existingindex.test.jssuite only rendersTracePageImpldirectly. The new unit tests coveruseNormalizeTraceId(), but they don’t verify that the real TracePage route actually invokes the hook and performs navigation whenparams.idis uppercase. Adding a small integration test that renders the default export (withRouteProps wrapper) under a router and assertsuseNavigate(..., { replace: true })is called would prevent regressions where the hook is accidentally removed or the normalizedparams.idis no longer passed down.