Skip to content

Commit e8f9344

Browse files
Add telemetry data catalog collection to wrangler deployments
1 parent 213ed2f commit e8f9344

33 files changed

+851
-41
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cloudflare/workers-utils": minor
3+
---
4+
5+
Add `getTelemetryDataCatalogWorkerURL` environment variable factory
6+
7+
Adds a new environment variable factory for `TELEMETRY_DATA_CATALOG_WORKER_URL` which configures the telemetry data catalog endpoint. Also improves PackageJSON type definitions to use `Record<string, string>` for dependencies, devDependencies, and scripts fields.

.changeset/tidy-carrots-dance.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add telemetry data catalog collection to wrangler deployments
6+
7+
Wrangler now sends anonymized usage data to a telemetry data catalog during `wrangler deploy`. This includes:
8+
9+
- Account ID and Worker name
10+
- Wrangler version and package manager used
11+
- Deployment timestamp
12+
- Binding type counts (how many KV namespaces, R2 buckets, D1 databases, etc.)
13+
- Project dependency information (package names and versions from package.json)
14+
15+
This data helps the Cloudflare team understand Wrangler usage patterns. The telemetry is disabled by default during tests and can be disabled by setting `TELEMETRY_DATA_CATALOG_WORKER_URL` to an empty string.

packages/workers-utils/src/environment-variables/factory.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ type VariableNames =
131131
| "DOCKER_HOST"
132132

133133
/** Environment variable used to signal that the current process is being run by the open-next deploy command. */
134-
| "OPEN_NEXT_DEPLOY";
134+
| "OPEN_NEXT_DEPLOY"
135+
136+
/** URL for the telemetry data catalog worker (defaults to `""` in vitest, the production data collector worker otherwise; falsy disables collection). */
137+
| "TELEMETRY_DATA_CATALOG_WORKER_URL";
135138

136139
type DeprecatedNames =
137140
| "CF_ACCOUNT_ID"

packages/workers-utils/src/environment-variables/misc-variables.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,19 @@ export const getCfFetchPathFromEnv = getEnvironmentVariableFactory({
392392
export const getWranglerCacheDirFromEnv = getEnvironmentVariableFactory({
393393
variableName: "WRANGLER_CACHE_DIR",
394394
});
395+
396+
/**
397+
* `TELEMETRY_DATA_CATALOG_WORKER_URL` specifies the URL for the telemetry data catalog worker.
398+
*
399+
* Defaults to `""` (disabling the data collection) when running in vitest (i.e. when `typeof vitest !== "undefined"`),
400+
* otherwise defaults to the production data collector worker's URL.
401+
*
402+
* When the value is falsy, telemetry data catalog collection is disabled.
403+
*/
404+
export const getTelemetryDataCatalogWorkerURL = getEnvironmentVariableFactory({
405+
variableName: "TELEMETRY_DATA_CATALOG_WORKER_URL",
406+
defaultValue: () =>
407+
typeof vitest !== "undefined"
408+
? ""
409+
: "https://telemetry-data-catalog-collector.devprod.workers.dev",
410+
});

packages/workers-utils/src/parse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ export function parseTOML(tomlContent: string, filePath?: string): unknown {
119119
export type PackageJSON = {
120120
name?: string;
121121
version?: string;
122-
devDependencies?: Record<string, unknown>;
123-
dependencies?: Record<string, unknown>;
124-
scripts?: Record<string, unknown>;
122+
devDependencies?: Record<string, string>;
123+
dependencies?: Record<string, string>;
124+
scripts?: Record<string, string>;
125125
};
126126

127127
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare global {
2+
const vitest: unknown;
3+
}
4+
export {};

packages/workers-utils/vitest.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare global {
2+
const vitest: unknown;
3+
}
4+
export {};

packages/wrangler/src/__tests__/deploy/assets.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { writeWranglerConfig } from "@cloudflare/workers-utils/test-helpers";
44
import { http, HttpResponse } from "msw";
55
import dedent from "ts-dedent";
66
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7-
import { getInstalledPackageVersion } from "../../autoconfig/frameworks/utils/packages";
87
import { clearOutputFilePath } from "../../output";
98
import { fetchSecrets } from "../../utils/fetch-secrets";
9+
import { getInstalledPackageVersion } from "../../utils/packages";
1010
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
1111
import { mockConsoleMethods } from "../helpers/mock-console";
1212
import { clearDialogs } from "../helpers/mock-dialogs";
@@ -54,7 +54,7 @@ vi.mock("../../package-manager", async (importOriginal) => ({
5454
}));
5555

5656
vi.mock("../../autoconfig/run");
57-
vi.mock("../../autoconfig/frameworks/utils/packages");
57+
vi.mock("../../utils/packages");
5858
vi.mock("../../autoconfig/c3-vendor/command");
5959

6060
describe("deploy", () => {

packages/wrangler/src/__tests__/deploy/bindings.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { sync } from "command-exists";
88
import { http, HttpResponse } from "msw";
99
import * as TOML from "smol-toml";
1010
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
11-
import { getInstalledPackageVersion } from "../../autoconfig/frameworks/utils/packages";
1211
import { clearOutputFilePath } from "../../output";
1312
import { fetchSecrets } from "../../utils/fetch-secrets";
13+
import { getInstalledPackageVersion } from "../../utils/packages";
1414
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
1515
import { mockConsoleMethods } from "../helpers/mock-console";
1616
import { clearDialogs } from "../helpers/mock-dialogs";
@@ -55,7 +55,7 @@ vi.mock("../../package-manager", async (importOriginal) => ({
5555
}));
5656

5757
vi.mock("../../autoconfig/run");
58-
vi.mock("../../autoconfig/frameworks/utils/packages");
58+
vi.mock("../../utils/packages");
5959
vi.mock("../../autoconfig/c3-vendor/command");
6060

6161
describe("deploy", () => {

packages/wrangler/src/__tests__/deploy/build.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
import * as esbuild from "esbuild";
1212
import { http, HttpResponse } from "msw";
1313
import { afterEach, beforeEach, describe, expect, it, test, vi } from "vitest";
14-
import { getInstalledPackageVersion } from "../../autoconfig/frameworks/utils/packages";
1514
import { printBundleSize } from "../../deployment-bundle/bundle-reporter";
1615
import { clearOutputFilePath } from "../../output";
1716
import { fetchSecrets } from "../../utils/fetch-secrets";
1817
import { diagnoseScriptSizeError } from "../../utils/friendly-validator-errors";
18+
import { getInstalledPackageVersion } from "../../utils/packages";
1919
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
2020
import { mockConsoleMethods } from "../helpers/mock-console";
2121
import { clearDialogs } from "../helpers/mock-dialogs";
@@ -58,7 +58,7 @@ vi.mock("../../package-manager", async (importOriginal) => ({
5858
}));
5959

6060
vi.mock("../../autoconfig/run");
61-
vi.mock("../../autoconfig/frameworks/utils/packages");
61+
vi.mock("../../utils/packages");
6262
vi.mock("../../autoconfig/c3-vendor/command");
6363

6464
describe("deploy", () => {

0 commit comments

Comments
 (0)