: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
import { useState } from 'react'
import { IconChevronRight } from '@posthog/icons'
import { Link } from '@posthog/lemon-ui'
import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'
import { TZLabel } from 'lib/components/TZLabel'
import { dayjs } from 'lib/dayjs'
import { cn } from 'lib/utils/css-classes'
import { formatDurationMilliseconds } from 'lib/utils/durations'
import { urls } from 'scenes/urls'
import type { ReplayObservationApi } from '../generated/api.schemas'
import { modelLabel } from '../replay_scanners/types'
import { Fact, FactList } from './FactList'
function durationLabel(observation: ReplayObservationApi): string | null {
if (!observation.started_at || !observation.completed_at) {
return null
}
const ms = dayjs(observation.completed_at).diff(observation.started_at)
return Number.isFinite(ms) && ms >= 0 ? formatDurationMilliseconds(ms) : null
}
export function ObservationDetails({ observation }: { observation: ReplayObservationApi }): JSX.Element {
const [expanded, setExpanded] = useState(false)
const snapshot = observation.scanner_snapshot
const duration = durationLabel(observation)
return (
<div className="flex flex-col gap-2">
<button
type="button"
className="flex items-center gap-1 text-sm font-medium self-start hover:text-default"
onClick={() => setExpanded(!expanded)}
aria-expanded={expanded}
data-attr="vision-observation-technical-details-toggle"
>
<IconChevronRight className={cn('transition-transform', expanded && 'rotate-90')} />
Details
</button>
{expanded && (
<FactList>
<Fact label="Observation ID">
{/* CopyToClipboardInline children cannot shrink, so the ID sits outside it to truncate. */}
<div className="flex items-center min-w-0">
<span className="font-mono text-xs truncate min-w-0" title={observation.id}>
{observation.id}
</span>
<span className="shrink-0">
<CopyToClipboardInline
data-attr="vision-observation-copy"
explicitValue={observation.id}
description="observation ID"
iconSize="xsmall"
/>
</span>
</div>
</Fact>
<Fact label="Session">
<Link
to={urls.sessionProfile(observation.session_id)}
className="block font-mono text-xs truncate"
data-attr="vision-observation-session-link"
>
{observation.session_id}
</Link>
</Fact>
{/* The backend emits the event only once a scan succeeds. */}
{observation.status === 'succeeded' && observation.completed_at && (
<Fact label="Observation event">
<Link
data-attr="vision-observation-open-event"
to={urls.event(observation.id, observation.completed_at)}
>
$recording_observed
</Link>
</Fact>
)}
{observation.started_at && (
<Fact label="Started">
<TZLabel time={observation.started_at} />
</Fact>
)}
{observation.completed_at && (
<Fact label="Completed">
<TZLabel time={observation.completed_at} />
</Fact>
)}
{duration && <Fact label="Duration">{duration}</Fact>}
{snapshot?.model && <Fact label="Model">{modelLabel(snapshot.model)}</Fact>}
</FactList>
)}
</div>
)
}