Skip to content

Commit 1fb5ec5

Browse files
feat(snapshots): Add diff_threshold field to snapshot manifest (#3259)
Add an optional `--diff-threshold` CLI flag to the `build snapshots` command. The value is included in the snapshot manifest JSON sent to the backend. When set, Sentry will only report images as changed if their pixel difference percentage exceeds the given threshold (e.g. `0.01` = only report changes >= 1%). The backend does not yet consume this field — a follow-up PR in `getsentry/sentry` will read and apply it during comparison. Changes: - `SnapshotsManifest`: new `diff_threshold: Option<f64>` field, skipped when `None` - `make_command`: new `--diff-threshold <THRESHOLD>` CLI argument - `execute`: wires the CLI value into the manifest --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1854c4e commit 1fb5ec5

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
### New Features ✨
2222

23+
- (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))
2324
- Add `sentry-cli build download` command to download installable builds (IPA/APK) by build ID ([#3221](https://github.com/getsentry/sentry-cli/pull/3221)).
2425
- 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)).
2526
- 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.

src/api/data_types/snapshots.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub struct CreateSnapshotResponse {
2525
pub struct SnapshotsManifest<'a> {
2626
pub app_id: String,
2727
pub images: HashMap<String, ImageMetadata>,
28+
/// If set, Sentry will only report images as changed if their difference %
29+
/// is greater than this value (e.g. 0.01 = only report changes >= 1%).
30+
#[serde(skip_serializing_if = "Option::is_none")]
31+
pub diff_threshold: Option<f64>,
2832
#[serde(flatten)]
2933
pub vcs_info: VcsInfo<'a>,
3034
}

src/commands/build/snapshots.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ pub fn make_command(command: Command) -> Command {
5151
.help("The application identifier.")
5252
.required(true),
5353
)
54+
.arg(
55+
Arg::new("diff_threshold")
56+
.long("diff-threshold")
57+
.value_name("THRESHOLD")
58+
.value_parser(|s: &str| {
59+
let v: f64 = s.parse().map_err(|e| format!("invalid float: {e}"))?;
60+
if !(0.0..=1.0).contains(&v) {
61+
return Err("value must be between 0.0 and 1.0".to_owned());
62+
}
63+
Ok(v)
64+
})
65+
.help(
66+
"If set, Sentry will only report images as changed if their \
67+
difference % is greater than this value. \
68+
Example: 0.01 = only report image changes >= 1%.",
69+
),
70+
)
5471
.git_metadata_args()
5572
}
5673

@@ -123,9 +140,12 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
123140
let manifest_entries = upload_images(images, &org, &project)?;
124141

125142
// Build manifest from discovered images
143+
let diff_threshold = matches.get_one::<f64>("diff_threshold").copied();
144+
126145
let manifest = SnapshotsManifest {
127146
app_id: app_id.clone(),
128147
images: manifest_entries,
148+
diff_threshold,
129149
vcs_info,
130150
};
131151

tests/integration/_cases/build/build-snapshots-help.trycmd

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,27 @@ Options:
2929
--auth-token <AUTH_TOKEN>
3030
Use the given Sentry auth token.
3131

32-
--head-sha <head_sha>
33-
The VCS commit sha to use for the upload. If not provided, the current commit sha will be
34-
used.
32+
--diff-threshold <THRESHOLD>
33+
If set, Sentry will only report images as changed if their difference % is greater than
34+
this value. Example: 0.01 = only report image changes >= 1%.
3535

3636
--log-level <LOG_LEVEL>
3737
Set the log output verbosity. [possible values: trace, debug, info, warn, error]
3838

39-
--base-sha <base_sha>
40-
The VCS commit's base sha to use for the upload. If not provided, the merge-base of the
41-
current and remote branch will be used.
39+
--head-sha <head_sha>
40+
The VCS commit sha to use for the upload. If not provided, the current commit sha will be
41+
used.
4242

4343
--quiet
4444
Do not print any output while preserving correct exit code. This flag is currently
4545
implemented only for selected subcommands.
4646

4747
[aliases: --silent]
4848

49+
--base-sha <base_sha>
50+
The VCS commit's base sha to use for the upload. If not provided, the merge-base of the
51+
current and remote branch will be used.
52+
4953
--vcs-provider <vcs_provider>
5054
The VCS provider to use for the upload. If not provided, the current provider will be
5155
used.

0 commit comments

Comments
 (0)