Skip to content

Commit 541d798

Browse files
Merge pull request #1740 from DustinCampbell/tweak-distro-telemetry
Only send telemetry for Linux distros that appears on an approved list
2 parents 14cc9fc + 5764033 commit 541d798

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/CSharpExtDownloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class CSharpExtDownloader
115115
telemetryProps['platform.architecture'] = platformInfo.architecture;
116116
telemetryProps['platform.platform'] = platformInfo.platform;
117117
if (platformInfo.distribution) {
118-
telemetryProps['platform.distribution'] = platformInfo.distribution.toString();
118+
telemetryProps['platform.distribution'] = platformInfo.distribution.toTelemetryString();
119119
}
120120

121121
if (this.reporter) {

src/platform.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as crypto from 'crypto';
67
import * as fs from 'fs';
78
import * as os from 'os';
89
import * as util from './common';
@@ -33,6 +34,34 @@ export class LinuxDistribution {
3334
return `name=${this.name}, version=${this.version}`;
3435
}
3536

37+
/**
38+
* Returns a string representation of LinuxDistribution that only returns the
39+
* distro name if it appears on an allowed list of known distros. Otherwise,
40+
* it returns 'other'.
41+
*/
42+
public toTelemetryString(): string {
43+
const allowedList = [
44+
'antergos', 'arch', 'centos', 'debian', 'deepin', 'elementary', 'fedora',
45+
'galliumos', 'gentoo', 'kali', 'linuxmint', 'manjoro', 'neon', 'opensuse',
46+
'parrot', 'rhel', 'ubuntu', 'zorin'
47+
];
48+
49+
if (this.name === unknown || allowedList.indexOf(this.name) >= 0) {
50+
return this.toString();
51+
}
52+
else {
53+
// Having a hash of the name will be helpful to identify spikes in the 'other'
54+
// bucket when a new distro becomes popular and needs to be added to the
55+
// allowed list above.
56+
const hash = crypto.createHash('sha256');
57+
hash.update(this.name);
58+
59+
const hashedName = hash.digest('hex');
60+
61+
return `other (${hashedName})`;
62+
}
63+
}
64+
3665
private static FromFilePath(filePath: string): Promise<LinuxDistribution> {
3766
return new Promise<LinuxDistribution>((resolve, reject) => {
3867
fs.readFile(filePath, 'utf8', (error, data) => {

0 commit comments

Comments
 (0)