diff --git a/.changeset/wet-starfishes-drum.md b/.changeset/wet-starfishes-drum.md new file mode 100644 index 000000000000..3c98766c46de --- /dev/null +++ b/.changeset/wet-starfishes-drum.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +Include default values for wrangler types --path and --x-include-runtime in telemetry + +User provided strings are still left redacted as always. diff --git a/packages/wrangler/src/__tests__/metrics.test.ts b/packages/wrangler/src/__tests__/metrics.test.ts index b23c7354889e..7c093c23c3ce 100644 --- a/packages/wrangler/src/__tests__/metrics.test.ts +++ b/packages/wrangler/src/__tests__/metrics.test.ts @@ -582,15 +582,22 @@ describe("metrics", () => { const args = { default: false, array: ["beep", "boop"], - secretArray: ["beep", "boop"], - // Note how + // Note how this is normalised "secret-array": ["beep", "boop"], number: 42, string: "secret", secretString: "secret", + flagOne: "default", + // Note how this is normalised + experimentalIncludeRuntime: "", }; - const redacted = redactArgValues(args, ["string", "array"]); + const redacted = redactArgValues(args, { + string: "*", + array: "*", + flagOne: ["default"], + xIncludeRuntime: [".wrangler/types/runtime.d.ts"], + }); expect(redacted).toEqual({ default: false, array: ["beep", "boop"], @@ -598,6 +605,8 @@ describe("metrics", () => { number: 42, string: "secret", secretString: "", + flagOne: "default", + xIncludeRuntime: ".wrangler/types/runtime.d.ts", }); }); }); diff --git a/packages/wrangler/src/metrics/metrics-dispatcher.ts b/packages/wrangler/src/metrics/metrics-dispatcher.ts index 97d5e62c626f..6d3e494ddca8 100644 --- a/packages/wrangler/src/metrics/metrics-dispatcher.ts +++ b/packages/wrangler/src/metrics/metrics-dispatcher.ts @@ -32,12 +32,15 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) { let amplitude_event_id = 0; /** We redact strings in arg values, unless they are named here */ - const allowList = { + const allowList: Record & { "*": AllowedValues } = { // applies to all commands // use camelCase version - "*": ["format", "logLevel"], - // specific commands - tail: ["status"], + "*": { format: "*", logLevel: "*" }, + "wrangler tail": { status: "*" }, + "wrangler types": { + xIncludeRuntime: [".wrangler/types/runtime.d.ts"], + path: ["worker-configuration.d.ts"], + }, }; return { @@ -253,35 +256,50 @@ const sanitiseUserInput = ( return result; }; +type AllowedValues = Record; const getAllowedArgs = ( - allowList: Record & { "*": string[] }, + allowList: Record & { "*": AllowedValues }, key: string ) => { const commandSpecific = allowList[key] ?? []; - return [...commandSpecific, ...allowList["*"]]; + return { ...commandSpecific, ...allowList["*"] }; }; export const redactArgValues = ( args: Record, - allowedKeys: string[] + allowedValues: AllowedValues ) => { const result: Record = {}; - for (const [k, value] of Object.entries(args)) { - const key = normalise(k); + for (let [key, value] of Object.entries(args)) { + key = normalise(key); + if (key === "xIncludeRuntime" && value === "") { + value = ".wrangler/types/runtime.d.ts"; + } + const allowedValuesForArg = allowedValues[key] ?? []; if (exclude.has(key)) { continue; } if ( typeof value === "number" || typeof value === "boolean" || - allowedKeys.includes(normalise(key)) + allowedValuesForArg.includes(key) ) { result[key] = value; - } else if (typeof value === "string") { + } else if ( + // redact if its a string, unless the value is in the allow list + // * is a special value that allows all values for that arg + typeof value === "string" && + !(allowedValuesForArg === "*" || allowedValuesForArg.includes(value)) + ) { result[key] = ""; } else if (Array.isArray(value)) { result[key] = value.map((v) => - typeof v === "string" ? "" : v + // redact if its a string, unless the value is in the allow list + // * is a special value that allows all values for that arg + typeof v === "string" && + !(allowedValuesForArg === "*" || allowedValuesForArg.includes(v)) + ? "" + : v ); } else { result[key] = value;