Agent Guidance
Best practices and operational guidance for AI coding agents using the Sentry CLI.
Key Principles
Section titled “Key Principles”- Just run the command — the CLI handles authentication and org/project detection automatically. Don't pre-authenticate or look up org/project before running commands. The CLI prompts for login if needed.
- Prefer CLI commands over raw API calls — the CLI has dedicated commands for most tasks. Reach for
sentry issue view,sentry issue list,sentry trace view, etc. before constructing API calls manually or fetching external documentation. - Use
sentry schemato explore the API — if you need to discover API endpoints, runsentry schemato browse interactively orsentry schema <resource>to search. This is faster than fetching OpenAPI specs externally. - Use
sentry issue view <id>to investigate issues — when asked about a specific issue (e.g.,CLI-G5,PROJECT-123), usesentry issue viewdirectly. - Use
--jsonfor machine-readable output — pipe throughjqfor filtering. Human-readable output includes formatting that is hard to parse. - The CLI auto-detects org/project — don't discover it yourself — most commands work without explicit targets by checking
.sentryclircconfig files, scanning for DSNs in.envfiles and source code, and matching directory names. Do not runsentry org listand thensentry project listto figure out which project this checkout belongs to — that manual fan-out just replicates the detection the CLI already runs on every command. Only specify<org>/<project>when the CLI reports it can't detect the target or detects the wrong one.
Design Principles
Section titled “Design Principles”The sentry CLI follows conventions from well-known tools — if you're familiar with them, that knowledge transfers directly:
gh(GitHub CLI) conventions: ThesentryCLI uses the same<noun> <verb>command pattern (e.g.,sentry issue list,sentry org view). Flags followghconventions:--jsonfor machine-readable output,--fieldsto select specific fields,-w/--webto open in browser,-q/--queryfor filtering,-n/--limitfor result count.sentry apimimicscurl: Thesentry apicommand provides direct API access with acurl-like interface —--methodfor HTTP method,--datafor request body,--headerfor custom headers. It handles authentication automatically. If you know how to call a REST API withcurl, the same patterns apply.
Context Window Tips
Section titled “Context Window Tips”- Use
--json --fieldsto select specific fields and reduce output size. Run<command> --helpto see available fields. Example:sentry issue list --json --fields shortId,title,priority,level,status - Use
--jsonwhen piping output between commands or processing programmatically - Use
--limitto cap the number of results (default is usually 10–100) - Prefer
sentry issue view PROJECT-123over listing and filtering manually - Use
sentry apifor endpoints not covered by dedicated commands
Safety Rules
Section titled “Safety Rules”- Always confirm with the user before running destructive commands:
project delete,trial start - For mutations, verify the org/project context looks correct in the command output before proceeding with further changes
- Never store or log authentication tokens — the CLI manages credentials automatically
- If the CLI reports the wrong org/project, override with explicit
<org>/<project>arguments
Exit Codes
Section titled “Exit Codes”The CLI uses semantic exit codes. Key ranges for agents:
| Range | Meaning | Agent Action |
|---|---|---|
| 0 | Success | Proceed normally |
| 10–19 | Auth error | Prompt user to run sentry auth login |
| 20–29 | Input error | Check command arguments and retry |
| 30–39 | API error | Retry or report to user |
| 40–49 | Feature unavailable | Inform user about plan/settings |
| 50–59 | Operation error | Report to user |
| 60–69 | Command-specific | Check stderr for details |
See Exit Codes for the complete reference.
Workflow Patterns
Section titled “Workflow Patterns”Investigate an Issue
Section titled “Investigate an Issue”# 1. Find the issue (auto-detects org/project from DSN or config)sentry issue list --query "is:unresolved" --limit 5
# 2. Get details. For agents, prefer --json — it includes the full issue plus# the latest event under `event`, so you get everything in one call.sentry issue view PROJECT-123 --json
# 3. Get AI root cause analysissentry issue explain PROJECT-123
# 4. Get a fix plansentry issue plan PROJECT-123sentry issue view <SHORT-ID> --json is the fastest way to get an agent up to
speed on an issue. Select just the fields you need with --fields instead of
consuming the whole payload — the latest event's request entry can carry live
session data (cookies, headers, body), so extract named fields rather than
dumping the entire object:
# Top-level issue fieldssentry issue view PROJECT-123 --json --fields shortId,title,culprit,count,userCount,permalink
# Named fields from the latest event — avoids pulling the full request/session blobsentry issue view PROJECT-123 --json --fields event.id,event.title,event.dateCreated
# Just the request URL and method (not the whole request entry). Event data# lives under event.entries[], each tagged with a `type` and `data` payload.sentry issue view PROJECT-123 --json | jq '.event.entries[] | select(.type == "request") | .data | {url, method}'Explore Traces and Performance
Section titled “Explore Traces and Performance”# 1. List recent traces (auto-detects org/project)sentry trace list --limit 5
# 2. View a specific trace with span treesentry trace view abc123def456...
# 3. View spans for a tracesentry span list abc123def456...
# 4. View logs associated with a tracesentry trace logs abc123def456...Stream Logs
Section titled “Stream Logs”# Stream logs in real-time (auto-detects org/project)sentry log list --follow
# Filter logs by severitysentry log list --query "severity:error"Capture Events Locally (Spotlight)
Section titled “Capture Events Locally (Spotlight)”# Run the app with the local server auto-enabled; tail errors/traces/logs.# No DSN needed — with no DSN, events go ONLY to the local server (nothing# reaches the user's Sentry org, no production quota). With a DSN set, the# SDK sends to both.sentry local run -- npm run dev # or: python manage.py runserver, etc.
# Watch only AI/agent (gen_ai, mcp) spans while iterating on an agent.sentry local -f ai
# Server-side SDKs read SENTRY_SPOTLIGHT automatically. The CLI also injects# the URL under every framework client prefix (NEXT_PUBLIC_, VITE_, PUBLIC_,# NUXT_PUBLIC_, REACT_APP_, VUE_APP_, GATSBY_). Until the browser SDK reads# these automatically (getsentry/sentry-javascript#18198), reference the var# matching your framework in the client config:# Sentry.init({ spotlight: process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT ?? false })Explore the API Schema
Section titled “Explore the API Schema”# Browse all API resource categoriessentry schema
# Search for endpoints related to a resourcesentry schema issues
# Get details about a specific endpointsentry schema "GET /api/0/organizations/{organization_id_or_slug}/issues/"Manage Releases
Section titled “Manage Releases”# Create a release — version must match Sentry.init({ release }) exactlysentry release create my-org/1.0.0 --project my-project
# Associate commits via repository integration (needs local git checkout)sentry release set-commits my-org/1.0.0 --auto
# Or read commits from local git history (no integration needed)sentry release set-commits my-org/1.0.0 --local
# Mark the release as finalizedsentry release finalize my-org/1.0.0
# Record a production deploysentry release deploy my-org/1.0.0 productionKey details:
- The positional is
<org-slug>/<version>. Insentry release create sentry/1.0.0,sentryis the org and1.0.0is the version — the slash separates org from version, it is not part of the version string. - The version must match the
releasevalue inSentry.init(). If your SDK uses"1.0.0", the command must useorg/1.0.0. --autorequires a Sentry repository integration (GitHub/GitLab/Bitbucket) and a local git checkout. It matches youroriginremote against Sentry's repo list. Without a checkout, use--local.- With no flag,
set-commitstries--autofirst and falls back to--localon failure.
Arbitrary API Access
Section titled “Arbitrary API Access”# GET request (default)sentry api /api/0/organizations/my-org/
# POST request with datasentry api /api/0/organizations/my-org/projects/ --method POST --data '{"name":"new-project","platform":"python"}'Dashboard Layout
Section titled “Dashboard Layout”Sentry dashboards use a 6-column grid. When adding widgets, aim to fill complete rows (widths should sum to 6).
Display types with default sizes:
| Display Type | Width | Height | Category | Notes |
|---|---|---|---|---|
big_number |
2 | 1 | common | Compact KPI — place 3 per row (2+2+2=6) |
line |
3 | 2 | common | Half-width chart — place 2 per row (3+3=6) |
area |
3 | 2 | common | Half-width chart — place 2 per row |
bar |
3 | 2 | common | Half-width chart — place 2 per row |
table |
6 | 2 | common | Full-width — always takes its own row |
stacked_area |
3 | 2 | specialized | Stacked area chart |
top_n |
3 | 2 | specialized | Top N ranked list |
categorical_bar |
3 | 2 | specialized | Categorical bar chart |
text |
3 | 2 | specialized | Static text/markdown widget |
details |
3 | 2 | internal | Detail view |
wheel |
3 | 2 | internal | Pie/wheel chart |
rage_and_dead_clicks |
3 | 2 | internal | Rage/dead click visualization |
server_tree |
3 | 2 | internal | Hierarchical tree display |
agents_traces_table |
3 | 2 | internal | Agents traces table |
Use common types for general dashboards. Use specialized only when specifically requested. Avoid internal types unless the user explicitly asks.
Available datasets: spans (default), errors, transactions, metrics, issue, logs. Run sentry dashboard widget --help for dataset descriptions, query formats, and examples.
Row-filling examples:
# 3 KPIs filling one row (2+2+2 = 6)sentry dashboard widget add <dashboard> "Error Count" --display big_number --query countsentry dashboard widget add <dashboard> "P95 Duration" --display big_number --query p95:span.durationsentry dashboard widget add <dashboard> "Throughput" --display big_number --query epm
# 2 charts filling one row (3+3 = 6)sentry dashboard widget add <dashboard> "Errors Over Time" --display line --query countsentry dashboard widget add <dashboard> "Latency Over Time" --display line --query p95:span.duration
# Full-width table (6 = 6)sentry dashboard widget add <dashboard> "Top Endpoints" --display table \ --query count --query p95:span.duration \ --group-by transaction --sort -count --limit 10Quick Reference
Section titled “Quick Reference”Time filtering
Section titled “Time filtering”Use --period (alias: -t) to filter by time window:
sentry trace list --period 1hsentry span list --period 24hsentry span list -t 7dScoping to an org or project
Section titled “Scoping to an org or project”Org and project are positional arguments following gh CLI conventions:
sentry trace list my-org/my-projectsentry issue list my-org/my-projectsentry span list my-org/my-project/abc123def456...Listing spans in a trace
Section titled “Listing spans in a trace”Pass the trace ID as a positional argument to span list:
sentry span list abc123def456...sentry span list my-org/my-project/abc123def456...Dataset names for the Events API
Section titled “Dataset names for the Events API”When querying the Events API (directly or via sentry api), valid dataset values are: spans, logs, errors, tracemetrics, profile_functions, and uptime_results.
Common Mistakes
Section titled “Common Mistakes”- Wrong issue ID format: Use
PROJECT-123(short ID), not the numeric ID123456789. The short ID includes the project prefix. - Pre-authenticating unnecessarily: Don't run
sentry auth loginbefore every command. The CLI detects missing/expired auth and prompts automatically. Only runsentry auth loginif you need to switch accounts. - Missing
--jsonfor piping: Human-readable output includes formatting. Use--jsonwhen parsing output programmatically. - Specifying org/project when not needed: Auto-detection resolves org/project from
.sentryclircconfig files, DSNs, env vars, and directory names. Let it work first — only add<org>/<project>if the CLI says it can't detect the target or detects the wrong one. - Manually discovering the project before running a command: Don't list the orgs you belong to, then list every project in each, to match the local checkout to a project — the CLI already does exactly this resolution internally on each command. Skip the fan-out and run the command directly; correct the target afterwards only if the output shows the wrong org/project.
- Confusing
--querysyntax: The--queryflag uses Sentry search syntax (e.g.,is:unresolved,assigned:me), not free text search. - Not using
--web: View commands support-w/--webto open the resource in the browser — useful for sharing links. - Fetching API schemas instead of using the CLI: Prefer
sentry schemato browse the API andsentry apito make requests — the CLI handles authentication and endpoint resolution, so there's rarely a need to download OpenAPI specs separately. - Release version mismatch: The
org/versionpositional is<org-slug>/<version>, whereorg/is the org, not part of the version.sentry release create sentry/1.0.0creates version1.0.0in orgsentry. If yourSentry.init()usesrelease: "1.0.0", this is correct. Don't double-prefix likesentry/myapp/1.0.0. - Running
set-commits --autowithout a git checkout:--autoneeds a local git repo to discover the origin remote URL and HEAD commit. In CI, ensureactions/checkoutwithfetch-depth: 0runs beforeset-commits --auto. - Using
sentry apiwhen CLI commands suffice:sentry issue list --jsonandsentry issue view --jsonalready includeshortId,title,count,userCount,priority,level,status,permalink, and other fields at the top level. When using--fieldsto select specific fields likecountoruserCount, the CLI automatically ensures these fields are present in the API response. Use--fieldsto select specific fields and--helpto see all available fields. Only fall back tosentry apifor data the CLI doesn't expose.