Skip to content

Commit

Permalink
fix: telemetry event and property should not contains number (#12709)
Browse files Browse the repository at this point in the history
* fix: telemetry event and property should not contains number

* fix: telemetry event and property should not contains number

* fix: add command full property in telemetry

* test: ut
  • Loading branch information
jayzhang authored Nov 13, 2024
1 parent a935362 commit 7d4f606
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/commands/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
telemetryUtils,
getHashedEnv,
isUserCancelError,
maskSecret,
} from "@microsoft/teamsfx-core";
import { cloneDeep, pick } from "lodash";
import path from "path";
Expand Down Expand Up @@ -89,6 +90,9 @@ class CLIEngine {
globalOptionValues: {},
argumentValues: [],
telemetryProperties: {
[TelemetryProperty.CommandFull]: maskSecret(args.join(" "), {
replace: "***",
}),
[TelemetryProperty.CommandName]: foundCommand.fullName,
[TelemetryProperty.Component]: TelemetryComponentType,
[TelemetryProperty.RunFrom]: tryDetectCICDPlatform(),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/models/m365Sideloading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const m365SideloadingCommand: CLICommand = {
},
],
telemetry: {
event: TelemetryEvent.M365Sigeloading,
event: TelemetryEvent.Install,
},
defaultInteractiveOption: false,
handler: async (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/models/m365Unacquire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const m365UnacquireCommand: CLICommand = {
},
],
telemetry: {
event: TelemetryEvent.M365Unacquire,
event: TelemetryEvent.Uninstall,
},
defaultInteractiveOption: true,
handler: async (ctx) => {
Expand Down
13 changes: 6 additions & 7 deletions packages/cli/src/telemetry/cliTelemetryEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum TelemetryEvent {
AccountLoginStart = "login-start",
AccountLogin = "login",
AccountLoginAzure = "login-azure",
AccountLoginM365 = "login-m365",
AccountLoginM365 = "login-m",

AccountLogout = "logout",

Expand Down Expand Up @@ -113,9 +113,9 @@ export enum TelemetryEvent {

Command = "command", // this event is used to track the usage of each command, including --help command

M365Sigeloading = "m365-sideloading",
M365Unacquire = "m365-unacquire",
M365LaunchInfo = "m365-launch-info",
Install = "install",
Uninstall = "uninstall",
M365LaunchInfo = "mos-launch-info",

Doctor = "doctor",

Expand Down Expand Up @@ -155,14 +155,13 @@ export enum TelemetryProperty {
Env = "env",
SettingsVersion = "settings-version",
NewProjectId = "new-project-id",
IsM365 = "is-m365",
IsCreatingM365 = "is-creating-m365",
ProgrammingLanguage = "programming-language",
HostType = "host-type",

RunFrom = "run-from",

IsCreatingM365 = "is-creating-office",
// command related property
CommandFull = "command-full",
CommandName = "command-name",
CommandHelp = "command-help",
CommandVersion = "command-version",
Expand Down
4 changes: 2 additions & 2 deletions packages/fx-core/src/common/secretmasker/masker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class SecretMasker {
// If the decision function value is positive, classify as 1 (secret), otherwise 0 (non-secret)
return decisionValue > 0 ? 1 : 0;
}
maskSecret(text: string, replace = "***"): string {
maskSecret(text: string, replace = "***", whiteList?: string[]): string {
const tokens = extractFeatures(text);
for (const token of tokens) {
if (token.type === "splitter") continue;
if (WHITE_LIST.includes(token.token)) continue;
if (whiteList && whiteList.includes(token.token)) continue;
const prediction = this.predict(token.vector!);
token.label = prediction;
if (prediction === 1) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fx-core/src/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function maskSecret(inputText?: string, option?: MaskSecretOptions): stri
if (!inputText) return "";
const replace = option?.replace || SECRET_REPLACE;
let output = maskSecretFromEnv(inputText);
output = secretMasker.maskSecret(output, replace);
output = secretMasker.maskSecret(output, replace, option?.whiteList);
return output;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/fx-core/tests/common/secretMasker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ describe("secret masker", () => {
const output = secretMasker.maskSecret("Successfully ran target precommit for project.");
assert.equal(output, "Successfully ran target precommit for project.");
});
it("white list", async () => {
const output = secretMasker.maskSecret("mysql -p password123456", undefined, [
"password123456",
]);
assert.equal(output, "mysql -p password123456");
});
});
});

0 comments on commit 7d4f606

Please sign in to comment.