Skip to content

Commit d1d268d

Browse files
fixup! allow WRANGLER_SEND_METRICS to override whether to report Wrangler crashes to Sentry
1 parent 8e42f8e commit d1d268d

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

.changeset/angry-apes-share.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"wrangler": patch
33
---
44

5-
allow WRANGLER_SEND_METRICS to override whether to report Wrangler crashes to Sentry
5+
Allow WRANGLER_SEND_ERROR_REPORTS env var to override whether to report Wrangler crashes to Sentry

packages/wrangler/src/__tests__/sentry.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe("sentry", () => {
123123
expect(sentryRequests?.length).toEqual(0);
124124
});
125125

126-
it("should not hit sentry (or even ask) after reportable error if WRANGLER_SEND_METRICS is explicitly false", async () => {
126+
it("should not hit sentry (or even ask) after reportable error if WRANGLER_SEND_ERROR_REPORTS is explicitly false", async () => {
127127
// Trigger an API error
128128
msw.use(
129129
http.get(
@@ -138,7 +138,7 @@ describe("sentry", () => {
138138
})
139139
);
140140
await expect(
141-
runWrangler("whoami", { WRANGLER_SEND_METRICS: "false" })
141+
runWrangler("whoami", { WRANGLER_SEND_ERROR_REPORTS: "false" })
142142
).rejects.toMatchInlineSnapshot(`[TypeError: Failed to fetch]`);
143143
expect(std.out).toMatchInlineSnapshot(`
144144
"Getting User settings...
@@ -454,7 +454,7 @@ describe("sentry", () => {
454454
});
455455
});
456456

457-
it("should hit sentry after reportable error (without confirmation) if WRANGLER_SEND_METRICS is explicitly true", async () => {
457+
it("should hit sentry after reportable error (without confirmation) if WRANGLER_SEND_ERROR_REPORTS is explicitly true", async () => {
458458
// Trigger an API error
459459
msw.use(
460460
http.get(
@@ -469,7 +469,7 @@ describe("sentry", () => {
469469
})
470470
);
471471
await expect(
472-
runWrangler("whoami", { WRANGLER_SEND_METRICS: "true" })
472+
runWrangler("whoami", { WRANGLER_SEND_ERROR_REPORTS: "true" })
473473
).rejects.toMatchInlineSnapshot(`[TypeError: Failed to fetch]`);
474474
expect(std.out).toMatchInlineSnapshot(`
475475
"Getting User settings...

packages/wrangler/src/environment-variables/factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type VariableNames =
8888
| "WRANGLER_C3_COMMAND"
8989
/** Enable/disable telemetry data collection. */
9090
| "WRANGLER_SEND_METRICS"
91+
/** Enable/disable error reporting to Sentry. */
92+
| "WRANGLER_SEND_ERROR_REPORTS"
9193
/** CI branch name (internal use). */
9294
| "WORKERS_CI_BRANCH"
9395
/** CI tag matching configuration (internal use). */

packages/wrangler/src/environment-variables/misc-variables.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export const getWranglerSendMetricsFromEnv =
4545
variableName: "WRANGLER_SEND_METRICS",
4646
});
4747

48+
/**
49+
* `WRANGLER_SEND_ERROR_REPORTS` can override whether we attempt to send error reports to Sentry.
50+
*/
51+
export const getWranglerSendErrorReportsFromEnv =
52+
getBooleanEnvironmentVariableFactory({
53+
variableName: "WRANGLER_SEND_ERROR_REPORTS",
54+
});
55+
4856
/**
4957
* Set `WRANGLER_API_ENVIRONMENT` environment variable to "staging" to tell Wrangler to hit the staging APIs rather than production.
5058
*/

packages/wrangler/src/sentry/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { rejectedSyncPromise } from "@sentry/utils";
33
import { fetch } from "undici";
44
import { version as wranglerVersion } from "../../package.json";
55
import { confirm } from "../dialogs";
6-
import { getWranglerSendMetricsFromEnv } from "../environment-variables/misc-variables";
6+
import { getWranglerSendErrorReportsFromEnv } from "../environment-variables/misc-variables";
77
import { logger } from "../logger";
88
import type { BaseTransportOptions, TransportRequest } from "@sentry/types";
99
import type { RequestInit } from "undici";
@@ -151,10 +151,10 @@ export function addBreadcrumb(
151151
// consent if not already granted.
152152
export async function captureGlobalException(e: unknown) {
153153
if (typeof SENTRY_DSN !== "undefined") {
154-
const sendMetricsEnvVar = getWranglerSendMetricsFromEnv();
154+
const sendErrorReportsEnvVar = getWranglerSendErrorReportsFromEnv();
155155
sentryReportingAllowed =
156-
sendMetricsEnvVar !== undefined
157-
? sendMetricsEnvVar
156+
sendErrorReportsEnvVar !== undefined
157+
? sendErrorReportsEnvVar
158158
: await confirm(
159159
"Would you like to report this error to Cloudflare? Wrangler's output and the error details will be shared with the Wrangler team to help us diagnose and fix the issue.",
160160
{ fallbackValue: false }

0 commit comments

Comments
 (0)