-
-
Notifications
You must be signed in to change notification settings - Fork 139
feat(ide): add telemetry tracking to VSCode extension #2505
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6cf1f8f
feat(ide): add telemetry tracking to VSCode extension
ymc9 42cb3ad
feat(ide): add post-build script to inject telemetry token
ymc9 843a08d
add vscode telemetry token env var
ymc9 1ca2d15
fix env var
ymc9 d08bab8
chore(ide): disable no-prototype-builtins eslint rule
ymc9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| import config from '@zenstackhq/eslint-config/base.js'; | ||
|
|
||
| /** @type {import("eslint").Linter.Config} */ | ||
| export default config; | ||
| export default [ | ||
| ...config, | ||
| { | ||
| rules: { | ||
| 'no-prototype-builtins': 'off', | ||
| }, | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import dotenv from 'dotenv'; | ||
| import fs from 'node:fs'; | ||
|
|
||
| dotenv.config({ path: './.env.local' }); | ||
| dotenv.config({ path: './.env' }); | ||
|
|
||
| const telemetryToken = process.env.VSCODE_TELEMETRY_TRACKING_TOKEN; | ||
| if (!telemetryToken) { | ||
| console.error('Error: VSCODE_TELEMETRY_TRACKING_TOKEN environment variable is not set'); | ||
| process.exit(1); | ||
| } | ||
| const file = 'dist/extension.js'; | ||
| let content = fs.readFileSync(file, 'utf-8'); | ||
| content = content.replace('<VSCODE_TELEMETRY_TRACKING_TOKEN>', telemetryToken); | ||
| fs.writeFileSync(file, content, 'utf-8'); | ||
| console.log('Telemetry token injected into dist/extension.js'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // modified from https://github.com/automation-stack/node-machine-id | ||
|
|
||
| import { execSync } from 'child_process'; | ||
| import { createHash } from 'crypto'; | ||
| import { v4 as uuid } from 'uuid'; | ||
|
|
||
| const { platform } = process; | ||
| const win32RegBinPath = { | ||
| native: '%windir%\\System32', | ||
| mixed: '%windir%\\sysnative\\cmd.exe /c %windir%\\System32', | ||
| }; | ||
| const guid = { | ||
| darwin: 'ioreg -rd1 -c IOPlatformExpertDevice', | ||
| win32: | ||
| `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` + | ||
| 'QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography ' + | ||
| '/v MachineGuid', | ||
| linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname 2> /dev/null) | head -n 1 || :', | ||
| freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid', | ||
| }; | ||
|
|
||
| function isWindowsProcessMixedOrNativeArchitecture() { | ||
| if (process.arch === 'ia32' && process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) { | ||
| return 'mixed'; | ||
| } | ||
| return 'native'; | ||
| } | ||
|
|
||
| function hash(guid: string): string { | ||
| return createHash('sha256').update(guid).digest('hex'); | ||
| } | ||
|
|
||
| function expose(result: string): string { | ||
| switch (platform) { | ||
| case 'darwin': | ||
| return result | ||
| .split('IOPlatformUUID')[1]! | ||
| .split('\n')[0]! | ||
| .replace(/=|\s+|"/gi, '') | ||
| .toLowerCase(); | ||
| case 'win32': | ||
| return result | ||
| .toString() | ||
| .split('REG_SZ')[1]! | ||
| .replace(/\r+|\n+|\s+/gi, '') | ||
| .toLowerCase(); | ||
| case 'linux': | ||
| return result | ||
| .toString() | ||
| .replace(/\r+|\n+|\s+/gi, '') | ||
| .toLowerCase(); | ||
| case 'freebsd': | ||
| return result | ||
| .toString() | ||
| .replace(/\r+|\n+|\s+/gi, '') | ||
| .toLowerCase(); | ||
| default: | ||
| throw new Error(`Unsupported platform: ${process.platform}`); | ||
| } | ||
| } | ||
ymc9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export function getMachineId() { | ||
| if (!(platform in guid)) { | ||
| return uuid(); | ||
| } | ||
| try { | ||
| const value = execSync(guid[platform as keyof typeof guid]); | ||
| const id = expose(value.toString()); | ||
| return hash(id); | ||
| } catch { | ||
| return uuid(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { init } from 'mixpanel'; | ||
| import type { Mixpanel } from 'mixpanel'; | ||
| import * as os from 'os'; | ||
| import * as vscode from 'vscode'; | ||
| import { getMachineId } from './machine-id-utils'; | ||
| import { v5 as uuidv5 } from 'uuid'; | ||
| import { version as extensionVersion } from '../../package.json'; | ||
|
|
||
| export const VSCODE_TELEMETRY_TRACKING_TOKEN = '<VSCODE_TELEMETRY_TRACKING_TOKEN>'; | ||
|
|
||
| export type TelemetryEvents = 'extension:activate' | 'extension:zmodel-preview' | 'extension:zmodel-save'; | ||
|
|
||
| export class VSCodeTelemetry { | ||
| private readonly mixpanel: Mixpanel | undefined; | ||
| private readonly deviceId = this.getDeviceId(); | ||
| private readonly _os_type = os.type(); | ||
| private readonly _os_release = os.release(); | ||
| private readonly _os_arch = os.arch(); | ||
| private readonly _os_version = os.version(); | ||
| private readonly _os_platform = os.platform(); | ||
| private readonly vscodeAppName = vscode.env.appName; | ||
| private readonly vscodeVersion = vscode.version; | ||
| private readonly vscodeAppHost = vscode.env.appHost; | ||
|
|
||
| constructor() { | ||
| if (vscode.env.isTelemetryEnabled) { | ||
| this.mixpanel = init(VSCODE_TELEMETRY_TRACKING_TOKEN, { | ||
| geolocate: true, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private getDeviceId() { | ||
| const hostId = getMachineId(); | ||
| // namespace UUID for generating UUIDv5 from DNS 'zenstack.dev' | ||
| return uuidv5(hostId, '133cac15-3efb-50fa-b5fc-4b90e441e563'); | ||
| } | ||
|
|
||
| track(event: TelemetryEvents, properties: Record<string, unknown> = {}) { | ||
| if (this.mixpanel) { | ||
| const payload = { | ||
| distinct_id: this.deviceId, | ||
| time: new Date(), | ||
| $os: this._os_type, | ||
| osType: this._os_type, | ||
| osRelease: this._os_release, | ||
| osPlatform: this._os_platform, | ||
| osArch: this._os_arch, | ||
| osVersion: this._os_version, | ||
| nodeVersion: process.version, | ||
| vscodeAppName: this.vscodeAppName, | ||
| vscodeVersion: this.vscodeVersion, | ||
| vscodeAppHost: this.vscodeAppHost, | ||
| extensionVersion, | ||
| ...properties, | ||
| }; | ||
| this.mixpanel.track(event, payload); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default new VSCodeTelemetry(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.