: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
chore(error-tracking): poison pill handling (#57146)
Zach Brown02f423f8d7a1
diff --git a/nodejs/src/ingestion/error-tracking/cymbal/client.test.ts b/nodejs/src/ingestion/error-tracking/cymbal/client.test.tsindex 8670ca79d3b6..6ba8b19132e1 100644--- a/nodejs/src/ingestion/error-tracking/cymbal/client.test.ts+++ b/nodejs/src/ingestion/error-tracking/cymbal/client.test.ts@@ -568,4 +568,96 @@ describe('CymbalClient', () => {expect(await client.healthCheck()).toBe(false)})})++ describe('poison pill isolation', () => {+ const createTimeoutError = () => {+ const error = new Error('The operation was aborted due to timeout')+ error.name = 'TimeoutError'+ return error+ }++ it('fans out to individual events on timeout and drops the poison pill', async () => {+ const client = createClient()+ const requests = [+ createRequest({ uuid: 'good-1' }),+ createRequest({ uuid: 'good-2' }),+ createRequest({ uuid: 'poison' }),+ createRequest({ uuid: 'good-3' }),+ ]++ mockFetch.mockImplementation((_url: string, opts: { body: string }) => {+ const parsed = parseJSON(opts.body) as CymbalRequest[]+ const hasPoison = parsed.some((r: CymbalRequest) => r.uuid === 'poison')+ if (hasPoison) {+ return Promise.reject(createTimeoutError())+ }+ return Promise.resolve({+ status: 200,+ json: () => Promise.resolve(parsed.map((r: CymbalRequest) => createResponse({ uuid: r.uuid }))),+ })+ })++ const results = await client.processExceptions(toItems(requests))++ expect(results).toHaveLength(4)+ expect(results[0]).toMatchObject({ uuid: 'good-1' })+ expect(results[1]).toMatchObject({ uuid: 'good-2' })+ expect(results[2]).toBeNull() // poison pill dropped+ expect(results[3]).toMatchObject({ uuid: 'good-3' })+ })++ it('throws 5xx errors during fan-out to let retry wrapper handle them', async () => {+ const client = createClient()+ const requests = [createRequest({ uuid: 'a' }), createRequest({ uuid: 'b' })]++ let callCount = 0+ mockFetch.mockImplementation(() => {+ callCount+++ if (callCount === 1) {+ // First call: batch times out, triggers fan-out+ return Promise.reject(createTimeoutError())+ }+ // During fan-out: first individual event hits a 5xx+ return Promise.resolve({ status: 500, json: () => Promise.resolve({}) })+ })++ await expect(client.processExceptions(toItems(requests))).rejects.toThrow('Cymbal returned 500')+ })++ it('preserves 1:1 ordering with poison pill at various positions', async () => {+ const client = createClient()+ const inputs = ['a', 'b', 'POISON', 'c', 'd']+ const requests = inputs.map((id) => createRequest({ uuid: id }))++ mockFetch.mockImplementation((_url: string, opts: { body: string }) => {+ const parsed = parseJSON(opts.body) as CymbalRequest[]+ if (parsed.some((r: CymbalRequest) => r.uuid === 'POISON')) {+ return Promise.reject(createTimeoutError())+ }+ return Promise.resolve({+ status: 200,+ json: () => Promise.resolve(parsed.map((r: CymbalRequest) => createResponse({ uuid: r.uuid }))),+ })+ })++ const results = await client.processExceptions(toItems(requests))++ expect(results).toHaveLength(5)+ for (let i = 0; i < inputs.length; i++) {+ if (inputs[i] === 'POISON') {+ expect(results[i]).toBeNull()+ } else {+ expect(results[i]).toMatchObject({ uuid: inputs[i] })+ }+ }+ })++ it('does not fan out single-event batches', async () => {+ const client = createClient()+ mockFetch.mockRejectedValue(createTimeoutError())++ // Single event timeout throws normally — no fan-out possible+ await expect(client.processExceptions(toItems([createRequest()]))).rejects.toThrow()+ })+ })})diff --git a/nodejs/src/ingestion/error-tracking/cymbal/client.ts b/nodejs/src/ingestion/error-tracking/cymbal/client.tsindex 09d1ab2b4d7e..f3053e48c899 100644--- a/nodejs/src/ingestion/error-tracking/cymbal/client.ts+++ b/nodejs/src/ingestion/error-tracking/cymbal/client.ts@@ -49,6 +49,11 @@ const cymbalRoutingGroupsHistogram = new Histogram({buckets: [1, 2, 3, 5, 10, 20, 50],})+const cymbalPoisonPillCounter = new Counter({+ name: 'error_tracking_cymbal_poison_pill_total',+ help: 'Events identified as poison pills via per-event fan-out on timeout',+})+/** Function signature for fetch implementation */export type FetchFunction = (url: string,@@ -74,11 +79,13 @@ export interface CymbalClientConfig {*/class CymbalError extends Error {isRetriable: boolean+ isTimeout: boolean- constructor(message: string, isRetriable: boolean) {+ constructor(message: string, isRetriable: boolean, isTimeout: boolean = false) {super(message)this.name = 'CymbalError'this.isRetriable = isRetriable+ this.isTimeout = isTimeout}}@@ -229,16 +236,71 @@ export class CymbalClient {const allResults: (CymbalResponse | null)[] = []for (const chunk of chunks) {- const results = await this.processChunk(- url,- chunk.map((item) => item.request)- )- allResults.push(...results)+ try {+ const results = await this.processChunk(+ url,+ chunk.map((item) => item.request)+ )+ allResults.push(...results)+ } catch (error) {+ if (!(error instanceof CymbalError) || !error.isTimeout || chunk.length <= 1) {+ throw error+ }+ // Timeout on a multi-event chunk — fan out to individual events+ // to isolate the poison pill. Non-timeout errors on individual+ // events are thrown to let the retry wrapper handle them.+ logger.warn('⚠️', 'cymbal_timeout_fan_out', {+ url,+ chunkSize: chunk.length,+ })+ const results = await this.fanOutOnTimeout(url, chunk)+ allResults.push(...results)+ }}return allResults}+ /**+ * Fan out a timed-out chunk to individual events. Each event gets a single+ * attempt through processChunk. Events that succeed return their response.+ * Events that timeout are confirmed poison pills and return null (dropped).+ * Non-timeout errors (5xx, network) are thrown to abort the fan-out and let+ * the retry wrapper handle them.+ */+ private async fanOutOnTimeout(+ url: string,+ items: { request: CymbalRequest; estimatedSize: number }[]+ ): Promise<(CymbalResponse | null)[]> {+ const results: (CymbalResponse | null)[] = []+ const concurrency = 10++ for (let i = 0; i < items.length; i += concurrency) {+ const batch = items.slice(i, i + concurrency)+ const batchResults = await Promise.all(+ batch.map(async (item): Promise<CymbalResponse | null> => {+ try {+ const [result] = await this.processChunk(url, [item.request])+ return result+ } catch (error) {+ if (error instanceof CymbalError && error.isTimeout) {+ cymbalPoisonPillCounter.inc()+ logger.error('🧪', 'cymbal_poison_pill_identified', {+ uuid: item.request.uuid,+ teamId: item.request.team_id,+ })+ return null+ }+ throw error+ }+ })+ )+ results.push(...batchResults)+ }++ return results+ }+/*** Process a single chunk of requests through Cymbal's HTTP API.*/@@ -331,8 +393,11 @@ export class CymbalClient {} catch (error) {const durationMs = performance.now() - startTimethis.recordMetrics('error', durationMs, requests.length)- // Network/timeout errors are retriable- throw new CymbalError(error instanceof Error ? error.message : String(error), true)+ // Network/timeout errors are retriable. Preserve whether the+ // original error was a timeout so the retry wrapper can distinguish+ // "Cymbal is hanging on this data" from "Cymbal is down."+ const isTimeout = error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError')+ throw new CymbalError(error instanceof Error ? error.message : String(error), true, isTimeout)}}diff --git a/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.test.ts b/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.test.tsindex ef899e063370..b0d449cbf1de 100644--- a/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.test.ts+++ b/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.test.ts@@ -649,8 +649,8 @@ describe('ErrorTrackingPipeline', () => {// so Kafka doesn't commit and retries the batchawait expect(runErrorTrackingPipeline(pipeline, [message])).rejects.toThrow('Cymbal unavailable')- // Cymbal was called 10 times (initial + 9 retries) before giving up- expect(mockCymbalClient.processExceptions).toHaveBeenCalledTimes(10)+ // Cymbal was called 3 times (initial + 2 retries) before giving up+ expect(mockCymbalClient.processExceptions).toHaveBeenCalledTimes(3)expect(mockHogTransformer.transformEventAndProduceMessages).not.toHaveBeenCalled()})diff --git a/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.ts b/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.tsindex e0db4c1517e8..9b4ed2e2a896 100644--- a/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.ts+++ b/nodejs/src/ingestion/error-tracking/error-tracking-pipeline.ts@@ -233,10 +233,11 @@ export function createErrorTrackingPipeline(// Process through Cymbal as a batch (before enrichment - Cymbal only// needs raw exception data, not person/geoip/group data).// Retry on transient failures (5xx, timeout, network errors).- // 10 tries with 100ms base sleep and 2x backoff (capped at 10s)- // gives ~30s total budget to ride out a Cymbal restart.+ // 3 retries keeps the worst-case batch time (3 × 45s timeout =+ // 135s) well within the 180s liveness interval, and reduces+ // amplification pressure on Cymbal during degradation..pipeBatchWithRetry(createCymbalProcessingStep(cymbalClient), {- tries: 10,+ tries: 3,sleepMs: 100,})// Enrich, prepare, create, and emit events