Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions static/app/components/stackTrace/frame/frameContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
hasContextRegisters,
} from 'sentry/components/events/interfaces/frame/utils';
import {parseAssembly} from 'sentry/components/events/interfaces/utils';
import {LoadingIndicator} from 'sentry/components/loadingIndicator';
import {FrameVariablesGrid} from 'sentry/components/stackTrace/frame/frameVariablesGrid';
import {
useStackTraceContext,
Expand All @@ -31,10 +32,16 @@ const COVERAGE_TEXT: Record<Coverage, string | undefined> = {
};

interface FrameContentProps {
effectiveContext?: Array<[number, string | null]>;
isLoadingSourceContext?: boolean;
sourceLineCoverage?: Array<Coverage | undefined>;
}

export function FrameContent({sourceLineCoverage = []}: FrameContentProps) {
export function FrameContent({
sourceLineCoverage = [],
effectiveContext,
isLoadingSourceContext,
}: FrameContentProps) {
const {event, frame, frameContextId, frameIndex, isExpanded, platform} =
useStackTraceFrameContext();
const {frames, lastFrameIndex, meta, stacktrace} = useStackTraceContext();
Expand All @@ -46,7 +53,7 @@ export function FrameContent({sourceLineCoverage = []}: FrameContentProps) {
hasBeenExpandedRef.current = true;
}

const contextLines = isExpanded ? (frame.context ?? []) : [];
const contextLines = isExpanded ? (effectiveContext ?? frame.context ?? []) : [];
const fileExtension = isExpanded ? (getFileExtension(frame.filename ?? '') ?? '') : '';
const prismLines = usePrismTokensSourceContext({
contextLines,
Expand All @@ -62,7 +69,11 @@ export function FrameContent({sourceLineCoverage = []}: FrameContentProps) {
const hasFrameVariables = !!frameVariables && Object.keys(frameVariables).length > 0;
const hasFrameRegisters = !!expandedFrameRegisters;
const hasAnyFrameDetails =
hasSourceContext || hasFrameVariables || hasFrameRegisters || hasFrameAssembly;
hasSourceContext ||
isLoadingSourceContext ||
hasFrameVariables ||
hasFrameRegisters ||
hasFrameAssembly;
const shouldShowNoDetails =
frameIndex === lastFrameIndex && frameIndex === 0 && !hasAnyFrameDetails;

Expand All @@ -78,7 +89,12 @@ export function FrameContent({sourceLineCoverage = []}: FrameContentProps) {
overflowX="hidden"
data-test-id="core-stacktrace-frame-context"
>
{hasSourceContext ? (
{isLoadingSourceContext ? (
<Container padding="sm md">
<LoadingIndicator mini size={16} />
{t('Loading source context…')}
</Container>
) : hasSourceContext ? (
<FrameSourceGrid>
{contextLines.map(([lineNumber, lineValue], lineIndex) => (
<FrameSourceRow
Expand Down
2 changes: 2 additions & 0 deletions static/app/components/stackTrace/frame/frameRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const StackTraceFrameRowRoot = memo(function StackTraceFrameRowRoot({
const {
event,
frames,
hasScmSourceContext,
lastFrameIndex,
platform,
stacktrace,
Expand All @@ -43,6 +44,7 @@ const StackTraceFrameRowRoot = memo(function StackTraceFrameRowRoot({
frame: row.frame,
registers,
platform,
hasScmSourceContext,
});

const frameContextId = useId();
Expand Down
32 changes: 32 additions & 0 deletions static/app/components/stackTrace/issueStackTrace/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,38 @@ describe('IssueStackTrace', () => {
});
});

it('fetches and renders SCM source context for frames without embedded context', async () => {
const {event, stacktrace} = makeCopyTestData();
const organization = OrganizationFixture({features: ['scm-source-context']});
ProjectsStore.loadInitialData([ProjectFixture({id: '1', slug: 'project-slug'})]);

const sourceContextRequest = MockApiClient.addMockResponse({
url: '/projects/org-slug/project-slug/stacktrace-source-context/',
body: {context: [[42, 'def handle():']], sourceUrl: null, error: null},
});

render(
<IssueStackTrace
event={event}
values={[
{
type: 'RuntimeError',
value: 'broke',
module: null,
mechanism: {handled: false, type: 'generic'},
stacktrace,
rawStacktrace: null,
threadId: null,
},
]}
/>,
{organization}
);

expect(sourceContextRequest).toHaveBeenCalled();
expect(await screen.findByText('def handle():')).toBeInTheDocument();
});

describe('exception groups', () => {
function makeExceptionGroupValues(): {
event: ReturnType<typeof EventFixture>;
Expand Down
5 changes: 5 additions & 0 deletions static/app/components/stackTrace/issueStackTrace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {Group} from 'sentry/types/group';
import type {Project} from 'sentry/types/project';
import type {StacktraceType} from 'sentry/types/stacktrace';
import {defined} from 'sentry/utils';
import {useOrganization} from 'sentry/utils/useOrganization';
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';

Expand Down Expand Up @@ -148,6 +149,8 @@ function IssueStackTraceContent({
isStandalone,
}: IssueStackTraceBaseProps & {isStandalone: boolean; values: ExceptionValue[]}) {
const {isMinified, isNewestFirst, view} = useStackTraceViewState();
const organization = useOrganization();
const hasScmSourceContext = organization.features.includes('scm-source-context');
const {hiddenExceptions, toggleRelatedExceptions, expandException} =
useHiddenExceptions(values);

Expand Down Expand Up @@ -258,6 +261,7 @@ function IssueStackTraceContent({
<StackTraceProvider
exceptionIndex={isStandalone ? undefined : exc.exceptionIndex}
event={event}
hasScmSourceContext={hasScmSourceContext}
stacktrace={exc.stacktrace}
minifiedStacktrace={exc.rawStacktrace ?? undefined}
meta={isStandalone ? rawEntryMeta : excMeta?.stacktrace}
Expand Down Expand Up @@ -344,6 +348,7 @@ function IssueStackTraceContent({
<StackTraceProvider
exceptionIndex={exc.exceptionIndex}
event={event}
hasScmSourceContext={hasScmSourceContext}
stacktrace={exc.stacktrace}
minifiedStacktrace={exc.rawStacktrace ?? undefined}
meta={exceptionValuesMeta?.[exc.exceptionIndex]?.stacktrace}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import {useEffect} from 'react';
import {useEffect, useMemo} from 'react';

import {useLineCoverageContext} from 'sentry/components/events/interfaces/crashContent/exception/lineCoverageContext';
import {useSourceContext} from 'sentry/components/events/interfaces/frame/useSourceContext';
import {useStacktraceCoverage} from 'sentry/components/events/interfaces/frame/useStacktraceCoverage';
import {
hasContextSource,
hasPotentialSourceContext,
} from 'sentry/components/events/interfaces/frame/utils';
import {FrameContent} from 'sentry/components/stackTrace/frame/frameContent';
import {
useStackTraceContext,
Expand All @@ -25,25 +30,47 @@ function getLineCoverage(

export function IssueStackTraceFrameContext() {
const {event, frame, isExpanded} = useStackTraceFrameContext();
const {project} = useStackTraceContext();
const {hasScmSourceContext, project} = useStackTraceContext();
const {hasCoverageData, setHasCoverageData} = useLineCoverageContext();
const organization = useOrganization({allowNull: true});
const organization = useOrganization();

const hasEmbeddedContext = hasContextSource(frame);
const shouldFetchSourceContext =
hasScmSourceContext &&
defined(project) &&
!hasEmbeddedContext &&
isExpanded &&
hasPotentialSourceContext(frame);

const {data: sourceContextData, isPending: isLoadingSourceContext} = useSourceContext(
{
event,
frame,
orgSlug: organization.slug,
projectSlug: project?.slug,
},
{enabled: shouldFetchSourceContext}
);

const contextLines = isExpanded ? (frame.context ?? []) : [];
const scmContext = useMemo(() => {
if (!sourceContextData?.context?.length) {
return undefined;
}
return sourceContextData.context;
}, [sourceContextData]);

const effectiveContext = hasEmbeddedContext ? frame.context : scmContext;
const contextLines = isExpanded ? (effectiveContext ?? []) : [];

const {data: coverageData, isPending: isLoadingCoverage} = useStacktraceCoverage(
{
event,
frame,
orgSlug: organization?.slug || '',
orgSlug: organization.slug,
projectSlug: project?.slug,
},
{
enabled:
isExpanded &&
defined(organization) &&
defined(project) &&
!!organization.codecovAccess,
enabled: isExpanded && defined(project) && !!organization.codecovAccess,
}
);

Expand All @@ -66,5 +93,11 @@ export function IssueStackTraceFrameContext() {
}
}, [coverageData, hasCoverageData, isLoadingCoverage, setHasCoverageData]);

return <FrameContent sourceLineCoverage={sourceLineCoverage} />;
return (
<FrameContent
sourceLineCoverage={sourceLineCoverage}
effectiveContext={effectiveContext}
isLoadingSourceContext={shouldFetchSourceContext && isLoadingSourceContext}
/>
);
}
2 changes: 2 additions & 0 deletions static/app/components/stackTrace/stackTraceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export interface StackTraceContextValue {
frames: Frame[];
/** True when any visible frame row has expandable details. */
hasAnyExpandableFrames: boolean;
/** True when the SCM source context feature is enabled for this org. */
hasScmSourceContext: boolean;
/** Hidden-system-frame expansion state keyed by frame index. */
hiddenFrameToggleMap: Record<number, boolean>;
/** True when the "Unminify Code" source map action must be hidden. */
Expand Down
6 changes: 5 additions & 1 deletion static/app/components/stackTrace/stackTraceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function StackTraceProvider({
exceptionIndex,
event,
frameSourceMapDebuggerData,
hasScmSourceContext,
hideSourceMapDebugger,
minifiedStacktrace,
stacktrace,
Expand Down Expand Up @@ -106,9 +107,10 @@ export function StackTraceProvider({
frame: row.frame,
registers,
platform,
hasScmSourceContext,
});
}),
[rows, frames.length, activeStacktrace.registers, platform]
[rows, frames.length, activeStacktrace.registers, platform, hasScmSourceContext]
);

const toggleHiddenFrames = useCallback((frameIndex: number) => {
Expand All @@ -124,6 +126,7 @@ export function StackTraceProvider({
exceptionIndex,
event,
hasAnyExpandableFrames,
hasScmSourceContext: hasScmSourceContext ?? false,
platform,
project,
stacktrace: activeStacktrace,
Expand All @@ -143,6 +146,7 @@ export function StackTraceProvider({
frameSourceMapDebuggerData,
frames,
hasAnyExpandableFrames,
hasScmSourceContext,
hideSourceMapDebugger,
hiddenFrameToggleMap,
lastFrameIndex,
Expand Down
2 changes: 2 additions & 0 deletions static/app/components/stackTrace/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface StackTraceProviderProps {
exceptionIndex?: number;
/** Per-frame source map debugger data, powering the "Unminify Code" action. */
frameSourceMapDebuggerData?: FrameSourceMapDebuggerData[];
/** Whether the SCM source context feature is enabled for this org. */
hasScmSourceContext?: boolean;
/** Hide the source maps debugger button entirely. */
hideSourceMapDebugger?: boolean;
/** Cap the number of frames rendered. Frames beyond this depth are omitted. */
Expand Down
Loading