Skip to content

feat(cli): Warm attribute keys for completion on login and setup - #1788

Merged
BYK merged 3 commits into
mainfrom
feat/cli-warm-attribute-completions
Nov 1, 2026
Merged

BYK merged 3 commits into
mainfrom
feat/cli-warm-attribute-completions

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1787.

Field completion (explore --field, dashboard widget --query, alert metrics --aggregate, …) reads attribute keys that, until now, only sentry attribute list fetched. So on a fresh login or install it offered nothing.

Warm-up (src/lib/completion-warmup.ts). auth login and cli setup (which cli upgrade runs) now request the spans, logs and tracemetrics keys in parallel, one request per dataset, and abort them all after 1 second so the command never looks stuck. The fetch layer stores the keys as it already does for every response. The warm-up never throws or prompts, and logs failures (404 without the feature, 403, 5xx, offline, timeout) only at debug level.

  • Which orgs: the default org, then up to 3 orgs used in the last 7 days. "Used" means a project was resolved or entities were listed in that org (project_cache and completion_cache, not counting the warmed attribute kinds themselves). With no default and no history, it warms the only org if the account has exactly one. Only orgs whose region the active account already has cached qualify, so the warm-up never switches accounts or makes a region lookup it can't abort.
  • Login: runs after the result prints and after the org list (which login already fetched in the background), so the account's orgs are known.
  • Setup: runs after its output, only when completions are on and a login is stored (an env token, as in CI, never triggers it). It skips any dataset of an org fetched in the last 24 h, so frequent upgrades don't re-download.

Sentry-defined keys first. The endpoint lists the keys an org stores by internal name, one attribute type after another, and appends a few curated aliases and contexts. In a large org, numeric and vendor keys filled the 500-entry cache before span.*. The attribute seed now stores attributeSource.source_type == "sentry" keys first. That covers stored keys that map to a Sentry definition, which the server tags sentry too (translate_internal_to_public_alias). This also helps attribute list.

listTraceItemAttributes takes an optional signal, which the transport already honors during retries.

Open question: in cli setup, the warm-up can be the first API request in the process. So users with NODE_EXTRA_CA_CERTS pointed at SaaS, or with both SENTRY_AUTH_TOKEN and a stored login, now see that one-time advisory notice during upgrades. They already see it on every other networked command. I left it as is rather than adding hooks to suppress those notices. Happy to add them if we want setup to stay fully silent.

Server-side alternative (not used here): GET /organizations/{org}/attribute-mappings/?type=spans&type=logs&type=tracemetrics already returns the static Sentry-defined set without a Snuba query (src/sentry/api/endpoints/organization_attribute_mappings.py). It's EXPERIMENTAL, though. It also includes secondary and deprecated aliases, leaves out virtual contexts, skips the expose checks, and reports units like millisecond as searchType. So the warm-up keeps using the trace-items endpoint, which also returns the org's own keys. Adding a sourceType filter to trace-items would mostly duplicate it, so no getsentry/sentry issue was filed.

via @BYK.

--

View Session in Sentry

Field completion reads attribute keys that only `sentry attribute list`
fetched until now. `auth login` and `cli setup` (which `cli upgrade`
runs) now request the spans, logs, and tracemetrics keys of the default
org plus up to three orgs used in the last week, in parallel, and abort
after one second. Setup skips datasets fetched in the last day, and with
`--no-completions` or without a stored login.

The attribute seed stores Sentry-defined keys first, so stored keys
sorted by name no longer push `span.*` and other conventions out of the
500-entry cache in large orgs.

Refs #1787

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 1, 2026 7:17pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 1, 2026
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@BYK
BYK enabled auto-merge (squash) November 1, 2026 19:10

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c51cf30. Configure here.

Comment thread packages/cli/src/commands/auth/login.ts Resolved
Comment thread packages/cli/src/commands/cli/setup.ts Resolved
@BYK
BYK merged commit b05681a into main Nov 1, 2026
31 checks passed
@BYK
BYK deleted the feat/cli-warm-attribute-completions branch November 1, 2026 19:31
BYK pushed a commit that referenced this pull request Nov 1, 2026
Follow-up to #1788, addressing [Warden's
finding](#1788 (comment))
that landed after the merge.

On a fresh curl install, `cli setup` warms attribute keys before its
optional auto-login stores a token. That warm-up exits early because no
one is logged in yet. `runInteractiveLogin()` then succeeds without
warming anything, so field completion stays empty on the main
first-install path. The org/region cache is also empty at that point, so
`pickWarmupOrgs()` would find nothing to warm anyway.

The fix:

- Moves `warmCachesAfterLogin()` (list orgs with a 1s cap, then warm
attribute keys) from `auth/login.ts` into `lib/completion-warmup.ts`.
- Calls it from setup after a successful auto-login, unless
`--no-completions` is set. `auth login` behaves the same as before.
- Moves the org-list stall/failure tests to
`test/lib/completion-warmup.test.ts`, next to a success-path test. Adds
setup tests for the auto-login warm-up with completions on and off.

Verified with `oxlint`, `oxfmt --check`, `tsc --noEmit`, and the
`completion-warmup`, `commands/cli`, and `commands/auth` suites (434
passed, 3 skipped).

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A6e7d266c60c8764ce956d19f -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A6e7d266c60c8764ce956d19f/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Preview — 0fc71a02 Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-fetch attribute keys on login and setup for completion

1 participant