Skip to content

: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.

feat(logs): show bytes dropped alongside records in drop-rule 24h panel (#59544)

Daniel Viscab0622d24b8cd
diff --git a/products/logs/frontend/components/LogsSampling/logsSamplingSectionLogic.ts b/products/logs/frontend/components/LogsSampling/logsSamplingSectionLogic.ts
index d17e5aab8b87..3567a89d379e 100644
--- a/products/logs/frontend/components/LogsSampling/logsSamplingSectionLogic.ts
+++ b/products/logs/frontend/components/LogsSampling/logsSamplingSectionLogic.ts
@@ -67,7 +67,15 @@ export const logsSamplingSectionLogic = kea<logsSamplingSectionLogicType>([
return {}
}
await breakpoint(1)
- return await fetchSamplingRuleDropTotalsLast24h(ids)
+ const totals = await fetchSamplingRuleDropTotalsLast24h(ids)
+ // The list-view cell only renders record count (column space is tight).
+ // Byte totals are surfaced on the rule detail page; here we collapse
+ // back to the records number this loader has always exposed.
+ const out: Record<string, number> = {}
+ for (const [id, { records }] of Object.entries(totals)) {
+ out[id] = records
+ }
+ return out
},
},
],
diff --git a/products/logs/frontend/components/LogsSampling/samplingRuleDropImpact.ts b/products/logs/frontend/components/LogsSampling/samplingRuleDropImpact.ts
index 88ba4d73373c..b8975fe3d720 100644
--- a/products/logs/frontend/components/LogsSampling/samplingRuleDropImpact.ts
+++ b/products/logs/frontend/components/LogsSampling/samplingRuleDropImpact.ts
@@ -2,19 +2,34 @@ import api from 'lib/api'
import { type HogQLQueryString, hogql } from '~/queries/utils'
-/** Ingestion writes per-rule drops to app_metrics2; HogQL exposes it as `app_metrics`. */
-export async function fetchSamplingRuleDropTotalsLast24h(ruleIds: string[]): Promise<Record<string, number>> {
+export interface SamplingRuleDropTotals {
+ records: number
+ bytes: number
+}
+
+/**
+ * Ingestion writes per-rule drops to app_metrics2; HogQL exposes it as `app_metrics`.
+ * Records are always populated (counted since the original metrics PR); bytes are
+ * populated for any drop that ran through a producer carrying per-row `bytes_uncompressed`
+ * (i.e. since the bytes-by-row producer change rolled out). Older drops attribute 0 bytes.
+ */
+export async function fetchSamplingRuleDropTotalsLast24h(
+ ruleIds: string[]
+): Promise<Record<string, SamplingRuleDropTotals>> {
if (ruleIds.length === 0) {
return {}
}
const query = hogql`
- SELECT instance_id, sum(count) AS dropped
+ SELECT
+ instance_id,
+ metric_name,
+ sum(count) AS total
FROM app_metrics
WHERE app_source = ${'logs'}
- AND metric_name = ${'sampling_records_dropped_by_rule'}
+ AND metric_name IN (${'sampling_records_dropped_by_rule'}, ${'bytes_dropped_by_rule'})
AND instance_id IN ${ruleIds}
AND timestamp >= now() - INTERVAL 24 HOUR
- GROUP BY instance_id
+ GROUP BY instance_id, metric_name
` as HogQLQueryString
const response = await api.queryHogQL(query, {
@@ -23,13 +38,21 @@ export async function fetchSamplingRuleDropTotalsLast24h(ruleIds: string[]): Pro
name: 'sampling_rule_drop_totals_24h',
})
- const out: Record<string, number> = {}
+ const out: Record<string, SamplingRuleDropTotals> = {}
for (const row of response.results ?? []) {
const instanceId = String(row[0] ?? '')
+ const metricName = String(row[1] ?? '')
+ const total = Number(row[2] ?? 0)
if (!instanceId) {
continue
}
- out[instanceId] = Number(row[1] ?? 0)
+ const existing = out[instanceId] ?? { records: 0, bytes: 0 }
+ if (metricName === 'sampling_records_dropped_by_rule') {
+ existing.records = total
+ } else if (metricName === 'bytes_dropped_by_rule') {
+ existing.bytes = total
+ }
+ out[instanceId] = existing
}
return out
}
diff --git a/products/logs/frontend/scenes/LogsSamplingDetailScene/LogsSamplingDetailScene.tsx b/products/logs/frontend/scenes/LogsSamplingDetailScene/LogsSamplingDetailScene.tsx
index cd377007af53..4b4ecf7cf104 100644
--- a/products/logs/frontend/scenes/LogsSamplingDetailScene/LogsSamplingDetailScene.tsx
+++ b/products/logs/frontend/scenes/LogsSamplingDetailScene/LogsSamplingDetailScene.tsx
@@ -5,7 +5,7 @@ import { IconInfo, IconRefresh } from '@posthog/icons'
import { LemonButton, LemonDialog } from '@posthog/lemon-ui'
import { Tooltip } from 'lib/lemon-ui/Tooltip/Tooltip'
-import { compactNumber } from 'lib/utils'
+import { compactNumber, humanizeBytes } from 'lib/utils'
import { SceneExport } from 'scenes/sceneTypes'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
@@ -102,10 +102,16 @@ function LogsSamplingDetailFormBody({ rule }: { rule: LogsSamplingRuleApi }): JS
) : (
<>
{/* Keep the last known number visible during a manual refresh so
- users can compare before / after rather than seeing it disappear. */}
+ users can compare before / after rather than seeing it disappear.
+ Bytes are reported alongside records once the per-row bytes_uncompressed
+ signal lands on each row at ingest — older drops attribute 0 bytes and
+ the byte clause is hidden. */}
<span>
- ~{compactNumber(ruleDropImpact24h)} log lines dropped in the last 24 hours
- (ingestion).
+ ~{compactNumber(ruleDropImpact24h.records)} log lines
+ {ruleDropImpact24h.bytes > 0 && (
+ <> (~{humanizeBytes(ruleDropImpact24h.bytes)})</>
+ )}{' '}
+ dropped in the last 24 hours (ingestion).
</span>
<Tooltip
title={
diff --git a/products/logs/frontend/scenes/LogsSamplingDetailScene/logsSamplingDetailSceneLogic.ts b/products/logs/frontend/scenes/LogsSamplingDetailScene/logsSamplingDetailSceneLogic.ts
index 2bfbce8bb730..4d06da9eee8e 100644
--- a/products/logs/frontend/scenes/LogsSamplingDetailScene/logsSamplingDetailSceneLogic.ts
+++ b/products/logs/frontend/scenes/LogsSamplingDetailScene/logsSamplingDetailSceneLogic.ts
@@ -13,7 +13,10 @@ import {
buildSamplingFormDefaults,
logsSamplingFormLogic,
} from 'products/logs/frontend/components/LogsSampling/logsSamplingFormLogic'
-import { fetchSamplingRuleDropTotalsLast24h } from 'products/logs/frontend/components/LogsSampling/samplingRuleDropImpact'
+import {
+ type SamplingRuleDropTotals,
+ fetchSamplingRuleDropTotalsLast24h,
+} from 'products/logs/frontend/components/LogsSampling/samplingRuleDropImpact'
import { logsSamplingRulesDestroy, logsSamplingRulesRetrieve } from 'products/logs/frontend/generated/api'
import { LogsSamplingRuleApi } from 'products/logs/frontend/generated/api.schemas'
import { logsDropRulesSettingsUrl } from 'products/logs/frontend/logsDropRulesSettingsUrl'
@@ -54,12 +57,12 @@ export const logsSamplingDetailSceneLogic = kea<logsSamplingDetailSceneLogicType
},
],
ruleDropImpact24h: [
- null as number | null,
+ null as SamplingRuleDropTotals | null,
{
loadRuleDropImpact24h: async (_, breakpoint) => {
await breakpoint(1)
const map = await fetchSamplingRuleDropTotalsLast24h([props.id])
- return map[props.id] ?? 0
+ return map[props.id] ?? { records: 0, bytes: 0 }
},
},
],