Skip to content

Commit 40b1f81

Browse files
CarmenPopoviciupenalosa
authored andcommitted
feat(wrangler): Capture Workers with static assets in the telemetry data (#7604)
* feat(wrangler): Capture Workers with static assets in the telemetry data * add changeset
1 parent e16822c commit 40b1f81

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

.changeset/long-houses-mate.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
feat: Capture Workers with static assets in the telemetry data
6+
7+
We want to measure accurately what this number of Workers + Assets projects running in remote mode is, as this number will be a very helpful data point down the road, when more decisions around remote mode will have to be taken.
8+
9+
These changes add this kind of insight to our telemetry data, by capturing whether the command running is in the context of a Workers + Assets project.
10+
11+
N.B. With these changes in place we will be capturing the Workers + Assets context for all commands, not just wrangler dev --remote.

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from "node:fs";
12
import { http, HttpResponse } from "msw";
23
import { vi } from "vitest";
34
import { CI } from "../is-ci";
@@ -189,6 +190,7 @@ describe("metrics", () => {
189190
isPagesCI: false,
190191
isWorkersCI: false,
191192
isInteractive: true,
193+
hasAssets: false,
192194
argsUsed: [],
193195
argsCombination: "",
194196
command: "wrangler docs",
@@ -359,6 +361,58 @@ describe("metrics", () => {
359361
expect(std.debug).toContain('isWorkersCI":true');
360362
});
361363

364+
it("should capture Workers + Assets projects", async () => {
365+
writeWranglerConfig({ assets: { directory: "./public" } });
366+
367+
// set up empty static assets directory
368+
fs.mkdirSync("./public");
369+
370+
const requests = mockMetricRequest();
371+
372+
await runWrangler("docs arg");
373+
expect(requests.count).toBe(2);
374+
375+
// command started
376+
const expectedStartReq = {
377+
deviceId: "f82b1f46-eb7b-4154-aa9f-ce95f23b2288",
378+
event: "wrangler command started",
379+
timestamp: 1733961600000,
380+
properties: {
381+
amplitude_session_id: 1733961600000,
382+
amplitude_event_id: 0,
383+
...{ ...reused, hasAssets: true },
384+
},
385+
};
386+
expect(std.debug).toContain(
387+
`Posting data ${JSON.stringify(expectedStartReq)}`
388+
);
389+
390+
// command completed
391+
const expectedCompleteReq = {
392+
deviceId: "f82b1f46-eb7b-4154-aa9f-ce95f23b2288",
393+
event: "wrangler command completed",
394+
timestamp: 1733961606000,
395+
properties: {
396+
amplitude_session_id: 1733961600000,
397+
amplitude_event_id: 1,
398+
...{ ...reused, hasAssets: true },
399+
durationMs: 6000,
400+
durationSeconds: 6,
401+
durationMinutes: 0.1,
402+
},
403+
};
404+
expect(std.debug).toContain(
405+
`Posting data ${JSON.stringify(expectedCompleteReq)}`
406+
);
407+
expect(std.out).toMatchInlineSnapshot(`
408+
"
409+
Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md
410+
Opening a link in your default browser: FAKE_DOCS_URL:{\\"params\\":\\"query=arg&hitsPerPage=1&getRankingInfo=0\\"}"
411+
`);
412+
expect(std.warn).toMatchInlineSnapshot(`""`);
413+
expect(std.err).toMatchInlineSnapshot(`""`);
414+
});
415+
362416
it("should not send arguments with wrangler login", async () => {
363417
const requests = mockMetricRequest();
364418

packages/wrangler/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ export async function main(argv: string[]): Promise<void> {
11551155
const { rawConfig, configPath } = experimental_readRawConfig(args);
11561156
dispatcher = getMetricsDispatcher({
11571157
sendMetrics: rawConfig.send_metrics,
1158+
hasAssets: !!rawConfig.assets?.directory,
11581159
configPath,
11591160
});
11601161
} catch (e) {

packages/wrangler/src/metrics/metrics-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export interface MetricsConfigOptions {
2323
* Otherwise, infer the enabled value from the user configuration.
2424
*/
2525
sendMetrics?: boolean;
26+
/**
27+
* Captures whether this is a Worker with static assets
28+
*/
29+
hasAssets?: boolean;
2630
/**
2731
* Path to wrangler configuration file, if it exists. Used for configFileType property
2832
*/

packages/wrangler/src/metrics/metrics-dispatcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
111111
isPagesCI: isPagesCI(),
112112
isWorkersCI: isWorkersCI(),
113113
isInteractive: isInteractive(),
114+
hasAssets: options.hasAssets ?? false,
114115
argsUsed,
115116
argsCombination,
116117
};

packages/wrangler/src/metrics/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export type CommonEventProperties = {
5252
* Whether the Wrangler client is running in an interactive instance
5353
*/
5454
isInteractive: boolean;
55+
/**
56+
* Whether this is a Worker with static assets
57+
*/
58+
hasAssets: boolean;
5559
/**
5660
* A list of normalised argument names/flags that were passed in or are set by default.
5761
* Excludes boolean flags set to false.

0 commit comments

Comments
 (0)