-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(tracemetrics): Improve samples panel rendering #101448
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,11 @@ import {useMemo} from 'react'; | |
|
|
||
| import {MutableSearch} from 'sentry/components/searchSyntax/mutableSearch'; | ||
| import type {NewQuery} from 'sentry/types/organization'; | ||
| import {useDiscoverQuery, type TableDataRow} from 'sentry/utils/discover/discoverQuery'; | ||
| import EventView from 'sentry/utils/discover/eventView'; | ||
| import {DiscoverDatasets} from 'sentry/utils/discover/types'; | ||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
| import useOrganization from 'sentry/utils/useOrganization'; | ||
| import usePageFilters from 'sentry/utils/usePageFilters'; | ||
| import {useSpansQuery} from 'sentry/views/insights/common/queries/useSpansQuery'; | ||
|
|
||
|
|
@@ -13,6 +16,7 @@ interface UseTraceTelemetryOptions { | |
| } | ||
|
|
||
| interface TraceTelemetryData { | ||
| errorsCount: number; | ||
| logsCount: number; | ||
| spansCount: number; | ||
| trace: string; | ||
|
|
@@ -27,7 +31,35 @@ export function useTraceTelemetry({ | |
| enabled, | ||
| traceIds, | ||
| }: UseTraceTelemetryOptions): TraceTelemetryResult { | ||
| const organization = useOrganization(); | ||
| const {selection} = usePageFilters(); | ||
| const location = useLocation(); | ||
|
|
||
| // Query for error count | ||
| const errorsEventView = useMemo(() => { | ||
| const traceFilter = new MutableSearch('').addFilterValueList('trace', traceIds); | ||
| const discoverQuery: NewQuery = { | ||
| id: undefined, | ||
| name: 'Error Count', | ||
| fields: ['trace', 'count()'], | ||
| orderby: '-count', | ||
| query: traceFilter.formatString(), | ||
| version: 2, | ||
| dataset: DiscoverDatasets.ERRORS, | ||
| }; | ||
| return EventView.fromNewQueryWithPageFilters(discoverQuery, selection); | ||
| }, [traceIds, selection]); | ||
|
|
||
| const errorsResult = useDiscoverQuery({ | ||
| eventView: errorsEventView, | ||
| limit: traceIds.length, | ||
| referrer: 'api.explore.trace-errors-count', | ||
| orgSlug: organization.slug, | ||
| location, | ||
| options: { | ||
| enabled: enabled && errorsEventView !== null, | ||
| }, | ||
| }); | ||
|
|
||
| // Query for spans count | ||
| const spansEventView = useMemo(() => { | ||
|
|
@@ -90,6 +122,7 @@ export function useTraceTelemetry({ | |
| trace: traceId, | ||
| spansCount: 0, | ||
| logsCount: 0, | ||
| errorsCount: 0, | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -115,11 +148,22 @@ export function useTraceTelemetry({ | |
| }); | ||
| } | ||
|
|
||
| // Populate errors count | ||
| if (errorsResult.data) { | ||
| errorsResult.data.data.forEach((row: TableDataRow) => { | ||
| const traceId = row.trace as string; | ||
| const count = row['count()'] as number; | ||
| if (dataMap.has(traceId)) { | ||
narsaynorath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dataMap.get(traceId)!.errorsCount = count; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| return dataMap; | ||
| }, [traceIds, spansResult.data, logsResult.data]); | ||
| }, [traceIds, spansResult.data, logsResult.data, errorsResult.data]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Incorrect Dependency in useMemo HookThe Additional Locations (1) |
||
|
|
||
| return { | ||
| data: telemetryData, | ||
| isLoading: spansResult.isPending || logsResult.isPending, | ||
| isLoading: spansResult.isPending || logsResult.isPending || errorsResult.isPending, | ||
| }; | ||
| } | ||
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.
Potential bug: The
useDiscoverQueryhook is called with an undefinedlocationvariable, which will cause a runtimeReferenceError.Description: The
useDiscoverQueryhook is called on line 56 with alocationvariable. However, this variable is not defined within the scope of theuseTraceTelemetryhook. It is not passed as a parameter, imported, or declared locally. SinceuseDiscoverQueryrequireslocationas a mandatory prop, this will result in aReferenceError: location is not definedwhen the component renders and the query is executed, causing a runtime crash.Suggested fix: The
useTraceTelemetryhook needs to acceptlocationas a parameter. Update its options interface, add it to the function signature, and pass it down touseDiscoverQuery. The calling component,samplesTab.tsx, should then pass itslocationobject to the hook.severity: 0.85, confidence: 1.0
Did we get this right? 👍 / 👎 to inform future reviews.
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.
Weird, this wasn't caught by my linter earlier.