From 3094b45cf7a5b3981ca66ff8616d3c9c5c1841f4 Mon Sep 17 00:00:00 2001 From: Nico Hinderling Date: Thu, 9 Apr 2026 13:55:56 -0700 Subject: [PATCH 1/4] feat(snapshots): Add diff_threshold field to snapshot manifest Add an optional --diff-threshold CLI flag that is passed through to the backend in the snapshot manifest. When set, Sentry will only report images as changed if their pixel difference exceeds the given threshold (e.g. 0.01 = 1%). Co-Authored-By: Claude --- src/api/data_types/snapshots.rs | 4 ++++ src/commands/build/snapshots.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/api/data_types/snapshots.rs b/src/api/data_types/snapshots.rs index 62fe80d4dd..0d6f5ca0f0 100644 --- a/src/api/data_types/snapshots.rs +++ b/src/api/data_types/snapshots.rs @@ -25,6 +25,10 @@ pub struct CreateSnapshotResponse { pub struct SnapshotsManifest<'a> { pub app_id: String, pub images: HashMap, + /// If set, Sentry will only report images as changed if their difference % + /// is greater than this value (e.g. 0.01 = only report changes >= 1%). + #[serde(skip_serializing_if = "Option::is_none")] + pub diff_threshold: Option, #[serde(flatten)] pub vcs_info: VcsInfo<'a>, } diff --git a/src/commands/build/snapshots.rs b/src/commands/build/snapshots.rs index 04bea69fa4..38f2cca550 100644 --- a/src/commands/build/snapshots.rs +++ b/src/commands/build/snapshots.rs @@ -51,6 +51,17 @@ pub fn make_command(command: Command) -> Command { .help("The application identifier.") .required(true), ) + .arg( + Arg::new("diff_threshold") + .long("diff-threshold") + .value_name("THRESHOLD") + .value_parser(clap::value_parser!(f64)) + .help( + "If set, Sentry will only report images as changed if their \ + difference % is greater than this value. \ + Example: 0.01 = only report image changes >= 1%.", + ), + ) .git_metadata_args() } @@ -123,9 +134,12 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { let manifest_entries = upload_images(images, &org, &project)?; // Build manifest from discovered images + let diff_threshold = matches.get_one::("diff_threshold").copied(); + let manifest = SnapshotsManifest { app_id: app_id.clone(), images: manifest_entries, + diff_threshold, vcs_info, }; From 96f8c00c9168678226f622f3ee3ae53e377e5030 Mon Sep 17 00:00:00 2001 From: Nico Hinderling Date: Thu, 9 Apr 2026 13:58:39 -0700 Subject: [PATCH 2/4] fix(snapshots): Validate diff_threshold is between 0.0 and 1.0 Co-Authored-By: Claude --- src/commands/build/snapshots.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/build/snapshots.rs b/src/commands/build/snapshots.rs index 38f2cca550..5c8f8b4c73 100644 --- a/src/commands/build/snapshots.rs +++ b/src/commands/build/snapshots.rs @@ -55,7 +55,13 @@ pub fn make_command(command: Command) -> Command { Arg::new("diff_threshold") .long("diff-threshold") .value_name("THRESHOLD") - .value_parser(clap::value_parser!(f64)) + .value_parser(|s: &str| { + let v: f64 = s.parse().map_err(|e| format!("invalid float: {e}"))?; + if !(0.0..=1.0).contains(&v) { + return Err("value must be between 0.0 and 1.0".to_owned()); + } + Ok(v) + }) .help( "If set, Sentry will only report images as changed if their \ difference % is greater than this value. \ From 13a1bec4e66ea0ea38260f0dc5fec1a3462095ba Mon Sep 17 00:00:00 2001 From: Nico Hinderling Date: Thu, 9 Apr 2026 13:59:08 -0700 Subject: [PATCH 3/4] docs(changelog): Add entry for diff_threshold option Co-Authored-By: Claude --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3ba26551..858ca4ddc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### New Features ✨ +- (snapshots) Add `--diff-threshold` option to `build snapshots` to set a minimum pixel difference percentage for reporting image changes ([#3259](https://github.com/getsentry/sentry-cli/pull/3259)) - Add `sentry-cli build download` command to download installable builds (IPA/APK) by build ID ([#3221](https://github.com/getsentry/sentry-cli/pull/3221)). - Add `sentry-cli code-mappings upload` command to bulk upload code mappings from a JSON file ([#3207](https://github.com/getsentry/sentry-cli/pull/3207), [#3208](https://github.com/getsentry/sentry-cli/pull/3208), [#3209](https://github.com/getsentry/sentry-cli/pull/3209), [#3210](https://github.com/getsentry/sentry-cli/pull/3210)). - Code mappings link stack trace paths (e.g. `com/example/module`) to source paths in your repository (e.g. `src/main/java/com/example/module`), enabling Sentry to display source context and link directly to your code from error stack traces. From 8b593f2e9f955465f3bf37bd316d3efb4271d38b Mon Sep 17 00:00:00 2001 From: Nico Hinderling Date: Thu, 9 Apr 2026 14:05:14 -0700 Subject: [PATCH 4/4] test(snapshots): Update help snapshot for diff_threshold option Co-Authored-By: Claude --- .../_cases/build/build-snapshots-help.trycmd | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/integration/_cases/build/build-snapshots-help.trycmd b/tests/integration/_cases/build/build-snapshots-help.trycmd index 56a7937694..ef71757741 100644 --- a/tests/integration/_cases/build/build-snapshots-help.trycmd +++ b/tests/integration/_cases/build/build-snapshots-help.trycmd @@ -29,16 +29,16 @@ Options: --auth-token Use the given Sentry auth token. - --head-sha - The VCS commit sha to use for the upload. If not provided, the current commit sha will be - used. + --diff-threshold + If set, Sentry will only report images as changed if their difference % is greater than + this value. Example: 0.01 = only report image changes >= 1%. --log-level Set the log output verbosity. [possible values: trace, debug, info, warn, error] - --base-sha - The VCS commit's base sha to use for the upload. If not provided, the merge-base of the - current and remote branch will be used. + --head-sha + The VCS commit sha to use for the upload. If not provided, the current commit sha will be + used. --quiet Do not print any output while preserving correct exit code. This flag is currently @@ -46,6 +46,10 @@ Options: [aliases: --silent] + --base-sha + The VCS commit's base sha to use for the upload. If not provided, the merge-base of the + current and remote branch will be used. + --vcs-provider The VCS provider to use for the upload. If not provided, the current provider will be used.