-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore(explore): Add in cross event query param #103666
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
nsdeschenes
merged 18 commits into
master
from
nd/exp-600/chore-explore-add-in-cross-event-query-param
Nov 27, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8ab07e3
:sparkles: Add in new cross event param file
nsdeschenes d48468d
:label: Update writable query param type
nsdeschenes cceabb2
:necktie: Add in cross events to readable query params
nsdeschenes 8b1f1a9
:necktie: Add in helper functions for cross events query param
nsdeschenes f8ed5fe
:rotating_light: Resolve TS issues
nsdeschenes 4999943
:recycle: Refactor cross event param to be json serializable array of…
nsdeschenes 5fe43c8
:necktie: Rework how set query params works for cross events so we ca…
nsdeschenes 4c299df
:necktie: Apply bugbot suggestion
nsdeschenes 9425a69
:bug: Fix JSON encoding of cross events
nsdeschenes 08b16af
:recycle: Just accept new array
nsdeschenes b7ab8b0
:white_check_mark: Add in tests for cross event hooks
nsdeschenes 3752842
:rotating_light: Remove export from isCrossEvent
nsdeschenes 957cf1a
:rotating_light: Ignore new things being added as they're not fully u…
nsdeschenes 3ae27f1
:fire: Remove knip ignore because it breaks more things
nsdeschenes c80b58c
:necktie: Add in cross event type guard
nsdeschenes b5bd9fb
:construction: Add in very basic event querying dropdown to make knip…
nsdeschenes 63ea612
:rotating_light: Fix TSC issue
nsdeschenes 14bfd29
:bug: check the value type as well
nsdeschenes 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import {useMemo, type ReactNode} from 'react'; | ||
|
|
||
| import {renderHookWithProviders} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {useResettableState} from 'sentry/utils/useResettableState'; | ||
| import { | ||
| defaultAggregateFields, | ||
| defaultAggregateSortBys, | ||
| defaultFields, | ||
| defaultQuery, | ||
| defaultSortBys, | ||
| } from 'sentry/views/explore/metrics/metricQuery'; | ||
| import { | ||
| QueryParamsContextProvider, | ||
| useQueryParamsCrossEvents, | ||
| useSetQueryParamsCrossEvents, | ||
| } from 'sentry/views/explore/queryParams/context'; | ||
| import {defaultCursor} from 'sentry/views/explore/queryParams/cursor'; | ||
| import {Mode} from 'sentry/views/explore/queryParams/mode'; | ||
| import {ReadableQueryParams} from 'sentry/views/explore/queryParams/readableQueryParams'; | ||
|
|
||
| const mockSetQueryParams = jest.fn(); | ||
|
|
||
| function Wrapper({children}: {children: ReactNode}) { | ||
| const [query] = useResettableState(defaultQuery); | ||
|
|
||
| const readableQueryParams = useMemo( | ||
| () => | ||
| new ReadableQueryParams({ | ||
| aggregateCursor: defaultCursor(), | ||
| aggregateFields: defaultAggregateFields(), | ||
| aggregateSortBys: defaultAggregateSortBys(defaultAggregateFields()), | ||
| cursor: defaultCursor(), | ||
| extrapolate: true, | ||
| fields: defaultFields(), | ||
| mode: Mode.AGGREGATE, | ||
| query, | ||
| sortBys: defaultSortBys(defaultFields()), | ||
| crossEvents: [{query: 'foo', type: 'spans'}], | ||
| }), | ||
| [query] | ||
| ); | ||
|
|
||
| return ( | ||
| <QueryParamsContextProvider | ||
| isUsingDefaultFields={false} | ||
| queryParams={readableQueryParams} | ||
| setQueryParams={mockSetQueryParams} | ||
| shouldManageFields={false} | ||
| > | ||
| {children} | ||
| </QueryParamsContextProvider> | ||
| ); | ||
| } | ||
|
|
||
| describe('QueryParamsContext', () => { | ||
| describe('crossEvents', () => { | ||
| describe('useQueryParamsCrossEvents', () => { | ||
| it('should return the crossEvents', () => { | ||
| const {result} = renderHookWithProviders(() => useQueryParamsCrossEvents(), { | ||
| additionalWrapper: Wrapper, | ||
| }); | ||
|
|
||
| expect(result.current).toEqual([{query: 'foo', type: 'spans'}]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useSetQueryParamsCrossEvents', () => { | ||
| it('should set the crossEvents', () => { | ||
| renderHookWithProviders( | ||
| () => { | ||
| const setCrossEvents = useSetQueryParamsCrossEvents(); | ||
| setCrossEvents([{query: 'bar', type: 'logs'}]); | ||
| return useQueryParamsCrossEvents(); | ||
| }, | ||
| {additionalWrapper: Wrapper} | ||
| ); | ||
|
|
||
| expect(mockSetQueryParams).toHaveBeenCalled(); | ||
| expect(mockSetQueryParams).toHaveBeenCalledWith({ | ||
| crossEvents: [{query: 'bar', type: 'logs'}], | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type {Location} from 'history'; | ||
|
|
||
| import {defined} from 'sentry/utils'; | ||
|
|
||
| type CrossEventType = 'logs' | 'spans' | 'metrics'; | ||
|
|
||
| export interface CrossEvent { | ||
| query: string; | ||
| type: CrossEventType; | ||
| } | ||
|
|
||
| export function getCrossEventsFromLocation( | ||
| location: Location, | ||
| key: string | ||
| ): CrossEvent[] | undefined { | ||
| let json: any; | ||
|
|
||
| if (!defined(location.query?.[key]) || Array.isArray(location.query?.[key])) { | ||
| return undefined; | ||
| } | ||
nsdeschenes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| json = JSON.parse(location.query?.[key]); | ||
nsdeschenes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (Array.isArray(json) && json.every(isCrossEvent)) { | ||
| return json; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| export function isCrossEventType(value: string): value is CrossEventType { | ||
| return value === 'logs' || value === 'spans' || value === 'metrics'; | ||
| } | ||
|
|
||
| function isCrossEvent(value: any): value is CrossEvent { | ||
| return ( | ||
| defined(value) && | ||
| typeof value === 'object' && | ||
| typeof value.query === 'string' && | ||
| typeof value.type === 'string' && | ||
| isCrossEventType(value.type) | ||
| ); | ||
| } | ||
nsdeschenes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.