|
1 | 1 | import {useCallback, useMemo} from 'react';
|
2 | 2 | import styled from '@emotion/styled';
|
| 3 | +import * as Sentry from '@sentry/react'; |
3 | 4 |
|
4 | 5 | import type {SelectOption} from 'sentry/components/compactSelect';
|
5 | 6 | import {CompactSelect} from 'sentry/components/compactSelect';
|
@@ -29,10 +30,32 @@ function FlamegraphThreadSelector({
|
29 | 30 | ] = useMemo(() => {
|
30 | 31 | const profiles: Array<SelectOption<number>> = [];
|
31 | 32 | const emptyProfiles: Array<SelectOption<number>> = [];
|
| 33 | + |
32 | 34 | const activeThreadId =
|
33 | 35 | typeof profileGroup.activeProfileIndex === 'number'
|
34 | 36 | ? profileGroup.profiles[profileGroup.activeProfileIndex]?.threadId
|
35 | 37 | : undefined;
|
| 38 | + |
| 39 | + // Sanity check and redirect to the correct thread id if the tid that was set |
| 40 | + // is not present in the profile group and/or points to a non existing thread. |
| 41 | + if (profileGroup.profiles.length > 0 && typeof threadId === 'number') { |
| 42 | + const profileWithThreadId = profileGroup.profiles.find( |
| 43 | + profile => profile.threadId === threadId |
| 44 | + ); |
| 45 | + |
| 46 | + if (!profileWithThreadId) { |
| 47 | + const fallbackThreadId = |
| 48 | + profileGroup.profiles[profileGroup.activeProfileIndex]?.threadId ?? 0; |
| 49 | + |
| 50 | + if (fallbackThreadId !== threadId) { |
| 51 | + onThreadIdChange(fallbackThreadId); |
| 52 | + Sentry.captureMessage( |
| 53 | + `Thread id ${threadId} not found in profile group, redirecting to ${fallbackThreadId}` |
| 54 | + ); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
36 | 59 | const sortedProfiles = [...profileGroup.profiles].sort(
|
37 | 60 | compareProfiles(activeThreadId)
|
38 | 61 | );
|
@@ -60,7 +83,7 @@ function FlamegraphThreadSelector({
|
60 | 83 | });
|
61 | 84 |
|
62 | 85 | return [profiles, emptyProfiles];
|
63 |
| - }, [profileGroup]); |
| 86 | + }, [profileGroup, threadId, onThreadIdChange]); |
64 | 87 |
|
65 | 88 | const handleChange: (opt: SelectOption<any>) => void = useCallback(
|
66 | 89 | opt => {
|
|
0 commit comments