sentry
sentry copied to clipboard
Add AI Summary tab for replay details with feature flag support
A new "AI Summary" tab was added to the Replay Details page.
- The
TabKeyenum instatic/app/utils/replays/hooks/useActiveReplayTab.tsxwas updated to includeAI_SUMMARY, and it was added tosupportedVideoTabsfor mobile compatibility. - In
static/app/views/replays/detail/layout/focusTabs.tsx, thegetReplayTabsfunction was modified to conditionally render the "AI Summary" tab based on theorganizations:replay-ai-summariesfeature flag, positioning it before theBreadcrumbstab. - A new
AISummarycomponent was created instatic/app/views/replays/detail/aiSummary/index.tsx. This component:- Makes a POST request to
/organizations/{organization_slug}/replays/summary/on initial load. - Displays a
LoadingIndicatorwhile the request is in flight. - Shows an error message if the request fails.
- Renders the
summarycontent upon successful completion.
- Makes a POST request to
- The
static/app/views/replays/detail/layout/focusArea.tsxfile was updated to import and render the newAISummarycomponent when theAI_SUMMARYtab is active.
Closes REPLAY-388
AI Summary Tab Implementation for Replay Details
Overview
Added a new "AI Summary" tab to the Replay Details page that is visible only when the organizations:replay-ai-summaries feature flag is enabled. The tab is positioned before the Breadcrumbs tab and makes a POST request to /organizations/{organization_slug}/replays/summary/ to fetch AI-generated summaries.
Changes Made
1. Updated TabKey Enum
File: static/app/utils/replays/hooks/useActiveReplayTab.tsx
- Added
AI_SUMMARY = 'ai-summary'to the TabKey enum - Added
TabKey.AI_SUMMARYto thesupportedVideoTabsarray to ensure it works for mobile replays
2. Updated FocusTabs Component
File: static/app/views/replays/detail/layout/focusTabs.tsx
- Added feature flag check for
replay-ai-summariesin thegetReplayTabsfunction - The AI Summary tab appears before Breadcrumbs when the feature flag is enabled
- Added proper TypeScript typing for the Organization parameter
3. Updated FocusArea Component
File: static/app/views/replays/detail/layout/focusArea.tsx
- Added case for
TabKey.AI_SUMMARYto render the newAISummarycomponent - Imported the new
AISummarycomponent
4. Created AISummary Component
File: static/app/views/replays/detail/aiSummary/index.tsx
-
Loading State: Shows
<LoadingIndicator>while the API request is in flight - Error State: Shows error alert if the request fails
- Success State: Displays the summary text from the API response
-
API Integration: Uses Sentry's
useApiQuery()hook with proper query key configuration for POST requests - Caching: Implements 5-minute stale time for efficient caching
- Conditional Fetching: Only makes requests when replay record is available
-
Feature Flag: Only accessible when
organizations:replay-ai-summariesis enabled - Styling: Consistent with other replay detail tabs using styled components
API Integration Details
Query Key Structure
function createAISummaryQueryKey(orgSlug: string, replayId: string): ApiQueryKey {
return [
`/organizations/${orgSlug}/replays/summary/`,
{
method: 'POST',
data: {
replayId,
},
},
];
}
useApiQuery Configuration
const {data, isLoading, isError} = useApiQuery<SummaryResponse>(
createAISummaryQueryKey(organization.slug, replayRecord?.id ?? ''),
{
staleTime: 5 * 60 * 1000, // 5 minutes
enabled: Boolean(replayRecord?.id),
}
);
Endpoint
POST /organizations/{organization_slug}/replays/summary/
Request Body
{
"replayId": "replay-id-here"
}
Expected Response
{
"summary": "AI-generated summary text here"
}
Benefits of useApiQuery Implementation
- Automatic Caching: Built-in caching with 5-minute stale time prevents unnecessary requests
- Request Deduplication: Multiple components requesting the same data will share a single request
- Background Refetching: Automatic background updates when data becomes stale
- Conditional Fetching: Only makes requests when replay record is available
- Error Handling: Built-in error states and retry logic
- Loading States: Automatic loading state management
- TypeScript Safety: Full type safety with TypeScript generics
User Experience
- Feature Flag Disabled: AI Summary tab is completely hidden
- Feature Flag Enabled: AI Summary tab appears as the first tab before Breadcrumbs
- First Load: Shows loading indicator while fetching summary
- Success: Displays the summary text with proper formatting
- Error: Shows user-friendly error message
- No Data: Shows informational message when no summary is available
- Subsequent Visits: Cached data loads instantly within 5-minute window
Testing
The implementation includes:
- Data test ID:
replay-details-ai-summary-tabfor automated testing - Proper error handling for API failures
- Loading states for better UX
- Feature flag integration for gradual rollout
- Conditional fetching to prevent unnecessary requests
Dependencies
- Feature flag:
organizations:replay-ai-summaries(already defined insrc/sentry/features/temporary.py) - API endpoint:
/organizations/{organization_slug}/replays/summary/(needs backend implementation) - Components: Uses existing Sentry UI components (
LoadingIndicator,Alert, etc.) - Query Client: Uses Sentry's
useApiQueryhook for data fetching and caching