: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(logs): copy message/raw popover and raw tab copy affordance (#69168)
Jon McCallum65128bc41434
diff --git a/products/logs/frontend/components/LogsViewer/CopyLogButton.tsx b/products/logs/frontend/components/LogsViewer/CopyLogButton.tsxnew file mode 100644index 000000000000..4088f4fb1ed2--- /dev/null+++ b/products/logs/frontend/components/LogsViewer/CopyLogButton.tsx@@ -0,0 +1,65 @@+import { IconCopy } from '@posthog/icons'+import { LemonButton } from '@posthog/lemon-ui'++import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from 'lib/ui/DropdownMenu/DropdownMenu'+import { copyToClipboard } from 'lib/utils/copyToClipboard'++import { ParsedLogMessage } from 'products/logs/frontend/types'++export function copyLogRaw(log: ParsedLogMessage): void {+ void copyToClipboard(JSON.stringify(log.originalLog, null, 2), 'raw log')+}++function copyLogMessage(log: ParsedLogMessage): void {+ void copyToClipboard(log.body, 'log message')+}++interface CopyLogButtonProps {+ log: ParsedLogMessage+ size?: 'xsmall' | 'small'+ noPadding?: boolean+ className?: string+}++/** Icon button that opens a two-choice menu: copy the log message, or copy the full raw log. */+export function CopyLogButton({ log, size = 'xsmall', noPadding, className }: CopyLogButtonProps): JSX.Element {+ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <LemonButton+ size={size}+ noPadding={noPadding}+ icon={<IconCopy />}+ tooltip="Copy log"+ aria-label="Copy log"+ className={className}+ data-attr="logs-viewer-copy-menu-open"+ />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem asChild>+ <ButtonPrimitive+ menuItem+ onClick={() => copyLogMessage(log)}+ data-attr="logs-viewer-copy-message-body"+ >+ <IconCopy />+ Copy message+ </ButtonPrimitive>+ </DropdownMenuItem>+ <DropdownMenuItem asChild>+ <ButtonPrimitive menuItem onClick={() => copyLogRaw(log)} data-attr="logs-viewer-copy-message-raw">+ <IconCopy />+ Copy raw+ </ButtonPrimitive>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )+}diff --git a/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx b/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsxindex 6bcf1757cff8..9a38fcbac96e 100644--- a/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx+++ b/products/logs/frontend/components/LogsViewer/LogDetailsModal/LogDetailsModal.tsx@@ -7,10 +7,10 @@ import { JSONViewer } from 'lib/components/JSONViewer'import { TZLabel } from 'lib/components/TZLabel'import ViewRecordingButton, { RecordingPlayerType } from 'lib/components/ViewRecordingButton/ViewRecordingButton'import { IconLink } from 'lib/lemon-ui/icons'-import { copyToClipboard } from 'lib/utils/copyToClipboard'import { PropertyFilterType, PropertyOperator } from '~/types'+import { CopyLogButton, copyLogRaw } from 'products/logs/frontend/components/LogsViewer/CopyLogButton'import { LogContextSelector } from 'products/logs/frontend/components/LogsViewer/LogContextSelector/LogContextSelector'import { LogDetailsTabContent } from 'products/logs/frontend/components/LogsViewer/LogDetailsModal/Tabs/Details/LogDetailsTab'@@ -93,14 +93,7 @@ export function LogDetailsModal({ timezone }: LogDetailsModalProps): JSX.Element<div className="flex items-center justify-between"><h3>Log details</h3><div className="flex items-center gap-1">- <LemonButton- size="xsmall"- icon={<IconCopy />}- onClick={() => void copyToClipboard(selectedLog.body, 'log message')}- tooltip="Copy log message"- aria-label="Copy log message"- data-attr="logs-viewer-copy-message"- />+ <CopyLogButton log={selectedLog} /><LemonButtonsize="xsmall"icon={<IconLink />}@@ -167,13 +160,22 @@ export function LogDetailsModal({ timezone }: LogDetailsModalProps): JSX.Elementlabel: 'Raw',content: (<div className="flex flex-col gap-2">- <div className="flex items-center">+ <div className="flex items-center justify-between"><LemonCheckboxchecked={jsonParseAllFields}onChange={setJsonParseAllFields}label="JSON parse all fields"size="small"/>+ <LemonButton+ size="xsmall"+ type="secondary"+ icon={<IconCopy />}+ onClick={() => copyLogRaw(selectedLog)}+ data-attr="logs-viewer-copy-raw"+ >+ Copy raw+ </LemonButton></div><div className="p-2 bg-bg-light rounded overflow-auto"><JSONViewer src={displayData} collapsed={2} sortKeys />diff --git a/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx b/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsxindex b27fef039990..7b75119f02af 100644--- a/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx+++ b/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx@@ -1,21 +1,13 @@import { useActions, useValues } from 'kea'-import {- IconBrackets,- IconChevronLeft,- IconChevronRight,- IconCopy,- IconExpand45,- IconPin,- IconPinFilled,-} from '@posthog/icons'+import { IconBrackets, IconChevronLeft, IconChevronRight, IconExpand45, IconPin, IconPinFilled } from '@posthog/icons'import { LemonButton } from '@posthog/lemon-ui'import ViewRecordingButton, { RecordingPlayerType } from 'lib/components/ViewRecordingButton/ViewRecordingButton'import { IconLink } from 'lib/lemon-ui/icons'-import { copyToClipboard } from 'lib/utils/copyToClipboard'import { cn } from 'lib/utils/css-classes'+import { CopyLogButton } from 'products/logs/frontend/components/LogsViewer/CopyLogButton'import { LogContextSelector } from 'products/logs/frontend/components/LogsViewer/LogContextSelector/LogContextSelector'import { logDetailsModalLogic } from 'products/logs/frontend/components/LogsViewer/LogDetailsModal'import { logsViewerLogic } from 'products/logs/frontend/components/LogsViewer/logsViewerLogic'@@ -97,19 +89,7 @@ export function LogRowFAB({aria-label={pinned ? 'Unpin log' : 'Pin log'}className={cn(pinned ? 'text-warning' : 'text-muted')}/>- <LemonButton- size="xsmall"- noPadding- icon={<IconCopy />}- onClick={(e) => {- e.preventDefault()- void copyToClipboard(log.body, 'log message')- }}- tooltip="Copy log message"- aria-label="Copy log message"- className="text-muted"- data-attr="logs-viewer-copy-message"- />+ <CopyLogButton log={log} noPadding className="text-muted" /><LemonButtonsize="xsmall"noPadding