: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
fix(logs): declare pattern sample size and round extrapolated counts (#68151)
Jon McCallumfa71861cebb0
diff --git a/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsx b/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsxindex df54be266ac4..fd28370b3f5f 100644--- a/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsx+++ b/products/logs/frontend/components/LogsPatterns/LogsPatterns.tsx@@ -1,10 +1,10 @@import { useValues } from 'kea'-import { LemonTable, LemonTag } from '@posthog/lemon-ui'+import { LemonBanner, LemonTable, LemonTag, Tooltip } from '@posthog/lemon-ui'import type { LemonTableColumns } from '@posthog/lemon-ui'import { TZLabel } from 'lib/components/TZLabel'-import { humanFriendlyNumber } from 'lib/utils/numbers'+import { humanFriendlyLargeNumber, humanFriendlyNumber } from 'lib/utils/numbers'import type { _LogPatternApi } from 'products/logs/frontend/generated/api.schemas'@@ -33,8 +33,23 @@ export function LogsPatterns({ id }: { id: string }): JSX.Element {const { patterns, patternsResponse, patternsResponseLoading, patternsError } = useValues(logsPatternsLogic({ id }))const { sampled, scanned_count, total_count, sample_coverage_pct } = patternsResponse- // Estimated counts get a "~" so a reader never mistakes an extrapolation for a measurement.- const renderEstimate = (value: number): string => `${sampled ? '~' : ''}${humanFriendlyNumber(value)}`+ // Estimated counts are rounded (not exact-comma-formatted) and prefixed with "~" so a+ // reader never mistakes an extrapolation for a measurement; the tooltip carries the raw+ // sample fact the estimate was derived from.+ const renderEstimate = (estimated: number, sampleCount: number): JSX.Element | string => {+ if (!sampled) {+ return humanFriendlyNumber(estimated)+ }+ return (+ <Tooltip+ title={`${humanFriendlyNumber(sampleCount)} of the ${humanFriendlyNumber(+ scanned_count+ )} sampled lines — extrapolated to the full window`}+ >+ <span>~{humanFriendlyLargeNumber(estimated)}</span>+ </Tooltip>+ )+ }const columns: LemonTableColumns<_LogPatternApi> = [{@@ -45,7 +60,7 @@ export function LogsPatterns({ id }: { id: string }): JSX.Element {{title: 'Count',dataIndex: 'estimated_count',- render: (_, row) => renderEstimate(row.estimated_count),+ render: (_, row) => renderEstimate(row.estimated_count, row.count),sorter: (a, b) => a.estimated_count - b.estimated_count,align: 'right',},@@ -61,7 +76,7 @@ export function LogsPatterns({ id }: { id: string }): JSX.Element {dataIndex: 'estimated_error_count',render: (_, row) =>row.estimated_error_count > 0 ? (- <LemonTag type="danger">{renderEstimate(row.estimated_error_count)}</LemonTag>+ <LemonTag type="danger">{renderEstimate(row.estimated_error_count, row.error_count)}</LemonTag>) : (<span className="text-muted">0</span>),@@ -89,14 +104,16 @@ export function LogsPatterns({ id }: { id: string }): JSX.Element {return (<div className="flex-1 min-h-0 overflow-auto" data-attr="logs-patterns">{sampled && !patternsResponseLoading && !patternsError && (- <div className="text-muted text-xs px-2 py-1" data-attr="logs-patterns-sample-info">- Mined from a sample of {humanFriendlyNumber(scanned_count)} of {humanFriendlyNumber(total_count)}{' '}- lines+ <LemonBanner type="info" className="m-2" data-attr="logs-patterns-sample-info">+ Patterns are mined from a representative sample of {humanFriendlyNumber(scanned_count)} lines out of+ the {humanFriendlyLargeNumber(total_count)} matching your filters{sample_coverage_pct < 100- ? `, drawn from evenly-spaced slices covering ${sample_coverage_pct.toFixed(1)}% of the window`+ ? `, drawn from evenly-spaced time slices covering ${sample_coverage_pct.toFixed(+ 1+ )}% of the window`: ''}- . Counts are estimates.- </div>+ . Counts are estimates for the full window — hover a count for the underlying sample figure.+ </LemonBanner>)}<LemonTablecolumns={columns}