-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add AI Summary tab for replay details with feature flag support #93224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
billyvg
wants to merge
6
commits into
master
Choose a base branch
from
cursor/add-summary-tab-to-replay-details-4ae6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+247
−1
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
150f372
Add AI Summary tab for replay details with feature flag support
cursoragent 2008e3d
Refactor AI Summary to use useApiQuery with caching and conditional f…
cursoragent d7afae0
:hammer_and_wrench: apply pre-commit fixes
getsantry[bot] d8476dd
rename AI Summary -> AI
billyvg 76e39e9
fix name
billyvg a624275
need project slug for endpoint
billyvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# 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_SUMMARY` to the `supportedVideoTabs` array 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-summaries` in the `getReplayTabs` function | ||
- 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_SUMMARY` to render the new `AISummary` component | ||
- Imported the new `AISummary` component | ||
|
||
### 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-summaries` is enabled | ||
- **Styling:** Consistent with other replay detail tabs using styled components | ||
|
||
## API Integration Details | ||
|
||
### Query Key Structure | ||
|
||
```typescript | ||
function createAISummaryQueryKey(orgSlug: string, replayId: string): ApiQueryKey { | ||
return [ | ||
`/organizations/${orgSlug}/replays/summary/`, | ||
{ | ||
method: 'POST', | ||
data: { | ||
replayId, | ||
}, | ||
}, | ||
]; | ||
} | ||
``` | ||
|
||
### useApiQuery Configuration | ||
|
||
```typescript | ||
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 | ||
|
||
```json | ||
{ | ||
"replayId": "replay-id-here" | ||
} | ||
``` | ||
|
||
### Expected Response | ||
|
||
```json | ||
{ | ||
"summary": "AI-generated summary text here" | ||
} | ||
``` | ||
|
||
## Benefits of useApiQuery Implementation | ||
|
||
1. **Automatic Caching:** Built-in caching with 5-minute stale time prevents unnecessary requests | ||
2. **Request Deduplication:** Multiple components requesting the same data will share a single request | ||
3. **Background Refetching:** Automatic background updates when data becomes stale | ||
4. **Conditional Fetching:** Only makes requests when replay record is available | ||
5. **Error Handling:** Built-in error states and retry logic | ||
6. **Loading States:** Automatic loading state management | ||
7. **TypeScript Safety:** Full type safety with TypeScript generics | ||
|
||
## User Experience | ||
|
||
1. **Feature Flag Disabled:** AI Summary tab is completely hidden | ||
2. **Feature Flag Enabled:** AI Summary tab appears as the first tab before Breadcrumbs | ||
3. **First Load:** Shows loading indicator while fetching summary | ||
4. **Success:** Displays the summary text with proper formatting | ||
5. **Error:** Shows user-friendly error message | ||
6. **No Data:** Shows informational message when no summary is available | ||
7. **Subsequent Visits:** Cached data loads instantly within 5-minute window | ||
|
||
## Testing | ||
|
||
The implementation includes: | ||
|
||
- Data test ID: `replay-details-ai-summary-tab` for 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 in `src/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 `useApiQuery` hook for data fetching and caching |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||
import styled from '@emotion/styled'; | ||||||
|
||||||
import {Alert} from 'sentry/components/core/alert'; | ||||||
import LoadingIndicator from 'sentry/components/loadingIndicator'; | ||||||
import {t} from 'sentry/locale'; | ||||||
import {space} from 'sentry/styles/space'; | ||||||
import type {ApiQueryKey} from 'sentry/utils/queryClient'; | ||||||
import {useApiQuery} from 'sentry/utils/queryClient'; | ||||||
import {decodeScalar} from 'sentry/utils/queryString'; | ||||||
import useLocationQuery from 'sentry/utils/url/useLocationQuery'; | ||||||
import useOrganization from 'sentry/utils/useOrganization'; | ||||||
import useProjectFromId from 'sentry/utils/useProjectFromId'; | ||||||
import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight'; | ||||||
import TabItemContainer from 'sentry/views/replays/detail/tabItemContainer'; | ||||||
import type {ReplayRecord} from 'sentry/views/replays/types'; | ||||||
|
||||||
interface Props { | ||||||
replayRecord: ReplayRecord | undefined; | ||||||
} | ||||||
|
||||||
interface SummaryResponse { | ||||||
summary: string; | ||||||
} | ||||||
|
||||||
function createAISummaryQueryKey( | ||||||
orgSlug: string, | ||||||
projectSlug: string | undefined, | ||||||
replayId: string | ||||||
): ApiQueryKey { | ||||||
return [ | ||||||
`/projects/${orgSlug}/${projectSlug}/replays/${replayId}/summarize/breadcrumbs/`, | ||||||
]; | ||||||
} | ||||||
|
||||||
export default function Ai({replayRecord}: Props) { | ||||||
const organization = useOrganization(); | ||||||
const {project: project_id} = useLocationQuery({ | ||||||
fields: {project: decodeScalar}, | ||||||
}); | ||||||
const project = useProjectFromId({project_id}); | ||||||
|
||||||
const { | ||||||
data: summaryData, | ||||||
isLoading, | ||||||
isError, | ||||||
error, | ||||||
} = useApiQuery<SummaryResponse>( | ||||||
createAISummaryQueryKey(organization.slug, project?.slug, replayRecord?.id ?? ''), | ||||||
{ | ||||||
staleTime: 5 * 60 * 1000, // 5 minutes | ||||||
enabled: Boolean(replayRecord?.id && project?.slug), | ||||||
} | ||||||
); | ||||||
|
||||||
const renderContent = () => { | ||||||
if (isLoading) { | ||||||
return ( | ||||||
<LoadingContainer> | ||||||
<LoadingIndicator /> | ||||||
</LoadingContainer> | ||||||
); | ||||||
} | ||||||
|
||||||
if (isError || error) { | ||||||
return <Alert type="error">{t('Failed to load AI summary')}</Alert>; | ||||||
} | ||||||
|
||||||
if (!summaryData) { | ||||||
return <Alert type="info">{t('No summary available for this replay.')}</Alert>; | ||||||
} | ||||||
|
||||||
return ( | ||||||
<SummaryContainer> | ||||||
<SummaryText>{summaryData.summary}</SummaryText> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</SummaryContainer> | ||||||
); | ||||||
}; | ||||||
|
||||||
return ( | ||||||
<PaddedFluidHeight> | ||||||
<TabItemContainer data-test-id="replay-details-ai-summary-tab"> | ||||||
{renderContent()} | ||||||
</TabItemContainer> | ||||||
</PaddedFluidHeight> | ||||||
); | ||||||
} | ||||||
|
||||||
const PaddedFluidHeight = styled(FluidHeight)` | ||||||
padding-top: ${space(1)}; | ||||||
`; | ||||||
|
||||||
const LoadingContainer = styled('div')` | ||||||
display: flex; | ||||||
justify-content: center; | ||||||
padding: ${space(4)}; | ||||||
`; | ||||||
|
||||||
const SummaryContainer = styled('div')` | ||||||
padding: ${space(2)}; | ||||||
`; | ||||||
|
||||||
const SummaryText = styled('p')` | ||||||
line-height: 1.6; | ||||||
margin: 0; | ||||||
white-space: pre-wrap; | ||||||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.