From 32981480f4a2d48184e9fabec9b8609467471f3e Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Sat, 5 Dec 2026 08:18:32 +0000 Subject: [PATCH 1/4] fix(cli): Opt out of telemetry for any truthy DO_NOT_TRACK or SENTRY_CLI_NO_TELEMETRY Both variables opted out only for the exact value `1`, so `DO_NOT_TRACK=true` still sent telemetry. They now opt out for any value except an empty or false-like one (`0`, `false`, `no`, `off`), read by a shared `isEnvFlagSet()` that the wizard's `SENTRY_SPOTLIGHT` check already used inline. A false-like value doesn't opt in: the next source in the precedence still decides. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- TELEMETRY.md | 2 +- .../src/content/docs/migrating-from-v3.md | 4 +- apps/cli-docs/src/fragments/configuration.md | 2 +- packages/cli/src/commands/wizard.ts | 5 +- packages/cli/src/lib/env-registry.ts | 4 +- packages/cli/src/lib/parse-bool.ts | 12 +++ packages/cli/src/lib/telemetry.ts | 19 ++-- .../cli/test/commands/cli/defaults.test.ts | 86 +++++++++++++++++++ 8 files changed, 119 insertions(+), 15 deletions(-) diff --git a/TELEMETRY.md b/TELEMETRY.md index cf8f08e881..e4f38d9950 100644 --- a/TELEMETRY.md +++ b/TELEMETRY.md @@ -308,7 +308,7 @@ Attributes: `gen_ai.provider.name`, `gen_ai.request.model`, | ------------------------- | -------------------------------------------- | --------------------------------------- | | `VITE_SENTRY_DSN` | Cloudflare Sentry telemetry | disabled when unset | | `VITE_SENTRY_ENVIRONMENT` | Cloudflare Sentry environment | development | -| `SENTRY_CLI_NO_TELEMETRY` | stdio telemetry off when `1` | on, to the CLI's project | +| `SENTRY_CLI_NO_TELEMETRY` | stdio telemetry off when set, as in the CLI | on, to the CLI's project | | `SENTRY_RELEASE` | stdio release tag | unset | | `SENTRY_HOST` | upstream Sentry host and `app.upstream.host` | `sentry.io` | | `NODE_ENV` | stdio environment | production fallback in packaged runtime | diff --git a/apps/cli-docs/src/content/docs/migrating-from-v3.md b/apps/cli-docs/src/content/docs/migrating-from-v3.md index e7ef14d644..809e371331 100644 --- a/apps/cli-docs/src/content/docs/migrating-from-v3.md +++ b/apps/cli-docs/src/content/docs/migrating-from-v3.md @@ -808,7 +808,9 @@ Otherwise the command stops with exit code 13 before sending any request. v4 sends usage data and error reports about the CLI itself to Sentry. To opt out, set `SENTRY_CLI_NO_TELEMETRY=1` or `DO_NOT_TRACK=1`, or run -`sentry cli defaults telemetry off`. +`sentry cli defaults telemetry off`. Either variable opts out with any value +except an empty or false-like one (`0`, `false`, `no`, `off`), so +`DO_NOT_TRACK=true` works too. ## Getting help diff --git a/apps/cli-docs/src/fragments/configuration.md b/apps/cli-docs/src/fragments/configuration.md index 3c99d703b5..db4405b2c2 100644 --- a/apps/cli-docs/src/fragments/configuration.md +++ b/apps/cli-docs/src/fragments/configuration.md @@ -98,7 +98,7 @@ Hints print below the output only on a terminal. When stdout is piped or redirec ## Telemetry -The CLI sends usage data and error reports about itself to Sentry. To opt out, set `SENTRY_CLI_NO_TELEMETRY=1` or `DO_NOT_TRACK=1`, or run `sentry cli defaults telemetry off`. +The CLI sends usage data and error reports about itself to Sentry. To opt out, set `SENTRY_CLI_NO_TELEMETRY=1` or `DO_NOT_TRACK=1`, or run `sentry cli defaults telemetry off`. Either variable opts out with any value except an empty or false-like one (`0`, `false`, `no`, `off`), so `DO_NOT_TRACK=true` works too. When telemetry can't be sent, for example while offline or when a firewall blocks Sentry, the CLI keeps it in its local database and sends up to 10 stored envelopes on each later run. The cache holds at most 100 envelopes and 4 MiB, compressed. When it's full, the oldest usage data goes first, then the oldest error reports. It discards error reports after 30 days and everything else after 4 days. Metrics, such as timings, aren't cached: when they can't be sent, they're dropped. diff --git a/packages/cli/src/commands/wizard.ts b/packages/cli/src/commands/wizard.ts index 21db0e455d..60d2201126 100644 --- a/packages/cli/src/commands/wizard.ts +++ b/packages/cli/src/commands/wizard.ts @@ -20,7 +20,7 @@ import { buildCommand } from "../lib/command.js"; import { ORG_PROJECT_TARGET, parseText } from "../lib/completion-target.js"; import { getEnv } from "../lib/env.js"; import { ValidationError, WizardExitError } from "../lib/errors.js"; -import { parseBoolValue } from "../lib/parse-bool.js"; +import { isEnvFlagSet } from "../lib/parse-bool.js"; import { type BoundArguments, boundArguments, @@ -175,8 +175,7 @@ export function parseWizardArguments(args: readonly string[]): WizardInput { * including a Spotlight URL. */ function isSpotlightEnabled(): boolean { - const value = getEnv()["SENTRY_SPOTLIGHT"]?.trim(); - return value ? parseBoolValue(value) !== false : false; + return isEnvFlagSet(getEnv()["SENTRY_SPOTLIGHT"]); } export const wizardCommand = buildCommand({ diff --git a/packages/cli/src/lib/env-registry.ts b/packages/cli/src/lib/env-registry.ts index d2b3d84a74..4dcf3f2b7a 100644 --- a/packages/cli/src/lib/env-registry.ts +++ b/packages/cli/src/lib/env-registry.ts @@ -306,14 +306,14 @@ export const ENV_VAR_REGISTRY: readonly EnvVarEntry[] = [ { name: "SENTRY_CLI_NO_TELEMETRY", description: - "Disable CLI telemetry (error tracking for the CLI itself). The CLI sends anonymized error reports to help improve reliability — set this to opt out.", + "Disable CLI telemetry (error tracking for the CLI itself). The CLI sends anonymized error reports to help improve reliability — set this to opt out.\n\nAny value turns telemetry off (`1`, `true`, `yes`, `on`) except an empty or false-like one (`0`, `false`, `no`, `off`). A false-like value doesn't turn telemetry on: `DO_NOT_TRACK` and `sentry cli defaults telemetry` still apply.", example: "1", devGuide: "Disable CLI telemetry (error tracking)", }, { name: "DO_NOT_TRACK", description: - "Industry-standard opt-out for telemetry. When set to `1`, the CLI disables all telemetry, equivalent to `SENTRY_CLI_NO_TELEMETRY=1`.", + "Industry-standard opt-out for telemetry. When set, the CLI disables all telemetry, equivalent to `SENTRY_CLI_NO_TELEMETRY=1`. It reads values the same way as `SENTRY_CLI_NO_TELEMETRY`: `1`, `true`, or any other value opts out, but an empty or false-like value (`0`, `false`, `no`, `off`) doesn't.", example: "1", }, { diff --git a/packages/cli/src/lib/parse-bool.ts b/packages/cli/src/lib/parse-bool.ts index 986c8709a9..3409869908 100644 --- a/packages/cli/src/lib/parse-bool.ts +++ b/packages/cli/src/lib/parse-bool.ts @@ -33,3 +33,15 @@ export function parseBoolValue(input: string): boolean | null { return null; } + +/** + * Whether an environment flag is on. Like the Sentry SDKs, any value counts + * except an empty or false-like one (`0`, `false`, `no`, `off`, …; see + * {@link parseBoolValue}), so `1`, `true`, `yes`, and a URL all turn it on. + * + * @param value - Raw environment value, or `undefined` when unset + */ +export function isEnvFlagSet(value: string | undefined): boolean { + const trimmed = value?.trim(); + return trimmed ? parseBoolValue(trimmed) !== false : false; +} diff --git a/packages/cli/src/lib/telemetry.ts b/packages/cli/src/lib/telemetry.ts index 09af0431c4..aa41970f53 100644 --- a/packages/cli/src/lib/telemetry.ts +++ b/packages/cli/src/lib/telemetry.ts @@ -58,6 +58,7 @@ import { } from "./telemetry/offline-transport.js"; import { makeCompressedTransport } from "./telemetry/zstd-transport.js"; import { omitUndefined } from "./omit-undefined.js"; +import { isEnvFlagSet } from "./parse-bool.js"; export type { Span } from "@sentry/core"; @@ -114,7 +115,7 @@ export function markSessionCrashed(): void { } } -/** Env var that disables CLI telemetry when set to `"1"`. */ +/** Env var that disables CLI telemetry when set (see {@link isEnvFlagSet}). */ export const TELEMETRY_ENV_VAR = "SENTRY_CLI_NO_TELEMETRY"; /** Industry-standard env var for opting out of telemetry. */ @@ -138,20 +139,24 @@ export type TelemetryEffective = { * Resolve the effective telemetry state with source attribution. * * Priority (highest to lowest): - * 1. `SENTRY_CLI_NO_TELEMETRY=1` — explicit CLI env var opt-out - * 2. `DO_NOT_TRACK=1` — industry-standard opt-out + * 1. `SENTRY_CLI_NO_TELEMETRY` — explicit CLI env var opt-out + * 2. `DO_NOT_TRACK` — industry-standard opt-out * 3. SQLite persistent preference — `sentry cli defaults telemetry on/off` * 4. Default: enabled * + * An env var opts out when it holds any value but an empty or false-like one + * ({@link isEnvFlagSet}). A false-like value such as `0` does not opt out, + * but it does not opt in either: the next source still decides. + * * The DB read is wrapped in try/catch — if the database is uninitialized * or corrupted, we fall through to the default (enabled). */ export function computeTelemetryEffective(): TelemetryEffective { - if (getEnv()[TELEMETRY_ENV_VAR] === "1") { + if (isEnvFlagSet(getEnv()[TELEMETRY_ENV_VAR])) { return { enabled: false, source: `env:${TELEMETRY_ENV_VAR}` }; } - if (getEnv()[DO_NOT_TRACK_ENV_VAR] === "1") { + if (isEnvFlagSet(getEnv()[DO_NOT_TRACK_ENV_VAR])) { return { enabled: false, source: `env:${DO_NOT_TRACK_ENV_VAR}` }; } @@ -213,8 +218,8 @@ export function scrubAnonymousMetric(metric: Metric): Metric { * paths that bypass this function's try/catch. * * Telemetry can be disabled via: - * - `SENTRY_CLI_NO_TELEMETRY=1` environment variable - * - `DO_NOT_TRACK=1` environment variable + * - `SENTRY_CLI_NO_TELEMETRY` environment variable (`1`, `true`, ...) + * - `DO_NOT_TRACK` environment variable (`1`, `true`, ...) * - `sentry cli defaults telemetry off` (persistent preference) * * @param callback - The CLI execution function to wrap, receives the span for naming diff --git a/packages/cli/test/commands/cli/defaults.test.ts b/packages/cli/test/commands/cli/defaults.test.ts index 7239e6fd99..98624ee42c 100644 --- a/packages/cli/test/commands/cli/defaults.test.ts +++ b/packages/cli/test/commands/cli/defaults.test.ts @@ -369,6 +369,92 @@ describe("computeTelemetryEffective", () => { teardown(); } }); + + const optOutVars = ["SENTRY_CLI_NO_TELEMETRY", "DO_NOT_TRACK"]; + + test.each( + optOutVars.flatMap((name) => + ["1", "true", "TRUE", "yes", " on "].map((value) => [name, value]), + ), + )("%s=%j opts out", (name, value) => { + setup(); + try { + process.env[name] = value; + expect(computeTelemetryEffective()).toEqual({ + enabled: false, + source: `env:${name}`, + }); + } finally { + teardown(); + } + }); + + test.each( + optOutVars.flatMap((name) => + ["0", "false", "FALSE", "no", "off", "", " "].map((value) => [ + name, + value, + ]), + ), + )("%s=%j does not opt out, so the preference applies", (name, value) => { + setup(); + try { + setOnOffPreference("telemetry", false); + process.env[name] = value; + expect(computeTelemetryEffective()).toEqual({ + enabled: false, + source: "preference", + }); + setOnOffPreference("telemetry", true); + expect(computeTelemetryEffective()).toEqual({ + enabled: true, + source: "preference", + }); + } finally { + teardown(); + } + }); + + test("SENTRY_CLI_NO_TELEMETRY=0 falls through to DO_NOT_TRACK", () => { + setup(); + try { + process.env["SENTRY_CLI_NO_TELEMETRY"] = "0"; + process.env["DO_NOT_TRACK"] = "true"; + expect(computeTelemetryEffective()).toEqual({ + enabled: false, + source: "env:DO_NOT_TRACK", + }); + } finally { + teardown(); + } + }); + + test("SENTRY_CLI_NO_TELEMETRY wins over DO_NOT_TRACK as the source", () => { + setup(); + try { + process.env["SENTRY_CLI_NO_TELEMETRY"] = "yes"; + process.env["DO_NOT_TRACK"] = "true"; + expect(computeTelemetryEffective().source).toBe( + "env:SENTRY_CLI_NO_TELEMETRY", + ); + } finally { + teardown(); + } + }); + + test("false-like env values with no preference leave the default on", () => { + setup(); + try { + process.env["SENTRY_CLI_NO_TELEMETRY"] = "false"; + process.env["DO_NOT_TRACK"] = "0"; + expect(computeTelemetryEffective()).toEqual({ + enabled: true, + source: "default", + }); + } finally { + teardown(); + } + }); }); // --------------------------------------------------------------------------- From 814582da24f923a2194b3d6bd5bb594a32503b2c Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Sat, 5 Dec 2026 08:21:10 +0000 Subject: [PATCH 2/4] ref(cli): Read telemetry opt-outs with the SDK's envToBool Use `envToBool` from `@sentry/core` for SENTRY_CLI_NO_TELEMETRY and DO_NOT_TRACK instead of a new `isEnvFlagSet()` helper. In loose mode it already returns false for empty and false-like values and true for any other value, which is the opt-out rule. Drops the helper and the wizard change that came with it. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- packages/cli/src/commands/wizard.ts | 5 +++-- packages/cli/src/lib/parse-bool.ts | 12 ------------ packages/cli/src/lib/telemetry.ts | 15 +++++++-------- packages/cli/test/commands/cli/defaults.test.ts | 7 ++----- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/packages/cli/src/commands/wizard.ts b/packages/cli/src/commands/wizard.ts index 60d2201126..21db0e455d 100644 --- a/packages/cli/src/commands/wizard.ts +++ b/packages/cli/src/commands/wizard.ts @@ -20,7 +20,7 @@ import { buildCommand } from "../lib/command.js"; import { ORG_PROJECT_TARGET, parseText } from "../lib/completion-target.js"; import { getEnv } from "../lib/env.js"; import { ValidationError, WizardExitError } from "../lib/errors.js"; -import { isEnvFlagSet } from "../lib/parse-bool.js"; +import { parseBoolValue } from "../lib/parse-bool.js"; import { type BoundArguments, boundArguments, @@ -175,7 +175,8 @@ export function parseWizardArguments(args: readonly string[]): WizardInput { * including a Spotlight URL. */ function isSpotlightEnabled(): boolean { - return isEnvFlagSet(getEnv()["SENTRY_SPOTLIGHT"]); + const value = getEnv()["SENTRY_SPOTLIGHT"]?.trim(); + return value ? parseBoolValue(value) !== false : false; } export const wizardCommand = buildCommand({ diff --git a/packages/cli/src/lib/parse-bool.ts b/packages/cli/src/lib/parse-bool.ts index 3409869908..986c8709a9 100644 --- a/packages/cli/src/lib/parse-bool.ts +++ b/packages/cli/src/lib/parse-bool.ts @@ -33,15 +33,3 @@ export function parseBoolValue(input: string): boolean | null { return null; } - -/** - * Whether an environment flag is on. Like the Sentry SDKs, any value counts - * except an empty or false-like one (`0`, `false`, `no`, `off`, …; see - * {@link parseBoolValue}), so `1`, `true`, `yes`, and a URL all turn it on. - * - * @param value - Raw environment value, or `undefined` when unset - */ -export function isEnvFlagSet(value: string | undefined): boolean { - const trimmed = value?.trim(); - return trimmed ? parseBoolValue(trimmed) !== false : false; -} diff --git a/packages/cli/src/lib/telemetry.ts b/packages/cli/src/lib/telemetry.ts index aa41970f53..70ee5f1f01 100644 --- a/packages/cli/src/lib/telemetry.ts +++ b/packages/cli/src/lib/telemetry.ts @@ -11,7 +11,7 @@ import { createRequire } from "node:module"; import { API_BASE_PATH } from "@sentry/api"; -import type { Metric, TransactionEvent } from "@sentry/core"; +import { envToBool, type Metric, type TransactionEvent } from "@sentry/core"; // oxlint-disable-next-line sentry-cli/no-namespace-import -- Sentry SDK recommends namespace import import * as Sentry from "@sentry/node"; @@ -58,7 +58,6 @@ import { } from "./telemetry/offline-transport.js"; import { makeCompressedTransport } from "./telemetry/zstd-transport.js"; import { omitUndefined } from "./omit-undefined.js"; -import { isEnvFlagSet } from "./parse-bool.js"; export type { Span } from "@sentry/core"; @@ -115,7 +114,7 @@ export function markSessionCrashed(): void { } } -/** Env var that disables CLI telemetry when set (see {@link isEnvFlagSet}). */ +/** Env var that disables CLI telemetry (see {@link computeTelemetryEffective}). */ export const TELEMETRY_ENV_VAR = "SENTRY_CLI_NO_TELEMETRY"; /** Industry-standard env var for opting out of telemetry. */ @@ -144,19 +143,19 @@ export type TelemetryEffective = { * 3. SQLite persistent preference — `sentry cli defaults telemetry on/off` * 4. Default: enabled * - * An env var opts out when it holds any value but an empty or false-like one - * ({@link isEnvFlagSet}). A false-like value such as `0` does not opt out, - * but it does not opt in either: the next source still decides. + * An env var opts out when the SDK's `envToBool` reads it as true: any value + * but an empty or false-like one (`0`, `false`, `no`, `off`, `f`, `n`, any + * case). A false-like value does not opt in either: the next source decides. * * The DB read is wrapped in try/catch — if the database is uninitialized * or corrupted, we fall through to the default (enabled). */ export function computeTelemetryEffective(): TelemetryEffective { - if (isEnvFlagSet(getEnv()[TELEMETRY_ENV_VAR])) { + if (envToBool(getEnv()[TELEMETRY_ENV_VAR])) { return { enabled: false, source: `env:${TELEMETRY_ENV_VAR}` }; } - if (isEnvFlagSet(getEnv()[DO_NOT_TRACK_ENV_VAR])) { + if (envToBool(getEnv()[DO_NOT_TRACK_ENV_VAR])) { return { enabled: false, source: `env:${DO_NOT_TRACK_ENV_VAR}` }; } diff --git a/packages/cli/test/commands/cli/defaults.test.ts b/packages/cli/test/commands/cli/defaults.test.ts index 98624ee42c..7b0bc6afc4 100644 --- a/packages/cli/test/commands/cli/defaults.test.ts +++ b/packages/cli/test/commands/cli/defaults.test.ts @@ -374,7 +374,7 @@ describe("computeTelemetryEffective", () => { test.each( optOutVars.flatMap((name) => - ["1", "true", "TRUE", "yes", " on "].map((value) => [name, value]), + ["1", "true", "TRUE", "yes", "on"].map((value) => [name, value]), ), )("%s=%j opts out", (name, value) => { setup(); @@ -391,10 +391,7 @@ describe("computeTelemetryEffective", () => { test.each( optOutVars.flatMap((name) => - ["0", "false", "FALSE", "no", "off", "", " "].map((value) => [ - name, - value, - ]), + ["0", "false", "FALSE", "no", "off", ""].map((value) => [name, value]), ), )("%s=%j does not opt out, so the preference applies", (name, value) => { setup(); From 0300d263d73a0dbdfe2c815c87759ace03d89381 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Sat, 5 Dec 2026 08:25:40 +0000 Subject: [PATCH 3/4] fix(cli): Honor truthy telemetry opt-outs and DO_NOT_TRACK in the installers `install` and `install.ps1` skipped their error reports only for SENTRY_CLI_NO_TELEMETRY=1 and ignored DO_NOT_TRACK. Both now skip them when either variable holds any value except an empty or false-like one (0, false, f, n, no, off, any case), the same values the CLI reads. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- .../src/content/docs/getting-started.mdx | 3 +- packages/cli/install | 17 ++++++++-- packages/cli/install.ps1 | 10 +++++- .../cli/test/lib/install-ps1-script.test.ts | 32 +++++++++++++++++ packages/cli/test/lib/install-script.test.ts | 34 +++++++++++++++++++ 5 files changed, 92 insertions(+), 4 deletions(-) diff --git a/apps/cli-docs/src/content/docs/getting-started.mdx b/apps/cli-docs/src/content/docs/getting-started.mdx index db03ee68ef..406843d719 100644 --- a/apps/cli-docs/src/content/docs/getting-started.mdx +++ b/apps/cli-docs/src/content/docs/getting-started.mdx @@ -62,7 +62,8 @@ curl https://cli.sentry.dev/install -fsS | SENTRY_INIT=1 bash ``` The installer reports its own errors to Sentry. Set `SENTRY_CLI_NO_TELEMETRY=1` -to turn this off; the CLI honors the same variable. +or `DO_NOT_TRACK=1` to turn this off; the CLI honors the same variables. Any +value except an empty or false-like one (`0`, `false`, `no`, `off`) counts. ### Verify the Install Script diff --git a/packages/cli/install b/packages/cli/install index e165485763..608e889c07 100755 --- a/packages/cli/install +++ b/packages/cli/install @@ -36,6 +36,7 @@ NC='\033[0m' # Installer errors go to Sentry through the envelope API, using the CLI's # public write-only DSN. No PII is collected. Opt out: SENTRY_CLI_NO_TELEMETRY=1 +# or DO_NOT_TRACK=1. SENTRY_DSN_KEY="1188a86f3f8168f089450587b00bca66" SENTRY_INGEST="https://o1.ingest.us.sentry.io" SENTRY_PROJECT_ID="4510776311808000" @@ -153,6 +154,7 @@ Environment Variables: SENTRY_VERSION Install a specific version (e.g., 0.42.2, nightly) SENTRY_INIT Set to 1 to run \`sentry init\` after installing SENTRY_CLI_NO_TELEMETRY Set to 1 to disable installer error reporting + DO_NOT_TRACK Same as SENTRY_CLI_NO_TELEMETRY Examples: curl -fsSL https://cli.sentry.dev/install | bash @@ -234,11 +236,22 @@ matches() { printf '%s\n' "$1" | grep -Eq "$2" } +# Usage: env_flag_set . Succeeds when a boolean environment variable is +# on: any value except an empty or false-like one (0, false, f, n, no, off, in +# any case). The CLI reads its telemetry opt-outs the same way. +env_flag_set() { + case "$1" in + "" | 0 | [Ff] | [Nn] | [Ff][Aa][Ll][Ss][Ee] | [Nn][Oo] | [Oo][Ff][Ff]) return 1 ;; + esac +} + # Usage: report_error . Sends an error event to Sentry in a # background subshell, so it never slows down or fails the install. report_error() { - # Respect the same opt-out as the CLI binary. - [ "${SENTRY_CLI_NO_TELEMETRY:-}" = "1" ] && return 0 + # Respect the same opt-outs as the CLI binary. + if env_flag_set "${SENTRY_CLI_NO_TELEMETRY:-}" || env_flag_set "${DO_NOT_TRACK:-}"; then + return 0 + fi ( # Telemetry must never fail the script or report its own failures. diff --git a/packages/cli/install.ps1 b/packages/cli/install.ps1 index 425901a02f..733d19980f 100644 --- a/packages/cli/install.ps1 +++ b/packages/cli/install.ps1 @@ -17,6 +17,7 @@ SENTRY_INIT Set to 1 to run `sentry init` after installing SENTRY_NO_MODIFY_PATH Set to 1 to leave the user PATH unchanged SENTRY_CLI_NO_TELEMETRY Set to 1 to disable installer error reporting + DO_NOT_TRACK Same as SENTRY_CLI_NO_TELEMETRY For the nightly channel, install stable first and then run `sentry cli upgrade nightly`. @@ -309,10 +310,17 @@ function Install-SentryCli { return 0 } + # Whether a boolean environment variable is on: any value except an empty or + # false-like one (0, false, f, n, no, off; -contains ignores case), as the + # CLI reads its telemetry opt-outs. + function Test-EnvFlag([string]$Value) { + return -not (@('', '0', 'false', 'f', 'n', 'no', 'off') -contains $Value) + } + # Fire-and-forget error report via the envelope API, mirroring the bash # installer. Uses the CLI's public write-only DSN. No PII collected. function Send-InstallError([string]$Message) { - if ($env:SENTRY_CLI_NO_TELEMETRY -eq '1') { return } + if ((Test-EnvFlag $env:SENTRY_CLI_NO_TELEMETRY) -or (Test-EnvFlag $env:DO_NOT_TRACK)) { return } try { $dsnKey = '1188a86f3f8168f089450587b00bca66' $projectId = '4510776311808000' diff --git a/packages/cli/test/lib/install-ps1-script.test.ts b/packages/cli/test/lib/install-ps1-script.test.ts index 9d8db69384..5e9719e8ea 100644 --- a/packages/cli/test/lib/install-ps1-script.test.ts +++ b/packages/cli/test/lib/install-ps1-script.test.ts @@ -97,6 +97,24 @@ function Invoke-WebRequest { Get-Content -Raw -LiteralPath $env:SENTRY_TEST_INSTALL_SCRIPT | Invoke-Expression `; +const OPT_OUT_CASES = ["SENTRY_CLI_NO_TELEMETRY", "DO_NOT_TRACK"].flatMap( + (name) => [ + ...["1", "true", "TRUE", "yes", "on"].map((value) => ({ + name, + value, + reports: false, + })), + ...["0", "false", "FALSE", "no", "off", ""].map((value) => ({ + name, + value, + reports: true, + })), + ], +); + +const ENVELOPE_URL = + "https://o1.ingest.us.sentry.io/api/4510776311808000/envelope/"; + const asset = "sentry-windows-x64.exe"; const served: ServedAsset = { name: asset, @@ -257,6 +275,20 @@ describe.skipIf(!hasPwsh)("PowerShell install script", () => { expect(recorded("setup-args").at(-1)).toBe("--no-modify-path"); }); + test.each(OPT_OUT_CASES)( + "$name=$value sends the error report: $reports", + ({ name, value, reports }) => { + env["SENTRY_TEST_SETUP_EXIT"] = "3"; + delete env["SENTRY_CLI_NO_TELEMETRY"]; + env[name] = value; + + const result = run(); + + expect(result.status).not.toBe(0); + expect(recorded("urls").includes(ENVELOPE_URL)).toBe(reports); + }, + ); + test.each([ { name: "non-Windows hosts", diff --git a/packages/cli/test/lib/install-script.test.ts b/packages/cli/test/lib/install-script.test.ts index f5b01da6a5..34a3f194f4 100644 --- a/packages/cli/test/lib/install-script.test.ts +++ b/packages/cli/test/lib/install-script.test.ts @@ -70,6 +70,21 @@ printf '%s\\n' "$0" >> "$SENTRY_TEST_DIR/post-binary" exit "\${SENTRY_TEST_POST_EXIT:-0}" `; +const OPT_OUT_CASES = ["SENTRY_CLI_NO_TELEMETRY", "DO_NOT_TRACK"].flatMap( + (name) => [ + ...["1", "true", "TRUE", "yes", "on"].map((value) => ({ + name, + value, + reports: false, + })), + ...["0", "false", "FALSE", "no", "off", ""].map((value) => ({ + name, + value, + reports: true, + })), + ], +); + const hostAsset = `sentry-${process.platform === "darwin" ? "darwin" : "linux"}-${process.arch === "arm64" ? "arm64" : "x64"}`; const served: ServedAsset = { name: hostAsset, @@ -733,6 +748,25 @@ exit 127 expect(report.tags["registry.curl_exit"]).toBe("0"); }); + test.each(OPT_OUT_CASES)( + "$name=$value sends the error report: $reports", + ({ name, value, reports }) => { + applyScenario( + { ...at(INSTALL_SCENARIOS, 0), registry: { status: 503 } }, + served, + testDir, + env, + ); + delete env["SENTRY_CLI_NO_TELEMETRY"]; + env[name] = value; + + const result = install(); + + expect(result.status).not.toBe(0); + expect(existsSync(join(testDir, "error-report"))).toBe(reports); + }, + ); + const shIsBash = spawnSync("sh", ["-c", 'echo "${BASH_VERSION:-}"'], { encoding: "utf8", From d61eaa29137e1d62595399732c22fb2a4e9e342e Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Sat, 5 Dec 2026 08:30:31 +0000 Subject: [PATCH 4/4] test(cli): Compare installer request URLs exactly `Array#includes` on the recorded URLs read to CodeQL as a URL substring check. Compare each URL with `===` instead; the test checks the same thing. --- packages/cli/test/lib/install-ps1-script.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/test/lib/install-ps1-script.test.ts b/packages/cli/test/lib/install-ps1-script.test.ts index 5e9719e8ea..a7a0de3eb1 100644 --- a/packages/cli/test/lib/install-ps1-script.test.ts +++ b/packages/cli/test/lib/install-ps1-script.test.ts @@ -285,7 +285,9 @@ describe.skipIf(!hasPwsh)("PowerShell install script", () => { const result = run(); expect(result.status).not.toBe(0); - expect(recorded("urls").includes(ENVELOPE_URL)).toBe(reports); + expect(recorded("urls").some((url) => url === ENVELOPE_URL)).toBe( + reports, + ); }, );