Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/content/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cli/
│ │ ├── release/ # archive, create, delete, deploy, deploys, finalize, list, propose-version, restore, set-commits, view
│ │ ├── replay/ # list, view
│ │ ├── repo/ # list
│ │ ├── snapshots/ # download
│ │ ├── sourcemap/ # inject, resolve, upload
│ │ ├── span/ # list, view
│ │ ├── team/ # list
Expand Down
29 changes: 29 additions & 0 deletions docs/src/fragments/commands/snapshots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


## Examples

```bash
# Download a specific baseline snapshot by ID
sentry snapshots download --snapshot-id 1234567890

# Download the latest baseline for an app, filtered by branch
sentry snapshots download --app-id my-app --branch main

# Extract images to a specific directory
sentry snapshots download --app-id my-app --output ./baseline/
```

## Important Notes

- `snapshots download` fetches baseline snapshot images from Sentry's preprod
system and extracts them to a local directory. **Sentry SaaS only.**
- Provide exactly one of `--snapshot-id` (a direct artifact ID) or `--app-id`
(resolves the latest baseline). `--branch` only applies with `--app-id`.
- With org auth tokens, resolving by `--app-id` requires `--project` (a project
ID or slug).
- If the downloadable archive has not been built yet, the command triggers a
build and waits for it (up to 5 minutes).
- Images are extracted to `./snapshots-base/` by default; override with
`--output`.
- The organization is resolved from `--org`, `SENTRY_ORG`, config defaults, or a
detected DSN.
8 changes: 8 additions & 0 deletions plugins/sentry-cli/skills/sentry-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ Work with Sentry cron monitors

→ Full flags and examples: `references/monitor.md`

### Snapshots

Manage and compare snapshots

- `sentry snapshots download` — Download baseline snapshot images

→ Full flags and examples: `references/snapshots.md`

### Sourcemap

Manage sourcemaps
Expand Down
37 changes: 37 additions & 0 deletions plugins/sentry-cli/skills/sentry-cli/references/snapshots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: sentry-cli-snapshots
version: 0.39.0-dev.0
description: Manage and compare snapshots
requires:
bins: ["sentry"]
auth: true
---

# Snapshots Commands

Manage and compare snapshots

### `sentry snapshots download`

Download baseline snapshot images

**Flags:**
- `--app-id <value> - App identifier (e.g. my-app) to resolve the latest baseline; mutually exclusive with --snapshot-id`
- `--snapshot-id <value> - Direct snapshot artifact ID; mutually exclusive with --app-id`
- `--branch <value> - Git branch filter (only with --app-id)`
- `-o, --output <value> - Directory for extracted images (default: ./snapshots-base/)`

**Examples:**

```bash
# Download a specific baseline snapshot by ID
sentry snapshots download --snapshot-id 1234567890

# Download the latest baseline for an app, filtered by branch
sentry snapshots download --app-id my-app --branch main

# Extract images to a specific directory
sentry snapshots download --app-id my-app --output ./baseline/
```

All commands also support `--json`, `--fields`, `--help`, `--log-level`, and `--verbose` flags.
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { listCommand as repoListCommand } from "./commands/repo/list.js";
import { schemaCommand } from "./commands/schema.js";
import { sendEnvelopeCommand } from "./commands/send-envelope.js";
import { sendEventCommand } from "./commands/send-event.js";
import { snapshotsRoute } from "./commands/snapshots/index.js";
import { sourcemapRoute } from "./commands/sourcemap/index.js";
import { spanRoute } from "./commands/span/index.js";
import { listCommand as spanListCommand } from "./commands/span/list.js";
Expand Down Expand Up @@ -117,6 +118,7 @@ export const routes = buildRouteMap({
explore: exploreCommand,
log: logRoute,
monitor: monitorRoute,
snapshots: snapshotsRoute,
sourcemap: sourcemapRoute,
sourcemaps: sourcemapRoute,
span: spanRoute,
Expand Down
230 changes: 230 additions & 0 deletions src/commands/snapshots/download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/**
* sentry snapshots download
*
* Download baseline snapshot images from Sentry's preprod system to a local
* directory. Resolve a snapshot by `--snapshot-id`, or the latest baseline for
* an app via `--app-id` (optionally filtered by `--branch`). Ensures the
* downloadable archive is built (triggering + polling if needed), then extracts
* the images.
*
* Org-scoped. Sentry SaaS only.
*/

import { resolve } from "node:path";
import type { SentryContext } from "../../context.js";
import {
downloadSnapshotArchive,
getLatestBaseSnapshot,
waitForSnapshotArchive,
} from "../../lib/api/preprod-artifacts.js";
import { buildCommand } from "../../lib/command.js";
import { getDefaultProject } from "../../lib/db/defaults.js";
import {
ContextError,
ResolutionError,
ValidationError,
} from "../../lib/errors.js";
import { mdKvTable, renderMarkdown } from "../../lib/formatters/markdown.js";
import { CommandOutput } from "../../lib/formatters/output.js";
import { logger } from "../../lib/logger.js";
import { resolveOrg } from "../../lib/resolve-target.js";
import { extractZipToDir } from "../../lib/snapshots/archive.js";

const log = logger.withTag("snapshots.download");

const USAGE_HINT =
"sentry snapshots download --app-id <app> | --snapshot-id <id>";
const DEFAULT_OUTPUT = "./snapshots-base/";

/** Flags accepted by `snapshots download`. */
type DownloadFlags = {
"app-id"?: string;
"snapshot-id"?: string;
branch?: string;
output?: string;
};

/** Structured result for `snapshots download`. */
type SnapshotDownloadResult = {
/** Organization slug. */
org: string;
/** The resolved snapshot artifact ID. */
snapshotId: string;
/** Local directory the images were extracted to. */
output: string;
/** Number of images extracted. */
imageCount: number;
};

/** Human-readable formatter for the download result. */
function formatDownloadResult(data: SnapshotDownloadResult): string {
return renderMarkdown(
mdKvTable([
["Snapshot ID", data.snapshotId],
["Images", String(data.imageCount)],
["Saved to", data.output],
])
);
}

/**
* Validate the mutually exclusive `--snapshot-id` / `--app-id` flags (and
* `--branch`'s dependency on `--app-id`) before any I/O.
*
* @throws {ValidationError} On conflicting/misused flags.
* @throws {ContextError} When neither ID flag is provided.
*/
function validateSnapshotFlags(flags: DownloadFlags): void {
const appId = flags["app-id"];
const snapshotId = flags["snapshot-id"];

if (appId && snapshotId) {
throw new ValidationError(
"Provide only one of --app-id or --snapshot-id",
"app-id"
);
}
if (flags.branch && !appId) {
throw new ValidationError(
"--branch can only be used with --app-id",
"branch"
);
}
if (!(appId || snapshotId)) {
throw new ContextError("Snapshot", USAGE_HINT, []);
}
}

/**
* Resolve the optional project (for `--app-id` with org auth tokens) from
* `SENTRY_PROJECT` (honoring `<org>/<project>` combo notation) then the
* configured default project.
*/
function resolveOptionalProject(env: NodeJS.ProcessEnv): string | undefined {
const raw = env.SENTRY_PROJECT?.trim();
if (raw) {
const parts = raw.split("/");
return parts.length === 2 ? parts[1] : raw;
}
return getDefaultProject() ?? undefined;
}

/**
* Resolve the snapshot ID to download. Assumes {@link validateSnapshotFlags}
* has run, so exactly one of `--snapshot-id` / `--app-id` is set.
*/
async function resolveSnapshotId(
org: string,
flags: DownloadFlags,
project: string | undefined
): Promise<string> {
const snapshotId = flags["snapshot-id"];
if (snapshotId) {
return snapshotId;
}

const appId = flags["app-id"] as string;
log.info(`Resolving latest baseline snapshot for app '${appId}'...`);
const latest = await getLatestBaseSnapshot(org, appId, {
branch: flags.branch,
project,
});
if (!latest) {
const branchMsg = flags.branch ? ` on branch '${flags.branch}'` : "";
throw new ResolutionError(
`Baseline snapshot for app '${appId}'${branchMsg}`,
"not found",
USAGE_HINT,
["No baseline snapshot exists for this app yet."]
);
}
log.info(
`Found snapshot ${latest.headArtifactId} (${latest.imageCount} images)`
);
return latest.headArtifactId;
}

export const downloadCommand = buildCommand({
docs: {
brief: "Download baseline snapshot images",
fullDescription:
"Download baseline snapshot images from Sentry's preprod system to a " +
"local directory.\n\n" +
"Use --snapshot-id to download a specific snapshot, or --app-id to " +
"resolve the latest baseline (org auth tokens require --project with a " +
"project ID or slug for --app-id).\n\n" +
"This feature only works with Sentry SaaS.\n\n" +
"Usage:\n" +
" sentry snapshots download --snapshot-id 1234567890\n" +
" sentry snapshots download --app-id my-app --branch main\n" +
" sentry snapshots download --app-id my-app --output ./baseline/",
},
output: {
human: formatDownloadResult,
},
parameters: {
flags: {
"app-id": {
kind: "parsed",
parse: String,
brief:
"App identifier (e.g. my-app) to resolve the latest baseline; mutually exclusive with --snapshot-id",
optional: true,
},
"snapshot-id": {
kind: "parsed",
parse: String,
brief: "Direct snapshot artifact ID; mutually exclusive with --app-id",
optional: true,
},
branch: {
kind: "parsed",
parse: String,
brief: "Git branch filter (only with --app-id)",
optional: true,
},
output: {
kind: "parsed",
parse: String,
brief: `Directory for extracted images (default: ${DEFAULT_OUTPUT})`,
optional: true,
},
},
aliases: {
o: "output",
},
},
async *func(this: SentryContext, flags: DownloadFlags) {
// Validate flag combinations before any I/O so bad usage fails fast.
validateSnapshotFlags(flags);

const resolved = await resolveOrg({ cwd: this.cwd });
if (!resolved) {
throw new ContextError("Organization", USAGE_HINT);
}
const { org } = resolved;
const project = resolveOptionalProject(this.env);

const snapshotId = await resolveSnapshotId(org, flags, project);

await waitForSnapshotArchive(org, snapshotId, () =>
log.info("Building snapshot archive...")
);

log.info(`Downloading snapshot ${snapshotId}...`);
const zip = await downloadSnapshotArchive(org, snapshotId);

const output = resolve(this.cwd, flags.output ?? DEFAULT_OUTPUT);
const imageCount = extractZipToDir(zip, output);

yield new CommandOutput<SnapshotDownloadResult>({
org,
snapshotId,
output,
imageCount,
});
return {
hint: `Downloaded ${imageCount} image(s) from snapshot ${snapshotId} to ${output}`,
};
},
});
17 changes: 17 additions & 0 deletions src/commands/snapshots/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* `sentry snapshots` — manage and compare preprod snapshot images.
*
* Currently exposes `download`. `diff` and `upload` are ported separately.
*/

import { buildRouteMap } from "../../lib/route-map.js";
import { downloadCommand } from "./download.js";

export const snapshotsRoute = buildRouteMap({
routes: {
download: downloadCommand,
},
docs: {
brief: "Manage and compare snapshots",
},
});
Loading
Loading