Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Initial check-in for supporting telemetry in vscode #6123

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update update-vscode-telemetry-key script
  • Loading branch information
RodgeFu committed Feb 27, 2025
commit fa8281e31a37fa9d27f45961761f31c08b768cf4
4 changes: 4 additions & 0 deletions eng/tsp-core/pipelines/templates/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Template building all packages with parallelism.

steps:
- script: pnpm run update-telemetry-key $(vscode.telemetryKey)
workingDirectory: $(Build.SourcesDirectory)/packages/typespec-vscode
displayName: Update vscode telemetry key

- script: pnpm run build
displayName: Build
30 changes: 18 additions & 12 deletions packages/typespec-vscode/scripts/update-telemetry-key.js
Original file line number Diff line number Diff line change
@@ -5,27 +5,33 @@ import { fileURLToPath } from "url";
const newKey = process.argv[2];
if (!newKey) {
console.log("One argument for telemetry-key to use is expected. Exit without updating anything");
process.exit(1);
} else {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const targetPackageJsonFile = path.resolve(__dirname, "../package.json");
console.log(`Updating package.json at ${targetPackageJsonFile}`);
const packageJson = JSON.parse(fs.readFileSync(targetPackageJsonFile, "utf8"));
console.log(`original package.json: \n` + JSON.stringify(packageJson, null, 2));
const oldKey = packageJson.telemetryKey;
console.log(`Original telemetry key: ${oldKey}`);
const oldKey = packageJson.telemetryKey ?? "";
const keyToString = (key) =>
`'${key.substring(0, 8)}...${key.substring(Math.max(0, oldKey.length - 17))}'(length: ${key.length})`;

const getLastSegOfKey = (key) => key.substring(Math.max(0, newKey.length - 12));

console.log(
`Updating telemetry key from ...${getLastSegOfKey(oldKey)} to ...${getLastSegOfKey(newKey)}`,
);
console.log(`Updating telemetry key from ${keyToString(oldKey)} to ${keyToString(newKey)}`);
packageJson.telemetryKey = newKey;

fs.writeFileSync(targetPackageJsonFile, JSON.stringify(packageJson, null, 2));

const newPackageJsonString = fs.readFileSync(targetPackageJsonFile, "utf8");
console.log(`package.json updated to: \n` + JSON.stringify(newPackageJsonString, null, 2));

console.log("package.json updated successfully");
// double verify the updated result
const newPackageJson = JSON.parse(fs.readFileSync(targetPackageJsonFile, "utf8"));
const updatedKey = newPackageJson.telemetryKey ?? "";
if (updatedKey !== newKey) {
console.error(
`Failed to update telemetry key in package.json. Actual = ${keyToString(updatedKey)}; Expected = ${keyToString(newKey)}`,
);
process.exit(2);
} else {
console.log(
`telemetryKey in package.json updated to '${keyToString(updatedKey)}' successfully`,
);
}
}
Loading
Oops, something went wrong.