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(error-tracking): log per-run chunk upload summary in the CLI (#74991)

Aleksander Błaszkiewicza29315a19c59
diff --git a/cli/.sampo/changesets/upload-summary-counts.md b/cli/.sampo/changesets/upload-summary-counts.md
new file mode 100644
index 000000000000..ebe01e0533b4
--- /dev/null
+++ b/cli/.sampo/changesets/upload-summary-counts.md
@@ -0,0 +1,5 @@
+---
+cargo/posthog-cli: patch
+---
+
+Sourcemap, dSYM, and ProGuard uploads now end with a single per-run summary line reporting how many chunks were uploaded, skipped as already present on the server, and skipped as too large. The summary is logged even when a run fails partway, and the same counts are attached to the `error_tracking_cli_sourcemaps_upload_finished` telemetry event so skip rates are queryable.
diff --git a/cli/src/api/symbol_sets.rs b/cli/src/api/symbol_sets.rs
index 66f82fe4be68..aaa08d54e42b 100644
--- a/cli/src/api/symbol_sets.rs
+++ b/cli/src/api/symbol_sets.rs
@@ -40,6 +40,46 @@ pub struct SymbolSetUpload {
pub data: Vec<u8>,
}
+/// Per-run tally of what an upload actually did. Without it a run that skipped
+/// every chunk is indistinguishable from one that uploaded every chunk, since
+/// both just exit zero.
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
+pub struct UploadSummary {
+ pub uploaded: usize,
+ pub skipped_already_present: usize,
+ pub skipped_too_large: usize,
+}
+
+impl UploadSummary {
+ pub fn skipped(&self) -> usize {
+ self.skipped_already_present + self.skipped_too_large
+ }
+
+ pub fn telemetry_props(&self) -> Vec<(&'static str, serde_json::Value)> {
+ vec![
+ ("uploaded", serde_json::json!(self.uploaded)),
+ (
+ "skipped_already_present",
+ serde_json::json!(self.skipped_already_present),
+ ),
+ (
+ "skipped_too_large",
+ serde_json::json!(self.skipped_too_large),
+ ),
+ ]
+ }
+
+ fn log(&self) {
+ info!(
+ "Upload summary: {} chunk(s) uploaded, {} skipped ({} already present, {} too large)",
+ self.uploaded,
+ self.skipped(),
+ self.skipped_already_present,
+ self.skipped_too_large
+ );
+ }
+}
+
#[derive(Debug, Serialize, Deserialize, Clone)]
struct StartUploadResponseData {
presigned_url: PresignedUrl,
@@ -78,13 +118,17 @@ struct BulkUploadFinishRequest {
/// the upload will be retried without release IDs.
/// If `force` is true, symbol sets whose content has changed are overwritten rather than skipped.
/// If `skip_on_conflict` is true, symbol sets whose content has changed are skipped rather than failing.
+///
+/// The summary is returned beside the result rather than inside it, because a
+/// failed run still needs to report the chunks it uploaded and skipped before
+/// it gave up.
pub fn upload_with_retry(
input_sets: Vec<SymbolSetUpload>,
batch_size: usize,
skip_release_on_fail: bool,
force: bool,
skip_on_conflict: bool,
-) -> Result<()> {
+) -> (UploadSummary, Result<()>) {
upload_with_retry_and_concurrency(
input_sets,
batch_size,
@@ -102,13 +146,21 @@ pub fn upload_with_retry_and_concurrency(
force: bool,
skip_on_conflict: bool,
concurrency: NonZeroUsize,
-) -> Result<()> {
- let thread_pool = build_upload_thread_pool(concurrency)?;
+) -> (UploadSummary, Result<()>) {
+ let mut summary = UploadSummary::default();
+ let thread_pool = match build_upload_thread_pool(concurrency) {
+ Ok(thread_pool) => thread_pool,
+ Err(e) => return (summary, Err(e)),
+ };
// One client for the whole run: reusing its connection pool avoids paying a
// TCP + TLS handshake per uploaded chunk.
- let s3_client = context()
+ let s3_client = match context()
.build_http_client()
- .context("Failed to initialize upload HTTP client")?;
+ .context("Failed to initialize upload HTTP client")
+ {
+ Ok(client) => client,
+ Err(e) => return (summary, Err(e)),
+ };
let res = upload_inner(
&input_sets,
batch_size,
@@ -116,11 +168,15 @@ pub fn upload_with_retry_and_concurrency(
skip_on_conflict,
&thread_pool,
&s3_client,
+ &mut summary,
);
- match res {
- Ok(()) => Ok(()),
+ let res = match res {
Err(UploadError::ReleaseIdMismatch) if skip_release_on_fail => {
warn!("Release ID mismatch detected. Retrying upload without release IDs...");
+ // Batches finalized before the mismatch are on the server by the time
+ // the retry runs, so upload_inner recounts them as already present.
+ // Remember them and reclassify below, because this run did upload them.
+ let uploaded_before_retry = summary.uploaded;
let sets_without_release: Vec<_> = input_sets
.into_iter()
.map(|s| SymbolSetUpload {
@@ -129,18 +185,28 @@ pub fn upload_with_retry_and_concurrency(
data: s.data,
})
.collect();
- upload_inner(
+ let res = upload_inner(
&sets_without_release,
batch_size,
force,
skip_on_conflict,
&thread_pool,
&s3_client,
- )
- .map_err(|e| e.into())
+ &mut summary,
+ );
+ summary.uploaded += uploaded_before_retry;
+ summary.skipped_already_present = summary
+ .skipped_already_present
+ .saturating_sub(uploaded_before_retry);
+ res
}
- Err(e) => Err(e.into()),
- }
+ res => res,
+ };
+
+ // Logged on failure too, so a partial run still reports how far it got.
+ summary.log();
+
+ (summary, res.map_err(Into::into))
}
fn build_upload_thread_pool(concurrency: NonZeroUsize) -> Result<ThreadPool> {
@@ -157,11 +223,17 @@ fn upload_inner(
skip_on_conflict: bool,
thread_pool: &ThreadPool,
s3_client: &Client,
+ summary: &mut UploadSummary,
) -> Result<(), UploadError> {
+ // A release-id-mismatch retry re-uploads the same sets from scratch, so the
+ // tally starts over rather than double-counting the first attempt.
+ *summary = UploadSummary::default();
+
let upload_requests: Vec<_> = input_sets
.iter()
.filter(|s| {
if s.data.len() > MAX_FILE_SIZE {
+ summary.skipped_too_large += 1;
warn!(
"Skipping symbol set with id: {}, file too large",
s.chunk_id
@@ -185,6 +257,7 @@ fn upload_inner(
.map(|(u, hash)| (u.chunk_id.as_str(), (u, hash)))
.collect();
+ summary.skipped_already_present += batch.len() - start_response.id_map.len();
info!(
"Server returned {} upload keys ({} skipped as already present)",
start_response.id_map.len(),
@@ -208,8 +281,10 @@ fn upload_inner(
});
let content_hashes = res?;
+ let uploaded = content_hashes.len();
finish_upload(content_hashes)?;
+ summary.uploaded += uploaded;
}
Ok(())
diff --git a/cli/src/debug_symbols/upload.rs b/cli/src/debug_symbols/upload.rs
index e34af0e853ef..769283fd9e24 100644
--- a/cli/src/debug_symbols/upload.rs
+++ b/cli/src/debug_symbols/upload.rs
@@ -123,13 +123,14 @@ pub fn upload(args: &Args) -> Result<()> {
// --include-source implies force unless the user explicitly asked to keep
// existing symbol sets with --skip-on-conflict.
let effective_force = conflict.force || (*include_source && !conflict.skip_on_conflict);
- api::symbol_sets::upload_with_retry(
+ let (_summary, upload_result) = api::symbol_sets::upload_with_retry(
uploads,
10,
release_args.skip_release_on_fail,
effective_force,
conflict.skip_on_conflict,
- )?;
+ );
+ upload_result?;
info!("Debug symbol upload complete");
Ok(())
diff --git a/cli/src/dsym/upload.rs b/cli/src/dsym/upload.rs
index 6a8e3fac1a94..c5b0c23cdbcb 100644
--- a/cli/src/dsym/upload.rs
+++ b/cli/src/dsym/upload.rs
@@ -201,13 +201,14 @@ pub fn upload(args: &Args) -> Result<()> {
// --include-source implies force unless the user explicitly asked to keep
// existing symbol sets with --skip-on-conflict.
let effective_force = conflict.force || (*include_source && !conflict.skip_on_conflict);
- api::symbol_sets::upload_with_retry(
+ let (_summary, upload_result) = api::symbol_sets::upload_with_retry(
uploads,
10,
release_args.skip_release_on_fail,
effective_force,
conflict.skip_on_conflict,
- )?;
+ );
+ upload_result?;
info!("dSYM upload complete");
Ok(())
diff --git a/cli/src/proguard/upload.rs b/cli/src/proguard/upload.rs
index 33cda63e1610..7f40a392bb4f 100644
--- a/cli/src/proguard/upload.rs
+++ b/cli/src/proguard/upload.rs
@@ -77,13 +77,14 @@ pub fn upload(args: &Args) -> Result<()> {
let to_upload: SymbolSetUpload = file.try_into()?;
- api::symbol_sets::upload_with_retry(
+ let (_summary, upload_result) = api::symbol_sets::upload_with_retry(
vec![to_upload],
*batch_size,
*skip_release_on_fail,
conflict.force,
conflict.skip_on_conflict,
- )?;
+ );
+ upload_result?;
Ok(())
}
diff --git a/cli/src/sourcemaps/hermes/upload.rs b/cli/src/sourcemaps/hermes/upload.rs
index 817d99b26b83..5f1b0041e0a1 100644
--- a/cli/src/sourcemaps/hermes/upload.rs
+++ b/cli/src/sourcemaps/hermes/upload.rs
@@ -91,7 +91,7 @@ pub fn upload(args: &Args) -> Result<()> {
);
let started_at = Instant::now();
- let upload_result = symbol_sets::upload_with_retry(
+ let (summary, upload_result) = symbol_sets::upload_with_retry(
uploads,
*batch_size,
release.skip_release_on_fail,
@@ -107,6 +107,7 @@ pub fn upload(args: &Args) -> Result<()> {
("duration_ms", json!(duration_ms)),
("success", json!(upload_result.is_ok())),
];
+ props.extend(summary.telemetry_props());
if let Err(ref e) = upload_result {
props.push(("error", json!(format!("{:#}", e))));
}
diff --git a/cli/src/sourcemaps/plain/upload.rs b/cli/src/sourcemaps/plain/upload.rs
index a7ff0698e63b..2b51b9c11033 100644
--- a/cli/src/sourcemaps/plain/upload.rs
+++ b/cli/src/sourcemaps/plain/upload.rs
@@ -153,7 +153,7 @@ pub fn upload(args: &Args, existing_release: Option<&Release>) -> Result<()> {
);
let started_at = Instant::now();
- let upload_result = symbol_sets::upload_with_retry_and_concurrency(
+ let (summary, upload_result) = symbol_sets::upload_with_retry_and_concurrency(
uploads,
args.batch_size,
args.release.skip_release_on_fail,
@@ -170,6 +170,7 @@ pub fn upload(args: &Args, existing_release: Option<&Release>) -> Result<()> {
("duration_ms", json!(duration_ms)),
("success", json!(upload_result.is_ok())),
];
+ props.extend(summary.telemetry_props());
if let Err(ref e) = upload_result {
props.push(("error", json!(format!("{:#}", e))));
}