-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(trace-tree-node): Mitigating SpanNode type guard usage #104481
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
base: abdk/trace-tree-node-missing-ins-guards
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -1,124 +1,40 @@ | ||
| import {useMemo} from 'react'; | ||
|
|
||
| import {ExternalLink} from 'sentry/components/core/link'; | ||
| import LoadingError from 'sentry/components/loadingError'; | ||
| import LoadingIndicator from 'sentry/components/loadingIndicator'; | ||
| import {t, tct} from 'sentry/locale'; | ||
| import type {EventTransaction} from 'sentry/types/event'; | ||
| import type {Project} from 'sentry/types/project'; | ||
| import useProjects from 'sentry/utils/useProjects'; | ||
| import {useTransaction} from 'sentry/views/performance/newTraceDetails/traceApi/useTransaction'; | ||
| import {getCustomInstrumentationLink} from 'sentry/views/performance/newTraceDetails/traceConfigurations'; | ||
| import {ProfilePreview} from 'sentry/views/performance/newTraceDetails/traceDrawer/details/profiling/profilePreview'; | ||
| import type {TraceTreeNodeDetailsProps} from 'sentry/views/performance/newTraceDetails/traceDrawer/tabs/traceTreeNodeDetails'; | ||
| import { | ||
| isEAPSpanNode, | ||
| isSpanNode, | ||
| } from 'sentry/views/performance/newTraceDetails/traceGuards'; | ||
| import type {EapSpanNode} from 'sentry/views/performance/newTraceDetails/traceModels/traceTreeNode/eapSpanNode'; | ||
| import type {NoInstrumentationNode} from 'sentry/views/performance/newTraceDetails/traceModels/traceTreeNode/noInstrumentationNode'; | ||
| import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider'; | ||
| import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider'; | ||
|
|
||
| import {TraceDrawerComponents} from './styles'; | ||
| import {getProfileMeta} from './utils'; | ||
|
|
||
| interface BaseProps extends TraceTreeNodeDetailsProps<NoInstrumentationNode> { | ||
| event: EventTransaction | null; | ||
| profileId: string | undefined; | ||
| profileMeta: ReturnType<typeof getProfileMeta>; | ||
| profilerId: string | undefined; | ||
| project: Project | undefined; | ||
| } | ||
|
|
||
| export function MissingInstrumentationNodeDetails({ | ||
| ...props | ||
| }: TraceTreeNodeDetailsProps<NoInstrumentationNode>) { | ||
| const {node} = props; | ||
| const {projects} = useProjects(); | ||
| const previous = node.previous; | ||
|
|
||
| if (isEAPSpanNode(node.previous)) { | ||
| return <EAPMissingInstrumentationNodeDetails {...props} projects={projects} />; | ||
| } | ||
|
|
||
| if (isSpanNode(node.previous)) { | ||
| const event = node.previous.event; | ||
| const project = projects.find(proj => proj.slug === event?.projectSlug); | ||
| const profileMeta = getProfileMeta(event) || ''; | ||
| const profileContext = event?.contexts?.profile ?? {}; | ||
|
|
||
| return ( | ||
| <BaseMissingInstrumentationNodeDetails | ||
| {...props} | ||
| profileMeta={profileMeta} | ||
| project={project} | ||
| event={event} | ||
| profileId={profileContext.profile_id} | ||
| profilerId={profileContext.profiler_id} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| function EAPMissingInstrumentationNodeDetails({ | ||
| projects, | ||
| ...props | ||
| }: TraceTreeNodeDetailsProps<NoInstrumentationNode> & { | ||
| projects: Project[]; | ||
| }) { | ||
| const {node} = props; | ||
| const previous = node.previous as EapSpanNode; | ||
|
|
||
| const { | ||
| data: eventTransaction = null, | ||
| isLoading: isEventTransactionLoading, | ||
| isError: isEventTransactionError, | ||
| } = useTransaction({ | ||
| event_id: previous.value.transaction_id, | ||
| const {data: eventTransaction = null} = useTransaction({ | ||
| event_id: previous.transactionId ?? '', | ||
| organization: props.organization, | ||
| project_slug: previous.value.project_slug, | ||
| project_slug: previous.projectSlug ?? '', | ||
|
Comment on lines
23
to
+27
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: Refactoring removed type guards, causing 🔍 Detailed AnalysisThe refactoring removed type guards, causing 💡 Suggested FixReintroduce type-specific logic to correctly extract 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews.
Contributor
Author
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. Invalid
Contributor
Author
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. We assign the parent's projectSlug for spanNodes. |
||
| }); | ||
|
|
||
| const profileMeta = useMemo( | ||
| () => getProfileMeta(eventTransaction) || '', | ||
| [eventTransaction] | ||
| ); | ||
|
|
||
| if (isEventTransactionLoading) { | ||
| return <LoadingIndicator />; | ||
| } | ||
|
|
||
| if (isEventTransactionError) { | ||
| return <LoadingError message={t('Failed to fetch span details')} />; | ||
| } | ||
|
|
||
| const project = projects.find(proj => proj.slug === eventTransaction?.projectSlug); | ||
| const profileContext = eventTransaction?.contexts?.profile ?? {}; | ||
|
|
||
| return ( | ||
| <BaseMissingInstrumentationNodeDetails | ||
| {...props} | ||
| profileMeta={profileMeta} | ||
| project={project} | ||
| event={eventTransaction} | ||
| profileId={profileContext.profile_id} | ||
| profilerId={profileContext.profiler_id} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function BaseMissingInstrumentationNodeDetails({ | ||
| node, | ||
| organization, | ||
| onTabScrollToNode, | ||
| profileMeta, | ||
| project, | ||
| event, | ||
| profileId, | ||
| profilerId, | ||
| }: BaseProps) { | ||
| return ( | ||
| <TraceDrawerComponents.DetailContainer> | ||
| <TraceDrawerComponents.HeaderContainer> | ||
|
|
@@ -135,8 +51,8 @@ function BaseMissingInstrumentationNodeDetails({ | |
| </TraceDrawerComponents.Title> | ||
| <TraceDrawerComponents.NodeActions | ||
| node={node} | ||
| organization={organization} | ||
| onTabScrollToNode={onTabScrollToNode} | ||
| organization={props.organization} | ||
| onTabScrollToNode={props.onTabScrollToNode} | ||
| /> | ||
| </TraceDrawerComponents.HeaderContainer> | ||
| <TraceDrawerComponents.BodyContainer> | ||
|
|
@@ -150,29 +66,31 @@ function BaseMissingInstrumentationNodeDetails({ | |
| } | ||
| )} | ||
| </p> | ||
| <ProfilesProvider | ||
| orgSlug={organization.slug} | ||
| projectSlug={event?.projectSlug ?? ''} | ||
| profileMeta={profileMeta || ''} | ||
| > | ||
| <ProfileContext.Consumer> | ||
| {profiles => ( | ||
| <ProfileGroupProvider | ||
| type="flamechart" | ||
| input={profiles?.type === 'resolved' ? profiles.data : null} | ||
| traceID={profileId ?? ''} | ||
| > | ||
| <ProfilePreview | ||
| project={project} | ||
| profileID={profileId} | ||
| profilerID={profilerId} | ||
| event={event} | ||
| missingInstrumentationNode={node} | ||
| /> | ||
| </ProfileGroupProvider> | ||
| )} | ||
| </ProfileContext.Consumer> | ||
| </ProfilesProvider> | ||
| {eventTransaction ? ( | ||
| <ProfilesProvider | ||
| orgSlug={props.organization.slug} | ||
| projectSlug={eventTransaction?.projectSlug ?? ''} | ||
| profileMeta={profileMeta || ''} | ||
| > | ||
| <ProfileContext.Consumer> | ||
| {profiles => ( | ||
| <ProfileGroupProvider | ||
| type="flamechart" | ||
| input={profiles?.type === 'resolved' ? profiles.data : null} | ||
| traceID={profileContext.profile_id ?? ''} | ||
| > | ||
| <ProfilePreview | ||
| project={project} | ||
| profileID={profileContext.profile_id ?? ''} | ||
| profilerID={profileContext.profiler_id ?? ''} | ||
| event={eventTransaction} | ||
| missingInstrumentationNode={node} | ||
| /> | ||
| </ProfileGroupProvider> | ||
| )} | ||
| </ProfileContext.Consumer> | ||
| </ProfilesProvider> | ||
| ) : null} | ||
| <p> | ||
| {t("If you'd prefer, you can also turn the feature off in the settings above.")} | ||
| </p> | ||
|
|
||
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.
Combined the two MissingInstrumentationNodeDetails to one.