: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): override record_count header when drop rules remove rows (#67161)
Frank Hamand634cc76c722b
diff --git a/nodejs/src/logs/logs-ingestion-consumer.test.ts b/nodejs/src/logs/logs-ingestion-consumer.test.tsindex b733211ef41d..818fe4c6e869 100644--- a/nodejs/src/logs/logs-ingestion-consumer.test.ts+++ b/nodejs/src/logs/logs-ingestion-consumer.test.ts@@ -1775,9 +1775,11 @@ describe('LogsIngestionConsumer', () => {const uncompressed = parseInt(outputHeaders()!.bytes_uncompressed, 10)const compressed = parseInt(outputHeaders()!.bytes_compressed, 10)+ const recordCount = parseInt(outputHeaders()!.record_count, 10)if (!enabled) {expect(uncompressed).toBe(1000)expect(compressed).toBe(500)+ expect(recordCount).toBe(2)return}expect(uncompressed).toBeGreaterThan(0)@@ -1785,6 +1787,8 @@ describe('LogsIngestionConsumer', () => {expect(compressed).toBeGreaterThan(0)expect(compressed).toBeLessThan(500)expect(compressed / uncompressed).toBeCloseTo(0.5, 5)+ // The dropped info row is removed from the count exactly; only the error row survives.+ expect(recordCount).toBe(1)})})})diff --git a/nodejs/src/logs/logs-ingestion-consumer.ts b/nodejs/src/logs/logs-ingestion-consumer.tsindex f9cabcc4c41f..c5aeb0e3877b 100644--- a/nodejs/src/logs/logs-ingestion-consumer.ts+++ b/nodejs/src/logs/logs-ingestion-consumer.ts@@ -577,6 +577,7 @@ export class LogsIngestionConsumer {let bytesUncompressedHeaderOverride: number | undefinedlet bytesCompressedHeaderOverride: number | undefined+ let recordCountHeaderOverride: number | undefined// Drop rules removed rows from this message — credit billing by the dropped// content fraction. `bytesReceived` stays gross (what was sent); `bytesAllowed`@@ -628,8 +629,9 @@ export class LogsIngestionConsumer {)}- // Scale both size headers down by the same dropped content fraction so- // downstream accounting sees only the surviving bytes.+ // Scale both size headers down by the same dropped content fraction, and+ // reduce the record count by the exact number of rows dropped, so+ // downstream accounting sees only the surviving rows and bytes.const compressedCredit = billingByteReductionForDrops(message.bytesCompressed,resolved.contentBytesDropped,@@ -637,6 +639,7 @@ export class LogsIngestionConsumer {)bytesUncompressedHeaderOverride = Math.max(0, header - contentCredit)bytesCompressedHeaderOverride = Math.max(0, message.bytesCompressed - compressedCredit)+ recordCountHeaderOverride = Math.max(0, message.recordCount - resolved.recordsDropped)}}@@ -672,6 +675,9 @@ export class LogsIngestionConsumer {...(bytesCompressedHeaderOverride !== undefined? { bytes_compressed: bytesCompressedHeaderOverride.toString() }: {}),+ ...(recordCountHeaderOverride !== undefined+ ? { record_count: recordCountHeaderOverride.toString() }+ : {}),},},])