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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
import {useDevicePixelRatio} from 'sentry/utils/useDevicePixelRatio';
import {useMemoWithPrevious} from 'sentry/utils/useMemoWithPrevious';
import {useContinuousProfile} from 'sentry/views/profiling/continuousProfileProvider';
import {useProfileGroup} from 'sentry/views/profiling/profileGroupProvider';
import {useContinuousProfileGroup} from 'sentry/views/profiling/profileGroupProvider';

import {FlamegraphDrawer} from './flamegraphDrawer/flamegraphDrawer';
import {FlamegraphWarnings} from './flamegraphOverlays/FlamegraphWarnings';
Expand Down Expand Up @@ -126,7 +126,7 @@ export function ContinuousFlamegraph(): ReactElement {
const dispatch = useDispatchFlamegraphState();

const profiles = useContinuousProfile();
const profileGroup = useProfileGroup() as ContinuousProfileGroup;
const profileGroup = useContinuousProfileGroup();

const flamegraphTheme = useFlamegraphTheme();
const position = useFlamegraphZoomPosition();
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/profiling/flamegraph/flamegraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function Flamegraph(): ReactElement {

const profiles = useProfiles();
const setProfiles = useSetProfiles();
const profileGroup = useProfileGroup() as ProfileGroup;
const profileGroup = useProfileGroup();

const flamegraphTheme = useFlamegraphTheme();
const position = useFlamegraphZoomPosition();
Expand Down
6 changes: 6 additions & 0 deletions static/app/utils/profiling/profile/importProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ProfileGroup {
profiles: Profile[];
traceID: string;
transactionID: string | null;
type: 'transaction';
images?: Image[];
}

Expand All @@ -53,6 +54,7 @@ export interface ContinuousProfileGroup {
profiles: Profile[];
traceID: string;
transactionID: string | null;
type: 'continuous';
images?: Image[];
}

Expand Down Expand Up @@ -111,6 +113,7 @@ function importJSSelfProfile(
const profile = importSingleProfile(input, frameIndex, options);

return {
type: 'transaction',
traceID,
name: traceID,
transactionID: null,
Expand Down Expand Up @@ -184,6 +187,7 @@ function importSentrySampledProfile(
}

return {
type: 'transaction',
transactionID: input.transaction.id,
traceID: input.transaction.trace_id,
name: input.transaction.name,
Expand Down Expand Up @@ -227,6 +231,7 @@ export function importSchema(
);

return {
type: 'transaction',
traceID,
transactionID: input.metadata.transactionID ?? null,
name: input.metadata?.transactionName ?? traceID,
Expand Down Expand Up @@ -255,6 +260,7 @@ export function importSentryContinuousProfileChunk(
return {
traceID,
name: '',
type: 'continuous',
transactionID: null,
activeProfileIndex: 0,
profiles: [importSingleProfile(input.profile, frameIndex, options)],
Expand Down
34 changes: 31 additions & 3 deletions static/app/views/profiling/profileGroupProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@ import type {
import {importProfile} from 'sentry/utils/profiling/profile/importProfile';

type ProfileGroupContextValue = ContinuousProfileGroup | ProfileGroup;

const ProfileGroupContext = createContext<ProfileGroupContextValue | null>(null);

export function useProfileGroup() {
function assertContinuousProfileGroup(
input: ProfileGroupContextValue | null
): asserts input is ContinuousProfileGroup {
if (input && input.type !== 'continuous') {
throw new Error('ProfileGroup is not of continuous profile type.');
}
}

function assertTransactionProfileGroup(
input: ProfileGroupContextValue | null
): asserts input is ProfileGroup {
if (input && input.type !== 'transaction') {
throw new Error('ProfileGroup is not of transaction profile type.');
}
}

export function useProfileGroup(): ProfileGroup {
const context = useContext(ProfileGroupContext);
if (!context) {
throw new Error('useProfileGroup was called outside of ProfileGroupProvider');
}
assertTransactionProfileGroup(context);
return context;
}

export function useContinuousProfileGroup(): ContinuousProfileGroup {
const context = useContext(ProfileGroupContext);
if (!context) {
throw new Error(
'useContinuousProfileGroup was called outside of ProfileGroupProvider'
);
}
assertContinuousProfileGroup(context);
return context;
}

Expand All @@ -28,6 +55,7 @@ export const LOADING_PROFILE_GROUP: Readonly<ProfileGroup> = {
measurements: {},
traceID: '',
profiles: [],
type: 'transaction',
};

interface ProfileGroupProviderProps {
Expand All @@ -52,7 +80,7 @@ export function ProfileGroupProvider(props: ProfileGroupProviderProps) {
}, [props.input, props.traceID, props.type, props.frameFilter]);

return (
<ProfileGroupContext.Provider value={profileGroup as ContinuousProfileGroup}>
<ProfileGroupContext.Provider value={profileGroup}>
{props.children}
</ProfileGroupContext.Provider>
);
Expand Down