: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(llma): replace copy-trace button with share dropdown (#58222)
posthog[bot]5f009fd0c508
diff --git a/products/llm_analytics/frontend/LLMAnalyticsTraceScene.tsx b/products/llm_analytics/frontend/LLMAnalyticsTraceScene.tsxindex 031c03855a73..496c011c12d1 100644--- a/products/llm_analytics/frontend/LLMAnalyticsTraceScene.tsx+++ b/products/llm_analytics/frontend/LLMAnalyticsTraceScene.tsx@@ -8,14 +8,17 @@ import { useDebouncedCallback } from 'use-debounce'import {IconAIText,+ IconChevronDown,IconChevronLeft,IconChevronRight,IconComment,IconCopy,+ IconDownload,IconMessage,IconPlay,IconReceipt,IconSearch,+ IconShare,} from '@posthog/icons'import {LemonButton,@@ -24,6 +27,7 @@ import {LemonDivider,LemonDialog,LemonInput,+ LemonMenu,LemonSelect,LemonTable,LemonTabs,@@ -88,7 +92,7 @@ import { SearchHighlight } from './SearchHighlight'import { SENTIMENT_DATE_WINDOW_DAYS } from './sentimentUtils'import { SummaryViewDisplay } from './summary-view/SummaryViewDisplay'import { TextViewDisplay } from './text-view/TextViewDisplay'-import { exportTraceToClipboard } from './traceExportUtils'+import { exportTraceToClipboard, exportTraceToFile } from './traceExportUtils'import { TraceReviewButton } from './traceReviews/TraceReviewButton'import { traceReviewModalLogic } from './traceReviews/traceReviewModalLogic'import { traceReviewsLazyLoaderLogic } from './traceReviews/traceReviewsLazyLoaderLogic'@@ -530,7 +534,7 @@ function TraceSceneWrapper(): JSX.Element {Discussion</LemonButton>)}- <CopyTraceButton trace={trace} tree={enrichedTree} />+ <ShareTraceButton trace={trace} tree={enrichedTree} /></div></div></div>@@ -1870,22 +1874,36 @@ function EventTypeFilters(): JSX.Element {)}-function CopyTraceButton({ trace, tree }: { trace: LLMTrace; tree: EnrichedTraceTreeNode[] }): JSX.Element {- const handleCopyTrace = async (): Promise<void> => {- await exportTraceToClipboard(trace, tree)- }-+function ShareTraceButton({ trace, tree }: { trace: LLMTrace; tree: EnrichedTraceTreeNode[] }): JSX.Element {return (- <LemonButton- type="secondary"- size="xsmall"- icon={<IconCopy />}- onClick={handleCopyTrace}- tooltip="Copy trace to clipboard"- data-attr="copy-trace-json"+ <LemonMenu+ items={[+ {+ label: 'Copy to clipboard',+ icon: <IconCopy />,+ onClick: () => void exportTraceToClipboard(trace, tree),+ 'data-attr': 'llma-trace-share-copy',+ },+ {+ label: 'Download file',+ icon: <IconDownload />,+ onClick: () => exportTraceToFile(trace, tree),+ 'data-attr': 'llma-trace-share-download',+ },+ ]}+ placement="bottom-end">- Copy trace JSON- </LemonButton>+ <LemonButton+ type="secondary"+ size="xsmall"+ icon={<IconShare />}+ sideIcon={<IconChevronDown />}+ tooltip="Share trace JSON"+ data-attr="llma-trace-share-button"+ >+ Share+ </LemonButton>+ </LemonMenu>)}diff --git a/products/llm_analytics/frontend/traceExportUtils.ts b/products/llm_analytics/frontend/traceExportUtils.tsindex a78091c91c34..43dc978ff7f5 100644--- a/products/llm_analytics/frontend/traceExportUtils.ts+++ b/products/llm_analytics/frontend/traceExportUtils.ts@@ -1,3 +1,4 @@+import { downloadFile, slugify } from 'lib/utils'import { copyToClipboard } from 'lib/utils/copyToClipboard'import { LLMTrace, LLMTraceEvent } from '~/queries/schema/schema-general'@@ -158,9 +159,16 @@ export function buildMinimalTraceJSON(trace: LLMTrace, tree: EnrichedTraceTreeNoreturn result}+function buildTraceJSONString(trace: LLMTrace, tree: EnrichedTraceTreeNode[]): string {+ return JSON.stringify(buildMinimalTraceJSON(trace, tree), null, 2)+}+export async function exportTraceToClipboard(trace: LLMTrace, tree: EnrichedTraceTreeNode[]): Promise<void> {- const exportData = buildMinimalTraceJSON(trace, tree)- const jsonString = JSON.stringify(exportData, null, 2)+ await copyToClipboard(buildTraceJSONString(trace, tree), 'trace data')+}- await copyToClipboard(jsonString, 'trace data')+export function exportTraceToFile(trace: LLMTrace, tree: EnrichedTraceTreeNode[]): void {+ const filename = `${slugify(trace.traceName || trace.id || 'trace')}.trace.json`+ const file = new File([buildTraceJSONString(trace, tree)], filename, { type: 'application/json' })+ downloadFile(file)}