: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(replay-recorder-v4): record flush and flush attempt durations (#127398)
Nicholas Waltz92021a5bc78d
diff --git a/rust/ai-research/replay-recorder-v4/src/consumer.rs b/rust/ai-research/replay-recorder-v4/src/consumer.rsindex d8806d5e26ad..761bbad04b94 100644--- a/rust/ai-research/replay-recorder-v4/src/consumer.rs+++ b/rust/ai-research/replay-recorder-v4/src/consumer.rs@@ -8,7 +8,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};use common_kafka::config::KafkaConfig;use futures::FutureExt;use lifecycle::Handle;-use metrics::counter;+use metrics::{counter, histogram};use rdkafka::consumer::{BaseConsumer, CommitMode, Consumer, ConsumerContext, RebalanceProtocol, StreamConsumer,};@@ -705,6 +705,7 @@ async fn flush_steps(handle: &Handle,retries: u32,) -> Result<(), String> {+ let flush_started = Instant::now();let offsets: HashMap<Tp, (u64, i64)> = batch.spans.iter()@@ -747,6 +748,7 @@ async fn flush_steps());}let timeout = settings.flush_timeout.min(left);+ let attempt_started = Instant::now();let stored = tokio::time::timeout(timeout,with_heartbeat(@@ -755,6 +757,13 @@ async fn flush_steps(),).await;+ let outcome = match &stored {+ Ok(Ok(())) => "ok",+ Ok(Err(_)) => "error",+ Err(_) => "timeout",+ };+ histogram!("ai_research_v4_recorder_flush_attempt_duration_seconds", "outcome" => outcome)+ .record(attempt_started.elapsed().as_secs_f64());let error = match stored {Ok(Ok(())) => break,Ok(Err(error)) => error.to_string(),@@ -770,6 +779,8 @@ async fn flush_steps(}}with_heartbeat(handle, consumer.commit(&offsets)).await?;+ histogram!("ai_research_v4_recorder_flush_duration_seconds")+ .record(flush_started.elapsed().as_secs_f64());inspectors.evict_idle(settings.session_idle);Ok(())}diff --git a/rust/ai-research/replay-recorder-v4/src/main.rs b/rust/ai-research/replay-recorder-v4/src/main.rsindex a2fbb6a726ec..01cf5b1a287f 100644--- a/rust/ai-research/replay-recorder-v4/src/main.rs+++ b/rust/ai-research/replay-recorder-v4/src/main.rs@@ -5,7 +5,7 @@ use axum::{routing::get, Router};use common_database::{get_pool_with_config, PoolConfig};use common_kafka::config::KafkaConfig;use common_kafka::kafka_producer::create_kafka_producer;-use common_metrics::setup_metrics_routes;+use common_metrics::{setup_metrics_routes_with_overrides, Matcher};use envconfig::Envconfig;use lifecycle::{ComponentOptions, Manager};use tracing::level_filters::LevelFilter;@@ -23,6 +23,10 @@ use replay_recorder_v4::limits::{Restrictions, SessionLimiter};use replay_recorder_v4::store::S3Store;use replay_recorder_v4::teams::TeamCache;+const FLUSH_DURATION_BUCKETS_SECONDS: &[f64] = &[+ 0.5, 1.0, 2.5, 5.0, 10.0, 20.0, 30.0, 45.0, 60.0, 90.0, 120.0, 180.0, 300.0,+];+common_alloc::used!();/// The index producer's local queue. A block row is a few KB, so this holds several large flushes.@@ -98,10 +102,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}")).await.expect("bind metrics port");- axum::serve(listener, setup_metrics_routes(router))- .with_graceful_shutdown(metrics_handle.shutdown_signal())- .await- .expect("metrics server");+ let overrides = [(+ Matcher::Prefix("ai_research_v4_recorder_flush_".to_owned()),+ FLUSH_DURATION_BUCKETS_SECONDS,+ )];+ axum::serve(+ listener,+ setup_metrics_routes_with_overrides(router, &overrides),+ )+ .with_graceful_shutdown(metrics_handle.shutdown_signal())+ .await+ .expect("metrics server");});// The first team list must load before any message is read: an empty list would skip every message as unknown.