: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
feat(cdp): add job-level lifecycle metrics for batch hogflow resolver (#67266)
Meikel Ratze0b80ba4811c
diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-batch-resolve.consumer.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-batch-resolve.consumer.tsindex 85c174491e6f..c15c30091706 100644--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-batch-resolve.consumer.ts+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-batch-resolve.consumer.ts@@ -37,6 +37,12 @@ const counterBatchHogFlowResolverPagesProcessed = new Counter({labelNames: ['outcome'], // success | fetch_failure | terminal_write_failure | invalid_state})+const counterBatchHogFlowResolverJobs = new Counter({+ name: 'cdp_batch_hog_flow_resolver_jobs',+ help: 'Batch hog flow resolver jobs by lifecycle outcome',+ labelNames: ['outcome'], // started | completed | failed+})+/*** State machine carried in `cyclotron_jobs.state` per resolver job:* cursor=null, pendingTerminal=undefined → fetch first page@@ -93,6 +99,7 @@ export class CdpCyclotronWorkerBatchResolve extends CdpConsumerBase<PluginsServe// older deploy. None should happen in steady state — alert on// the counter so we notice fast.counterBatchHogFlowResolverPagesProcessed.labels({ outcome: 'invalid_state' }).inc()+ counterBatchHogFlowResolverJobs.labels({ outcome: 'failed' }).inc()logger.error('🔴', `${this.name} - invalid resolver state, failing job`, {jobId: job.id,teamId: job.teamId,@@ -107,6 +114,16 @@ export class CdpCyclotronWorkerBatchResolve extends CdpConsumerBase<PluginsServereturn}+ // First-dequeue detection: the initial cyclotron invocation of a batch+ // resolver job arrives with cursor=null, no pending terminal, zero+ // pages processed, and zero attempts. `attempts` is required in the+ // guard because a first-page fetch failure reschedules with the same+ // cursor/pagesProcessed/pendingTerminal but bumps attempts — without+ // it, `started` would fire again on every retry of the first page.+ if (!state.pendingTerminal && state.cursor === null && state.pagesProcessed === 0 && state.attempts === 0) {+ counterBatchHogFlowResolverJobs.labels({ outcome: 'started' }).inc()+ }+try {if (state.pendingTerminal) {try {@@ -340,6 +357,7 @@ export class CdpCyclotronWorkerBatchResolve extends CdpConsumerBase<PluginsServecounterBatchHogFlowResolverPagesProcessed.labels({ outcome: 'terminal_write_failure' }).inc()const nextAttempts = state.attempts + 1if (nextAttempts >= MAX_RESOLVER_ATTEMPTS) {+ counterBatchHogFlowResolverJobs.labels({ outcome: 'failed' }).inc()logger.error('🔴',`${this.name} - terminal status write failed permanently after ${MAX_RESOLVER_ATTEMPTS} attempts; failing job`,@@ -366,6 +384,10 @@ export class CdpCyclotronWorkerBatchResolve extends CdpConsumerBase<PluginsServereturn}+ counterBatchHogFlowResolverJobs+ .labels({ outcome: state.pendingTerminal === 'completed' ? 'completed' : 'failed' })+ .inc()+// Monitoring flush happens in processResolverJob's finally block so every// dequeue clears its own queued logs/metrics, not just terminal writes.await job.ack()