:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(error-tracking): replace fix prompt modal with AgentPromptButton (#60180)
Catalin Irimie44e22b674ca5
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 53a799fb03aa..f8c71116e5ac 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1512,6 +1512,10 @@ snapshots:hash: v1.k794b7964.e3ef4fd9cc4b6d78c9b770bd7ba6d8113539cd73ce87b31013306f745ea9202f.9NtMQB2_LUzXfE_zDhDnKUsCgHVWc4ttxT2tpksLyhwerrortracking-exceptioncard--exception-card-session-timeline-without-steps--light:hash: v1.k794b7964.56e62ea17d56098dfa8d66ad4499e743df46e0c1924f8df73f2b6478079c48ea.oSzjIEqfVs8iFv6Ed8nN0I07e3StdO56qy6oIoeRrUA+ errortracking-stacktraceactions--default--dark:+ hash: v1.k794b7964.91672c912d93ad2ed58f1ba200f7ca1fcaee83297f5936f2399c53d47a154d6f.7oRecDOjn9XKHnTyts_9Ko_lK_576I_0NXnJh1gu6V0+ errortracking-stacktraceactions--default--light:+ hash: v1.k794b7964.e71e9c6c659253a5ebb77c302c3a4ca30a1026d722dc20bcecd9cdfa412aa2c3.24lOV34SOsFGjAvDzHMQaw-XNf7eQrd8VyBsY839SLwerrortracking-stacktracedisplay--generic-display-empty--dark:hash: v1.k794b7964.c6ab3cf58033c6b078df8533c0fb3bf4e99ad647d2d10fef3c12265f9d8c1151.R27Z2h6kgWs7HZgZQXOoQN5MKDt9L0SNXqtRdq9d8XYerrortracking-stacktracedisplay--generic-display-empty--light:@@ -4859,7 +4863,7 @@ snapshots:scenes-app-insights-funnels--funnel-left-to-right-breakdown-edit--light:hash: v1.k794b7964.414326f685dca45885b93d728ae8a75c7d8b600af35d76c9512a74a27e453006.IyZ8qHUwOv6qsBYvdUR1ZsK1Md_GNFCftDGvNZj78BQscenes-app-insights-funnels--funnel-left-to-right-edit--dark:- hash: v1.k794b7964.293297b83994468984576e5c15fa2cbbb2c4c0a7a8234959b9deba539efa383b.xupnP9sdcp25xPBOMzrhSHwtRpKPLKHaqLDBncapvQA+ hash: v1.k794b7964.c47bdb853ef9b6becfb675e2ca0bdbdb0c1b4385cf2442d50dd92752d90f7906.gaL7vRk-pWoOUkiPi-NGCd1W72x-M5l9jk5Qu-UcjwIscenes-app-insights-funnels--funnel-left-to-right-edit--light:hash: v1.k794b7964.c63132bb5b13cbe97938ebdb2e59e320ebc338bd12b2d3bfd6af81e56270650a.3gc3UBg-8GVo4HkNBH7UrogK2q1uh9pXPDjTdYGT8ncscenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--dark:diff --git a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsxindex 274b8483a28e..797be629deb4 100644--- a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx+++ b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx@@ -44,6 +44,8 @@ export interface AgentPromptButtonProps {size?: ButtonSize/** Renders the dropdown open on first paint. Useful for visual regression snapshots. */defaultOpen?: boolean+ /** Fired whenever a combo runs (agent deeplink opened or clipboard copied). Useful for analytics. */+ onRun?: (params: { actionKey: string; agentKey: string }) => void'data-attr'?: string}@@ -136,6 +138,7 @@ export function AgentPromptButton({storageKey,size = 'sm',defaultOpen = false,+ onRun,'data-attr': dataAttr,}: AgentPromptButtonProps): JSX.Element | null {const resolvedStorageKey =@@ -166,6 +169,7 @@ export function AgentPromptButton({const runCombo = (actionKey: string, agentKey: string): void => {const action = actions.find((a) => a.key === actionKey) ?? actions[0]const prompt = action.buildPrompt()+ onRun?.({ actionKey, agentKey })if (agentKey === CLIPBOARD_KEY) {void copyToClipboard(prompt, `${action.label.toLowerCase()} prompt`)returndiff --git a/products/error_tracking/frontend/components/ExceptionCard/FixModal.tsx b/products/error_tracking/frontend/components/ExceptionCard/FixModal.tsxdeleted file mode 100644index af882eb7abad..000000000000--- a/products/error_tracking/frontend/components/ExceptionCard/FixModal.tsx+++ /dev/null@@ -1,120 +0,0 @@-import { useActions, useValues } from 'kea'-import posthog from 'posthog-js'--import { LemonButton, LemonModal, LemonSegmentedButton } from '@posthog/lemon-ui'--import { copyToClipboard } from 'lib/utils/copyToClipboard'-import { urls } from 'scenes/urls'--import { useStacktraceDisplay } from '../../hooks/use-stacktrace-display'-import { fixModalLogic } from './fixModalLogic'--interface FixModalProps {- isOpen: boolean- onClose: () => void- issueId: string-}--export function FixModal({ isOpen, onClose, issueId }: FixModalProps): JSX.Element {- const { mode } = useValues(fixModalLogic)- const { setMode } = useActions(fixModalLogic)- const { stacktraceText } = useStacktraceDisplay()-- const generatePrompt = (): string => {- const issueUrl = window.location.origin + urls.errorTrackingIssue(issueId)-- if (mode === 'explain') {- return `Please help me understand this error in depth. Here's the stack trace:--\`\`\`-${stacktraceText}-\`\`\`--Note: Frames marked with [IN-APP] are from the application code (my code), while frames without this marker are from external libraries/frameworks.-Focus your analysis primarily on the [IN-APP] frames as these are most likely where the issue originates.--Can you:-1. Perform a deep dive analysis into what's causing this error. Consider multiple possible factors and dig deep to find the root cause.-2. Explain the relevant parts of the code that are involved in this error. Walk through the execution flow that leads to this issue.-3. Provide a detailed explanation of exactly how this issue happened, including the sequence of events and conditions that trigger it.-4. Include code examples and context where helpful to illustrate your explanation.--The final output should be:-- A comprehensive technical explanation of the root cause-- A walkthrough of the relevant code paths-- A detailed summary of exactly how the issue occurs--PostHog issue: ${issueUrl}-`- }- return `Please help me fix the root cause of this error. Here's the stack trace:--\`\`\`-${stacktraceText}-\`\`\`--Note: Frames marked with [IN-APP] are from the application code (my code), while frames without this marker are from external libraries/frameworks.-Focus your analysis primarily on the [IN-APP] frames as these are most likely where the issue needs to be fixed.--Can you:-1. Gather relevant information from the codebase to understand the context of this error.-2. Inspect the code paths involved to identify the root cause.-3. Determine the simplest and cleanest fix for this issue.-4. Implement the fix directly in the codebase.--The final output of your efforts should be:-- An implemented fix for the issue applied directly to the code-- A brief explanation of what was changed and why--PostHog issue: ${issueUrl}-`- }-- const handleCopy = (): void => {- void copyToClipboard(generatePrompt(), 'LLM prompt')- posthog.capture('error_tracking_prompt_copied', { issue_id: issueId, mode })- onClose()- }-- return (- <LemonModal- isOpen={isOpen}- onClose={onClose}- title={mode === 'explain' ? 'Explain this error with AI' : 'Fix this error with AI'}- width="50rem"- footer={- <div className="flex items-center justify-end gap-2">- <LemonButton type="secondary" onClick={onClose}>- Close- </LemonButton>- <LemonButton type="primary" onClick={handleCopy}>- Copy to clipboard- </LemonButton>- </div>- }- >- <div className="space-y-4">- <div className="flex items-center gap-2">- <span className="text-muted">Mode:</span>- <LemonSegmentedButton- value={mode}- onChange={(newMode) => setMode(newMode)}- options={[- { value: 'explain', label: 'Explain' },- { value: 'fix', label: 'Fix' },- ]}- size="small"- />- </div>- <p className="text-muted">- {mode === 'explain'- ? 'Paste this prompt into your favourite coding assistant to get a detailed explanation of this error:'- : 'Paste this prompt into your favourite coding assistant to get help fixing this error:'}- </p>- <div className="bg-bg-light border rounded p-4 font-mono text-sm whitespace-pre-wrap max-h-96 overflow-auto">- {generatePrompt()}- </div>- </div>- </LemonModal>- )-}diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.stories.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.stories.tsxnew file mode 100644index 000000000000..c87f300f9fe7--- /dev/null+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.stories.tsx@@ -0,0 +1,56 @@+import { Meta } from '@storybook/react'++import { LemonCard } from '@posthog/lemon-ui'++import { sceneLogic } from 'scenes/sceneLogic'++import { mswDecorator } from '~/mocks/browser'+import { ErrorTrackingRelationalIssue } from '~/queries/schema/schema-general'++import { ExceptionLogicWrapper } from '../../../../__mocks__/events'+import { StyleVariables } from '../../../StyleVariables'+import { StackTraceActions } from './StackTraceActions'++const MOCK_ISSUE: ErrorTrackingRelationalIssue = {+ id: 'issue-id',+ name: 'Test issue',+ description: null,+ assignee: null,+ status: 'active',+ first_seen: '2024-01-01T00:00:00Z',+}++const meta: Meta = {+ title: 'ErrorTracking/StackTraceActions',+ parameters: {+ layout: 'centered',+ viewMode: 'story',+ },+ decorators: [+ (Story: React.FC): JSX.Element => {+ sceneLogic.mount()+ return (+ <StyleVariables>+ <LemonCard hoverEffect={false} className="p-2">+ <Story />+ </LemonCard>+ </StyleVariables>+ )+ },+ mswDecorator({+ post: {+ 'api/environments/:team_id/error_tracking/stack_frames/batch_get/': require('../../../../__mocks__/stack_frames/batch_get'),+ },+ }),+ ],+}++export default meta++export function Default(): JSX.Element {+ return (+ <ExceptionLogicWrapper eventName="javascript_resolved">+ <StackTraceActions issue={MOCK_ISSUE} />+ </ExceptionLogicWrapper>+ )+}diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsxindex 6206d64b77c0..3b69fffc588d 100644--- a/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsx+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsx@@ -1,8 +1,9 @@import { useActions, useValues } from 'kea'-import { useState } from 'react'+import posthog from 'posthog-js'-import { IconChevronDown, IconMagicWand } from '@posthog/icons'+import { IconChevronDown, IconInfo, IconMagicWand, IconWrench } from '@posthog/icons'+import { AgentPromptButton } from 'lib/components/AgentPromptButton'import { errorPropertiesLogic } from 'lib/components/Errors/errorPropertiesLogic'import { ErrorTrackingException } from 'lib/components/Errors/types'import { ButtonGroupPrimitive, ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'@@ -17,9 +18,10 @@ import {import { ErrorTrackingRelationalIssue } from '~/queries/schema/schema-general'+import { useStacktraceDisplay } from '../../../../hooks/use-stacktrace-display'import { useErrorTrackingExplainIssue } from '../../../ExplainIssueTool'+import { buildExplainPrompt, buildFixPrompt } from '../../aiPrompts'import { exceptionCardLogic } from '../../exceptionCardLogic'-import { FixModal } from '../../FixModal'export interface StackTraceActionsProps {issue: ErrorTrackingRelationalIssue@@ -28,37 +30,55 @@ export interface StackTraceActionsProps {export function StackTraceActions({ issue }: StackTraceActionsProps): JSX.Element {const { exceptionList } = useValues(errorPropertiesLogic)const showFixButton = hasResolvedStackFrames(exceptionList)- const [showFixModal, setShowFixModal] = useState(false)+ const { stacktraceText } = useStacktraceDisplay()const { openMax } = useErrorTrackingExplainIssue(issue.id)return (- <ButtonGroupPrimitive size="sm">+ <div className="flex items-center gap-1">{showFixButton && (+ <AgentPromptButton+ storageKey="error-tracking-issue"+ data-attr="error-tracking-fix-with-ai"+ actions={[+ {+ key: 'fix',+ label: 'Fix',+ icon: <IconWrench />,+ buildPrompt: () => buildFixPrompt(stacktraceText, issue.id),+ },+ {+ key: 'explain',+ label: 'Explain',+ icon: <IconInfo />,+ buildPrompt: () => buildExplainPrompt(stacktraceText, issue.id),+ },+ ]}+ onRun={({ actionKey, agentKey }) =>+ posthog.capture('error_tracking_prompt_used', {+ issue_id: issue.id,+ mode: actionKey,+ agent: agentKey,+ })+ }+ />+ )}+ <ButtonGroupPrimitive size="sm"><ButtonPrimitive- onClick={() => setShowFixModal(true)}+ onClick={() => openMax()}className="px-2 h-[1.4rem]"- tooltip="Generate AI prompt to fix this error"+ tooltip="Ask PostHog AI for an explanation of this issue"><IconMagicWand />- Get AI prompt- </ButtonPrimitive>- )}- <ButtonPrimitive- onClick={() => openMax()}- className="px-2 h-[1.4rem]"- tooltip="Ask PostHog AI for an explanation of this issue"- >- <IconMagicWand />- Explain- </ButtonPrimitive>- <ShowDropDownMenu>- <ButtonPrimitive className="px-2 h-[1.4rem]">- Show- <IconChevronDown />+ Explain</ButtonPrimitive>- </ShowDropDownMenu>- <FixModal isOpen={showFixModal} onClose={() => setShowFixModal(false)} issueId={issue.id} />- </ButtonGroupPrimitive>+ <ShowDropDownMenu>+ <ButtonPrimitive className="px-2 h-[1.4rem]">+ Show+ <IconChevronDown />+ </ButtonPrimitive>+ </ShowDropDownMenu>+ </ButtonGroupPrimitive>+ </div>)}diff --git a/products/error_tracking/frontend/components/ExceptionCard/aiPrompts.ts b/products/error_tracking/frontend/components/ExceptionCard/aiPrompts.tsnew file mode 100644index 000000000000..e6ef0ed7f7d9--- /dev/null+++ b/products/error_tracking/frontend/components/ExceptionCard/aiPrompts.ts@@ -0,0 +1,54 @@+import { urls } from 'scenes/urls'++function issueUrl(issueId: string): string {+ return window.location.origin + urls.errorTrackingIssue(issueId)+}++export function buildFixPrompt(stacktraceText: string, issueId: string): string {+ return `Please help me fix the root cause of this error. Here's the stack trace:++\`\`\`+${stacktraceText}+\`\`\`++Note: Frames marked with [IN-APP] are from the application code (my code), while frames without this marker are from external libraries/frameworks.+Focus your analysis primarily on the [IN-APP] frames as these are most likely where the issue needs to be fixed.++Can you:+1. Gather relevant information from the codebase to understand the context of this error.+2. Inspect the code paths involved to identify the root cause.+3. Determine the simplest and cleanest fix for this issue.+4. Implement the fix directly in the codebase.++The final output of your efforts should be:+- An implemented fix for the issue applied directly to the code+- A brief explanation of what was changed and why++PostHog issue: ${issueUrl(issueId)}+`+}++export function buildExplainPrompt(stacktraceText: string, issueId: string): string {+ return `Please help me understand this error in depth. Here's the stack trace:++\`\`\`+${stacktraceText}+\`\`\`++Note: Frames marked with [IN-APP] are from the application code (my code), while frames without this marker are from external libraries/frameworks.+Focus your analysis primarily on the [IN-APP] frames as these are most likely where the issue originates.++Can you:+1. Perform a deep dive analysis into what's causing this error. Consider multiple possible factors and dig deep to find the root cause.+2. Explain the relevant parts of the code that are involved in this error. Walk through the execution flow that leads to this issue.+3. Provide a detailed explanation of exactly how this issue happened, including the sequence of events and conditions that trigger it.+4. Include code examples and context where helpful to illustrate your explanation.++The final output should be:+- A comprehensive technical explanation of the root cause+- A walkthrough of the relevant code paths+- A detailed summary of exactly how the issue occurs++PostHog issue: ${issueUrl(issueId)}+`+}diff --git a/products/error_tracking/frontend/components/ExceptionCard/fixModalLogic.ts b/products/error_tracking/frontend/components/ExceptionCard/fixModalLogic.tsdeleted file mode 100644index e41c831e72d5..000000000000--- a/products/error_tracking/frontend/components/ExceptionCard/fixModalLogic.ts+++ /dev/null@@ -1,21 +0,0 @@-import { actions, kea, path, reducers } from 'kea'--import type { fixModalLogicType } from './fixModalLogicType'--export type FixMode = 'explain' | 'fix'--export const fixModalLogic = kea<fixModalLogicType>([- path(['products', 'error_tracking', 'frontend', 'components', 'ExceptionCard', 'fixModalLogic']),- actions({- setMode: (mode: FixMode) => ({ mode }),- }),- reducers({- mode: [- 'fix' as FixMode,- { persist: true },- {- setMode: (_, { mode }) => mode,- },- ],- }),-])