Skip to content

Commit

Permalink
feat: add telemetry commands (#7236)
Browse files Browse the repository at this point in the history
* add telemetry commands

* changeset

* fix and test dates

* update changeset

* add global/project status

* default true

* remove changeset

* update wrangler telemetry status

feat: add `wrangler metrics` as an alias for `wrangler telemetry` (#7284)

* add metrics alias

* tests

* use each to test alias

feat: send metrics for command start/complete/error (#7267)

* stop collecting userId in telemetry

Co-authored-by: emily-shen <emily-shen@users.noreply.github.com>

* implement telemetry collection

* infer errorType based on the constructor name

* implement common event properties

* log common event properties

Co-authored-by: Edmund Hung <me@edmund.dev>

* respect metric enabled/disabled

* remove dispatcher.identify

* include SPARROW_SOURCE_KEY in PR pre-release build

* fix tests

* ensure debug log covers the request failed message

* replace SPARROW_SOURCE_KEY regardless whethe env exists

---------

Co-authored-by: Edmund Hung <edmund@cloudflare.com>
Co-authored-by: emily-shen <emily-shen@users.noreply.github.com>
Co-authored-by: Edmund Hung <me@edmund.dev>

fix nested properties (#7300)

feat: add banner to indicate when telemetry is on (#7302)

* add banner

* abort if telemetry disable

* basic sendNewEvent tests

* banner tests

* settle promises before exiting

* remove unnecessary banner logic

* just check if version is different

feat: add some more properties to telemetry events (#7320)

* isCI and isNonInteractive

* add argsUsed and argsCombination

* don't include args if value is false

* redact arg values if string

* lint

* isNonInteractive -> isInteractive

cleanup defineCommand

test duration

log metrics request failure

add draft telemetry.md

add node and os versions

don't send wrangler metrics from c3 if disabled

don't send c3 metrics from wrangler init

add config type

add more comments to send-event

move types out of send-event.ts

add comment about applyBeforeValidation

normalize into camelcase

refactor telemetry command

update tests and some comments

normalise all args

pr feedback

update telemetry.md

use useragent to get package manager

make sendEvent/sendNewEvent sync

rename sendEvent and sendNewEvent

fix lock file

remove flushPromises

changeset

fail silently

feat(wrangler): make resources identifier optional if x-provision flag is enabled (#7377)

Fix wrangler module import under npm monorepos (#7130)

* Update import resolution for files and package exports

In an npm workspace environment, wrangler will now be able to
successfully resolve package exports.

Previously, wrangler would only be able to resolve modules in a relative
`node_modules` directory and not workspace root `node_modules`
directory.

* Use esbuild plugin

chore(wrangler): fix type errors with experimental flags (#7391)

refactor(wrangler): Explicitely pick node compat plugins for each mode (#7387)

* refactor: cleanup & simplify

* refactor(wrangler): Explicitely pick node compat plugins for each mode

* Update packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts

Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>

* fixup! renamed vars (review feedback)

* fixup! format

---------

Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>

fix: error in angular c3 template (#7342)

* fixed: related to issues-7341
AngularAppEngine class does not have .render, instead it should be
.handle method

* added: changeset

* Tidy up changeset

* fix Angular template

- add a preview script so that it gets included in CI test
- remove unnecessary --`experimnental-local` CLI arg
- add missing `xhr2` dependency

---------

Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>

[C3] Bump create-qwik from 1.10.0 to 1.11.0 in /packages/create-cloudflare/src/frameworks (#7359)

* [C3] Bump create-qwik in /packages/create-cloudflare/src/frameworks

Bumps [create-qwik](https://github.com/QwikDev/qwik/tree/HEAD/packages/create-qwik) from 1.10.0 to 1.11.0.
- [Release notes](https://github.com/QwikDev/qwik/releases)
- [Changelog](https://github.com/QwikDev/qwik/blob/create-qwik@1.11.0/packages/create-qwik/CHANGELOG.md)
- [Commits](https://github.com/QwikDev/qwik/commits/create-qwik@1.11.0/packages/create-qwik)

---
updated-dependencies:
- dependency-name: create-qwik
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: update dependencies of "create-cloudflare" package

The following dependency versions have been updated:

| Dependency  | From   | To     |
| ----------- | ------ | ------ |
| create-qwik | 1.10.0 | 1.11.0 |

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Wrangler automated PR updater <wrangler@cloudflare.com>

Remove await from user Worker fetch in router-worker (#7410)

fix: update Angular experimental Workers + Assets template (#7409)

* fix: update Angular experimental Workers + Assets template

* ci: enable tests on experimental Workers + Assets C3 templates

fix: update queues max_batch_timeout in miniflare (#7399)

* update timeout limit

* changeset

* test

* remove only

Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>

---------

Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>

refactor: move projectRoot computation to config validation (#7415)

move telemetry.md out of src

fixups

tiody up readRawConfig

Rename serve_directly to experimental_serve_directly (#7429)

chore(deps): bump the workerd-and-workers-types group across 1 directory with 2 updates (#7418)

Updates `workerd` from 1.20241106.1 to 1.20241202.2

Version Packages (#7358)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

ci: don't watch for changes on the workers-shared test:ci job (#7420)

refactor: remove missed redundant computation of `projectRoot` (#7421)

* refactor: remove missed redundant computation of `projectRoot`

* test: do not watch test files in workflow fixture test jobs

feat(wrangler): add inherit bindings support (#7385)

* feat(wrangler): add inherit bindings support

* add test

* add changeset

* rename file to bindings

Relax type on `observability.enabled` (#7436)

fix: C3 experimental template for Solid now uses correct preset (#7343)

fix: allow the asset directory to be omitted in Wrangler config for commands that don't need it (#7426)

fix: C3 experimental template for Nuxt now uses correct preset (#7332)

* fix: C3 experimental template for Nuxt now uses correct preset

* test: remove quarantine from Nuxt experimental template

using the github browser merge is always a bad idea

fix e2e
  • Loading branch information
emily-shen committed Dec 4, 2024
1 parent 4e571fd commit 46f8fae
Show file tree
Hide file tree
Showing 43 changed files with 1,406 additions and 529 deletions.
9 changes: 9 additions & 0 deletions .changeset/perfect-cougars-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": minor
---

Add anonymous telemetry to Wrangler commands

For new users, Cloudflare will collect anonymous usage telemetry to guide and improve Wrangler's development. If you have already opted out of Wrangler's existing telemetry, this setting will still be respected.

See our [data policy](https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md) for more details on what we collect and how to opt out if you wish.
2 changes: 2 additions & 0 deletions .github/workflows/create-pullrequest-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
run: node .github/prereleases/2-build-pack-upload.mjs
env:
NODE_ENV: "production"
# this is the "test/staging" key for sparrow analytics
SPARROW_SOURCE_KEY: "5adf183f94b3436ba78d67f506965998"
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_PUBLIC_KEY: ${{ secrets.ALGOLIA_PUBLIC_KEY }}
SENTRY_DSN: "https://9edbb8417b284aa2bbead9b4c318918b@sentry10.cfdata.org/583"
Expand Down
58 changes: 58 additions & 0 deletions packages/create-cloudflare/src/helpers/__tests__/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { existsSync } from "fs";
import { spawn } from "cross-spawn";
import { readMetricsConfig } from "helpers/metrics-config";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import whichPMRuns from "which-pm-runs";
import { quoteShellArgs, runCommand } from "../command";
Expand All @@ -13,6 +14,7 @@ let spawnStderr: string | undefined = undefined;
vi.mock("cross-spawn");
vi.mock("fs");
vi.mock("which-pm-runs");
vi.mock("helpers/metrics-config");

describe("Command Helpers", () => {
afterEach(() => {
Expand Down Expand Up @@ -55,6 +57,62 @@ describe("Command Helpers", () => {
});
});

describe("respect telemetry permissions when running wrangler", () => {
test("runCommand has WRANGLER_SEND_METRICS=false if its a wrangler command and c3 telemetry is disabled", async () => {
vi.mocked(readMetricsConfig).mockReturnValue({
c3permission: {
enabled: false,
date: new Date(2000),
},
});
await runCommand(["npx", "wrangler"]);

expect(spawn).toHaveBeenCalledWith(
"npx",
["wrangler"],
expect.objectContaining({
env: expect.objectContaining({ WRANGLER_SEND_METRICS: "false" }),
}),
);
});

test("runCommand doesn't have WRANGLER_SEND_METRICS=false if its a wrangler command and c3 telemetry is enabled", async () => {
vi.mocked(readMetricsConfig).mockReturnValue({
c3permission: {
enabled: true,
date: new Date(2000),
},
});
await runCommand(["npx", "wrangler"]);

expect(spawn).toHaveBeenCalledWith(
"npx",
["wrangler"],
expect.objectContaining({
env: expect.not.objectContaining({ WRANGLER_SEND_METRICS: "false" }),
}),
);
});

test("runCommand doesn't have WRANGLER_SEND_METRICS=false if not a wrangler command", async () => {
vi.mocked(readMetricsConfig).mockReturnValue({
c3permission: {
enabled: false,
date: new Date(2000),
},
});
await runCommand(["ls", "-l"]);

expect(spawn).toHaveBeenCalledWith(
"ls",
["-l"],
expect.objectContaining({
env: expect.not.objectContaining({ WRANGLER_SEND_METRICS: "false" }),
}),
);
});
});

describe("quoteShellArgs", () => {
test.runIf(process.platform !== "win32")("mac", async () => {
expect(quoteShellArgs([`pages:dev`])).toEqual("pages:dev");
Expand Down
10 changes: 10 additions & 0 deletions packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { stripAnsi } from "@cloudflare/cli";
import { CancelError } from "@cloudflare/cli/error";
import { isInteractive, spinner } from "@cloudflare/cli/interactive";
import { spawn } from "cross-spawn";
import { readMetricsConfig } from "./metrics-config";

/**
* Command is a string array, like ['git', 'commit', '-m', '"Initial commit"']
Expand Down Expand Up @@ -52,6 +53,15 @@ export const runCommand = async (
doneText: opts.doneText,
promise() {
const [executable, ...args] = command;
// Don't send metrics data on any wrangler commands if telemetry is disabled in C3
// If telemetry is disabled separately for wrangler, wrangler will handle that
if (args[0] === "wrangler") {
const metrics = readMetricsConfig();
if (metrics.c3permission?.enabled === false) {
opts.env ??= {};
opts.env["WRANGLER_SEND_METRICS"] = "false";
}
}
const abortController = new AbortController();
const cmd = spawn(executable, [...args], {
// TODO: ideally inherit stderr, but npm install uses this for warnings
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ async function buildMain(flags: BuildFlags = {}) {
__RELATIVE_PACKAGE_PATH__,
"import.meta.url": "import_meta_url",
"process.env.NODE_ENV": `'${process.env.NODE_ENV || "production"}'`,
...(process.env.SPARROW_SOURCE_KEY
? { SPARROW_SOURCE_KEY: `"${process.env.SPARROW_SOURCE_KEY}"` }
: {}),
"process.env.SPARROW_SOURCE_KEY": JSON.stringify(
process.env.SPARROW_SOURCE_KEY ?? ""
),
...(process.env.ALGOLIA_APP_ID
? { ALGOLIA_APP_ID: `"${process.env.ALGOLIA_APP_ID}"` }
: {}),
Expand Down
22 changes: 22 additions & 0 deletions packages/wrangler/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { File, FormData } from "undici";
import { vi } from "vitest";
import { version as wranglerVersion } from "../../package.json";
import { downloadWorker } from "../init";
import { writeMetricsConfig } from "../metrics/metrics-config";
import { getPackageManager } from "../package-manager";
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
Expand Down Expand Up @@ -149,6 +150,27 @@ describe("init", () => {
);
});
});

test("if telemetry is disabled in wrangler, then disable for c3 too", async () => {
writeMetricsConfig({
permission: {
enabled: false,
date: new Date(2024, 11, 11),
},
});
await runWrangler("init");

expect(execa).toHaveBeenCalledWith(
"mockpm",
["create", "cloudflare@^2.5.0"],
{
env: {
CREATE_CLOUDFLARE_TELEMETRY_DISABLED: "1",
},
stdio: "inherit",
}
);
});
});

describe("deprecated behavior is retained with --no-delegate-c3", () => {
Expand Down
Loading

0 comments on commit 46f8fae

Please sign in to comment.