Skip to content

Commit 205a6b5

Browse files
committed
normalize into camelcase
1 parent 1549390 commit 205a6b5

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ describe("metrics", () => {
279279
"array",
280280
"number",
281281
"positional",
282-
"xgradualrollouts",
283-
"xversions",
282+
"xGradualRollouts",
283+
"xVersions",
284284
],
285285
argsCombination:
286-
"array, number, positional, xgradualrollouts, xversions",
286+
"array, number, positional, xGradualRollouts, xVersions",
287287
command: "wrangler command subcommand",
288288
args: {
289289
...reusedGlobalArgs,
@@ -309,11 +309,11 @@ describe("metrics", () => {
309309
"array",
310310
"number",
311311
"positional",
312-
"xgradualrollouts",
313-
"xversions",
312+
"xGradualRollouts",
313+
"xVersions",
314314
],
315315
argsCombination:
316-
"array, number, positional, xgradualrollouts, xversions",
316+
"array, number, positional, xGradualRollouts, xVersions",
317317
command: "wrangler command subcommand",
318318
args: {
319319
...reusedGlobalArgs,
@@ -361,11 +361,11 @@ describe("metrics", () => {
361361
"array",
362362
"number",
363363
"positional",
364-
"xgradualrollouts",
365-
"xversions",
364+
"xGradualRollouts",
365+
"xVersions",
366366
],
367367
argsCombination:
368-
"array, number, positional, xgradualrollouts, xversions",
368+
"array, number, positional, xGradualRollouts, xVersions",
369369
command: "wrangler command subcommand",
370370
args: {
371371
...reusedGlobalArgs,
@@ -392,11 +392,11 @@ describe("metrics", () => {
392392
"array",
393393
"number",
394394
"positional",
395-
"xgradualrollouts",
396-
"xversions",
395+
"xGradualRollouts",
396+
"xVersions",
397397
],
398398
argsCombination:
399-
"array, number, positional, xgradualrollouts, xversions",
399+
"array, number, positional, xGradualRollouts, xVersions",
400400
command: "wrangler command subcommand",
401401
args: {
402402
...reusedGlobalArgs,

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
4141
/** We redact strings in arg values, unless they are named here */
4242
const allowList = {
4343
// applies to all commands
44-
"*": ["format", "log-level", "logLevel"],
44+
// use camelCase version
45+
"*": ["format", "logLevel"],
4546
// specific commands
4647
tail: ["status"],
4748
};
@@ -86,7 +87,7 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
8687
return;
8788
}
8889
printMetricsBanner();
89-
const argsUsed = normaliseArgs(properties.args ?? {});
90+
const argsUsed = sanitiseUserInput(properties.args ?? {});
9091
const argsCombination = argsUsed.sort().join(", ");
9192
const commonEventProperties: CommonEventProperties = {
9293
amplitude_session_id,
@@ -201,9 +202,15 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
201202

202203
export type Properties = Record<string, unknown>;
203204

205+
const normalise = (arg: string) => {
206+
const camelize = (str: string) =>
207+
str.replace(/-./g, (x) => x[1].toUpperCase());
208+
return camelize(arg.replace("experimental", "x"));
209+
};
210+
204211
const exclude = new Set(["$0", "_"]);
205212
/** just some pretty naive cleaning so we don't send "experimental-versions", "experimentalVersions", "x-versions" and "xVersions" etc. */
206-
const normaliseArgs = (argsWithValues: Record<string, unknown>) => {
213+
const sanitiseUserInput = (argsWithValues: Record<string, unknown>) => {
207214
const result: string[] = [];
208215
const args = Object.keys(argsWithValues);
209216
for (const arg of args) {
@@ -216,10 +223,8 @@ const normaliseArgs = (argsWithValues: Record<string, unknown>) => {
216223
) {
217224
continue;
218225
}
219-
const normalisedArg = arg
220-
.replace("experimental", "x")
221-
.replaceAll("-", "")
222-
.toLowerCase();
226+
227+
const normalisedArg = normalise(arg);
223228
if (result.includes(normalisedArg)) {
224229
continue;
225230
}
@@ -248,7 +253,7 @@ export const redactArgValues = (
248253
if (
249254
typeof value === "number" ||
250255
typeof value === "boolean" ||
251-
allowedKeys.includes(key)
256+
allowedKeys.includes(normalise(key))
252257
) {
253258
result[key] = value;
254259
} else if (typeof value === "string") {

0 commit comments

Comments
 (0)