Skip to content

DX-2977: identify the cli with Upstash-Telemetry headers - #18

Merged
CahidArda merged 2 commits into
mainfrom
DX-2977-telemetry-headers
Sep 2, 2026
Merged

DX-2977: identify the cli with Upstash-Telemetry headers#18
CahidArda merged 2 commits into
mainfrom
DX-2977-telemetry-headers

Conversation

@CahidArda

Copy link
Copy Markdown
Collaborator

The coordinator cannot tell the cli apart from a raw API-key caller: both send only Basic auth. Send the same Upstash-Telemetry-* trio the JS SDKs and @upstash/mcp-server already send, so requests can be attributed.

Claude-Session: https://claude.ai/code/session_016dGHwYmqdtkQswYYbrgudB

The coordinator cannot tell the cli apart from a raw API-key caller: both
send only Basic auth. Send the same Upstash-Telemetry-* trio the JS SDKs
and @upstash/mcp-server already send, so requests can be attributed.

Claude-Session: https://claude.ai/code/session_016dGHwYmqdtkQswYYbrgudB
@linear-code

linear-code Bot commented Sep 1, 2026

Copy link
Copy Markdown

DX-2977

Adds the opt-out alongside the headers themselves, following what the
other Upstash SDKs and comparable CLIs do:

  upstash telemetry disable | enable | status   persisted, as with
                                                `vercel telemetry disable`
                                                and `fly settings analytics`
  UPSTASH_DISABLE_TELEMETRY=1                   read by redis-js, qstash-js,
                                                vector-js and the rest

The env var beats the saved preference, so a CI job opts out without
writing config.

The headers are now resolved per request instead of at import. `cli.ts`
calls dotenv only after the module graph is evaluated, so a value read at
import time would miss a `.env` file.

The saved preference lives beside the credentials in config.json, so
`writeConfig` merges rather than overwrites and `deleteConfig` keeps the
preference behind: logging out must not quietly turn telemetry back on.
It also now reports whether credentials were actually removed, so logout
does not claim one when only the preference was stored.

Claude-Session: https://claude.ai/code/session_016dGHwYmqdtkQswYYbrgudB

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

deleteConfig() can leave legacy ~/.upstash.json credentials on disk (especially after writing a telemetry-only new config), causing logout to report no credentials while not actually logging the user out.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds opt-out telemetry identification so Upstash can distinguish the CLI from raw API-key callers by attaching the same Upstash-Telemetry-* headers used by other Upstash SDKs, plus a CLI command and documentation for managing the setting.

Changes:

  • Add src/telemetry.ts to compute the Upstash-Telemetry-Sdk/Runtime/Platform headers and honor UPSTASH_DISABLE_TELEMETRY plus a persisted preference.
  • Persist telemetry_disabled alongside credentials in the config file and introduce upstash telemetry {status,enable,disable}.
  • Extend the HTTP client to attach telemetry headers, with unit tests and README documentation.
File summaries
File Description
tests/unit/telemetry.test.ts New unit tests for telemetry status/headers and persistence behavior.
tests/unit/client.test.ts New unit test asserting requests include the telemetry header trio.
src/telemetry.ts Implements telemetry status resolution and header construction.
src/config.ts Stores/reads telemetry_disabled in config; preserves preference across login/logout.
src/commands/telemetry.ts Adds upstash telemetry command group to manage the preference.
src/client.ts Adds telemetry headers to every API request.
src/cli.ts Registers the new telemetry command with the main CLI program.
README.md Documents what telemetry headers are sent and how to disable/enable them.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/config.ts
Comment on lines 100 to +110
export function deleteConfig(): boolean {
const path = getConfigPath();
if (!existsSync(path)) return false;
rmSync(path);
return true;
const existing = readRawConfig(path);
if (!existing) return false;
const hadCredentials = Boolean(existing.email && (existing.api_key ?? existing.apiKey));
if (existing.telemetry_disabled === undefined) {
rmSync(path);
} else {
writeStoredConfig({ telemetry_disabled: existing.telemetry_disabled });
}
return hadCredentials;
expect(deleteConfig()).toBe(false);
});

it("keeps the config file readable only by the owner", async () => {
@CahidArda
CahidArda merged commit 1a40bf5 into main Sep 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants