Skip to content

Commit cb287f7

Browse files
authored
fix: end trace when asset is not available (MetaMask#27131)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Before this PR, AssetOverviewContent started a manual Sentry trace for MarketInsightsEntryCardLoad, and the happy-path end happened only when the MarketInsightsEntryCard component actually mounted. If the asset had no Market Insights report, that card never rendered, so its endTrace() never ran. That left the span “open” in the trace map until the generic cleanup timeout removed it. This is shown in the 5 min traces in the screenshot. This PR adds the missing failure/empty-state endTrace() path, ensuring the trace is closed both when the card renders and when no asset/report is available, instead of being left dangling until timeout. We can see that even when the API returns a 404 and the report is not available, the trace is ended. <img width="2688" height="734" alt="SCR-20260310-khdy" src="https://github.com/user-attachments/assets/435b2224-105c-4c08-9c1e-b7ba5a71b02e" /> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/TSA-241 ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk instrumentation-only change that closes a previously orphaned Sentry span when Market Insights data is missing; main risk is inadvertently ending a span too early/for the wrong asset id. > > **Overview** > Fixes an orphaned Sentry trace in `AssetOverviewContent` for `TraceName.MarketInsightsEntryCardLoad` when Market Insights is enabled but no report exists (e.g., 404), by explicitly calling `endTrace` once loading completes. > > Also makes the `onMarketInsightsDisplayResolved` callback optional-safe (`?.`) and ensures the effect depends on `marketInsightsCaip19Id` so trace cleanup aligns with the current asset. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit eb747c2. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 2a5aeb3 commit cb287f7

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

app/components/UI/TokenDetails/components/AssetOverviewContent.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ import { IconName } from '../../../../component-library/components/Icons/Icon';
7373
import { useRWAToken } from '../../Bridge/hooks/useRWAToken';
7474
import { BridgeToken } from '../../Bridge/types';
7575
import { useAnalytics } from '../../../hooks/useAnalytics/useAnalytics';
76-
import { trace, TraceName, TraceOperation } from '../../../../util/trace';
76+
import {
77+
endTrace,
78+
trace,
79+
TraceName,
80+
TraceOperation,
81+
} from '../../../../util/trace';
7782

7883
const styleSheet = (params: { theme: Theme }) => {
7984
const { theme } = params;
@@ -312,22 +317,27 @@ const AssetOverviewContent: React.FC<AssetOverviewContentProps> = ({
312317
} = useMarketInsights(marketInsightsCaip19Id, isMarketInsightsEnabled);
313318

314319
useEffect(() => {
315-
if (!onMarketInsightsDisplayResolved) {
316-
return;
317-
}
318320
if (!isMarketInsightsEnabled) {
319-
onMarketInsightsDisplayResolved(false);
321+
onMarketInsightsDisplayResolved?.(false);
320322
return;
321323
}
322324
if (isMarketInsightsLoading) {
323325
return;
324326
}
325-
onMarketInsightsDisplayResolved(Boolean(marketInsightsReport));
327+
if (!marketInsightsReport && marketInsightsCaip19Id) {
328+
// No report available — cancel the orphaned trace that was started during render
329+
endTrace({
330+
name: TraceName.MarketInsightsEntryCardLoad,
331+
id: marketInsightsCaip19Id,
332+
});
333+
}
334+
onMarketInsightsDisplayResolved?.(Boolean(marketInsightsReport));
326335
}, [
327336
onMarketInsightsDisplayResolved,
328337
isMarketInsightsEnabled,
329338
isMarketInsightsLoading,
330339
marketInsightsReport,
340+
marketInsightsCaip19Id,
331341
]);
332342

333343
// Start the entry card trace synchronously during render so it is registered

0 commit comments

Comments
 (0)