-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add explore equation to dashboards #99404
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
shruthilayaj
merged 7 commits into
master
from
shruthi/feat/add-explore-equation-to-dashboards
Sep 15, 2025
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8bcc9c
check in progres
shruthilayaj 716161c
oops
shruthilayaj 26c7ac8
tests
shruthilayaj ede58cd
remove unintended changes
shruthilayaj 657c4b2
just update the api caller to use the right format
shruthilayaj 31b3077
tests
shruthilayaj 2d21277
dont mutate query obj
shruthilayaj 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
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
74 changes: 74 additions & 0 deletions
74
static/app/views/dashboards/widgetBuilder/components/exploreArithmeticBuilder.tsx
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,74 @@ | ||
| import {useCallback, useMemo} from 'react'; | ||
|
|
||
| import {ArithmeticBuilder} from 'sentry/components/arithmeticBuilder'; | ||
| import type {Expression} from 'sentry/components/arithmeticBuilder/expression'; | ||
| import type {FunctionArgument} from 'sentry/components/arithmeticBuilder/types'; | ||
| import {stripEquationPrefix} from 'sentry/utils/discover/fields'; | ||
| import { | ||
| ALLOWED_EXPLORE_EQUATION_AGGREGATES, | ||
| FieldKind, | ||
| getFieldDefinition, | ||
| } from 'sentry/utils/fields'; | ||
| import {useTraceItemTags} from 'sentry/views/explore/contexts/spanTagsContext'; | ||
| import {useExploreSuggestedAttribute} from 'sentry/views/explore/hooks/useExploreSuggestedAttribute'; | ||
|
|
||
| type Props = { | ||
| equation: string; | ||
| onUpdate: (value: string) => void; | ||
| }; | ||
|
|
||
| export function ExploreArithmeticBuilder({equation, onUpdate}: Props) { | ||
| const expression = stripEquationPrefix(equation); | ||
| const {tags: numberTags} = useTraceItemTags('number'); | ||
| const {tags: stringTags} = useTraceItemTags('string'); | ||
|
|
||
| const functionArguments: FunctionArgument[] = useMemo(() => { | ||
| return [ | ||
| ...Object.entries(numberTags).map(([key, tag]) => { | ||
| return { | ||
| kind: FieldKind.MEASUREMENT, | ||
| name: key, | ||
| label: tag.name, | ||
| }; | ||
| }), | ||
| ...Object.entries(stringTags).map(([key, tag]) => { | ||
| return { | ||
| kind: FieldKind.TAG, | ||
| name: key, | ||
| label: tag.name, | ||
| }; | ||
| }), | ||
| ]; | ||
| }, [numberTags, stringTags]); | ||
|
|
||
| const getSpanFieldDefinition = useCallback( | ||
| (key: string) => { | ||
| const tag = numberTags[key] ?? stringTags[key]; | ||
| return getFieldDefinition(key, 'span', tag?.kind); | ||
| }, | ||
| [numberTags, stringTags] | ||
| ); | ||
|
|
||
| const handleExpressionChange = useCallback( | ||
| (newExpression: Expression) => { | ||
| onUpdate(stripEquationPrefix(newExpression.text)); | ||
| }, | ||
| [onUpdate] | ||
| ); | ||
|
|
||
| const getSuggestedAttribute = useExploreSuggestedAttribute({ | ||
| numberAttributes: numberTags, | ||
| stringAttributes: stringTags, | ||
| }); | ||
|
|
||
| return ( | ||
| <ArithmeticBuilder | ||
| aggregations={ALLOWED_EXPLORE_EQUATION_AGGREGATES} | ||
| functionArguments={functionArguments} | ||
| getFieldDefinition={getSpanFieldDefinition} | ||
| expression={expression} | ||
| setExpression={handleExpressionChange} | ||
| getSuggestedKey={getSuggestedAttribute} | ||
| /> | ||
| ); | ||
| } |
Oops, something went wrong.
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.
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.
should we be conditionally allowing it based on feature flag? i know we have the
visibility-explore-equationsflag which doesn't seem to be fully rolled out yet 🤔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 add equation button is flagged https://github.com/getsentry/sentry/pull/99404/files#diff-0559dfcce1f9b988a4626e5d7c6624642aa77322acee5f3e4e593614d5e96b57R869-R871, I think that should be good enough?
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.
oh whoopsies i missed that, yup should be good 👍