Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 6e2f624

Browse files
authored
Merge pull request #12 from microsoft/option-to-disable-telemetry
Added option to disable telemetry and notice in readme
2 parents bf36ba5 + c8246fe commit 6e2f624

File tree

10 files changed

+53
-17
lines changed

10 files changed

+53
-17
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ The API to use the GitHub action or Azure DevOps task is similar
5454
- `thresholds`: A comma seperated list of thresholds for each of the metrics in bytes. If this is empty, no thresholding will apply. When this is not empty, the task will fail when any of the given thresholds are crossed
5555
- required: false
5656
- default: ''
57+
- `telemetryEnabled`: Set to `false` to disable telemetry
58+
- required: false
59+
- default: 'true'
60+
61+
# Data Collection
62+
63+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
64+
65+
To disable data collection when using this extension, set the `telemetryEnabled` input to `false`
5766

5867
# Contributing
5968

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ inputs:
3232
description: 'A comma seperated list of thresholds for each of the metrics in bytes. If this is empty, no thresholding will apply. When this is not empty, the task will fail when any of the given thresholds are crossed'
3333
required: false
3434
default: ''
35+
telemetryEnabled:
36+
description: 'Set to `false` to disable telemetry'
37+
required: false
38+
default: 'true'
3539
runs:
3640
using: 'node12'
3741
main: 'dist_gh_action/index.js'

ado-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "android-app-size-diff-utils",
44
"name": "Android app size changes",
5-
"version": "0.0.29",
5+
"version": "0.0.30",
66
"publisher": "PraveenPendyala",
77
"targets": [
88
{

dist_gh_action/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "android-app-size-diff",
3-
"version": "0.0.29",
3+
"version": "0.0.30",
44
"description": "Azure DevOps task to measure the size in Android app size by looking at 2 given APKs and AABs",
55
"main": "index.js",
66
"scripts": {

src/adoTask/adoTaskRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class AdoTaskRunner {
4040
try {
4141
const adoCiCore = new AdoCiCore();
4242
const ciRunner = new CiRunner(adoCiCore);
43-
await ciRunner.runWithTelemetry();
43+
await ciRunner.run();
4444
}
4545
catch (err) {
4646
adoTask.setResult(adoTask.TaskResult.Failed, err.message);

src/apkAnalyzer/CiRunner.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,28 @@ export interface CiCore {
4242
export default class CiRunner {
4343
ciCore: CiCore; // either Github action core or ADO Task
4444
thresholdChecker: ThresholdChecker;
45-
telemetryClient: appInsights.TelemetryClient;
4645

4746
constructor(ciCore: CiCore) {
4847
this.ciCore = ciCore;
4948
this.thresholdChecker = new ThresholdChecker(ciCore);
49+
}
5050

51+
/**
52+
* Runs the ci runner with telemetry enabled if set
53+
*/
54+
public async run() {
55+
const telemetryEnabled = Boolean(JSON.parse(this.ciCore.getInput('telemetryEnabled')));
56+
57+
if (telemetryEnabled) {
58+
console.log("Running with usage telemetry..");
59+
return this.runAppSizeAnalysisWithTelemetry();
60+
} else {
61+
console.log("Running with telemetry disabled..");
62+
return this.runAppSizeAnalysis();
63+
}
64+
}
65+
66+
private async runAppSizeAnalysisWithTelemetry() {
5167
// Configure and enable telemetry
5268
appInsights.setup('0ba004b8-ff05-41fa-a241-3f026d68fc3a') // Change this to your own instrumentation key
5369
.setAutoDependencyCorrelation(true)
@@ -59,28 +75,26 @@ export default class CiRunner {
5975
.setUseDiskRetryCaching(true)
6076
.setSendLiveMetrics(true)
6177
.start();
62-
this.telemetryClient = appInsights.defaultClient;
63-
}
78+
const telemetryClient = appInsights.defaultClient;
6479

65-
public async runWithTelemetry() {
6680
// Send app start telemetry
6781
const startTime = new Date().getTime();
6882
const telemetryProperties = {
6983
ciName: this.ciCore.getCiName()
7084
}
71-
this.telemetryClient.trackEvent({
85+
telemetryClient.trackEvent({
7286
name: 'RunStarted',
7387
properties: telemetryProperties
7488
});
7589

7690
var result: any;
7791
try {
78-
result = await this.run();
92+
result = await this.runAppSizeAnalysis();
7993

8094
// Send success telemetry
8195
const endTime = new Date().getTime();
8296
const elapsedTime = endTime - startTime;
83-
this.telemetryClient.trackEvent({
97+
telemetryClient.trackEvent({
8498
name: 'RunSuccess',
8599
measurements: {
86100
duration: elapsedTime
@@ -89,24 +103,24 @@ export default class CiRunner {
89103
});
90104
} catch (err) {
91105
// Send error telemetry
92-
this.telemetryClient.trackEvent({
106+
telemetryClient.trackEvent({
93107
name: 'RunFailed',
94108
properties: telemetryProperties
95109
});
96-
this.telemetryClient.trackException({
110+
telemetryClient.trackException({
97111
exception: err,
98112
properties: telemetryProperties
99113
});
100114

101115
throw err;
102116
} finally {
103-
this.telemetryClient.flush();
117+
telemetryClient.flush();
104118
}
105119

106120
return result;
107121
}
108122

109-
private async run() {
123+
private async runAppSizeAnalysis() {
110124
const baseAppPath = this.ciCore.getInput('baseAppPath');
111125
const targetAppPath = this.ciCore.getInput('targetAppPath');
112126
const baseAppLabel = this.ciCore.getInput('baseAppLabel');

src/githubAction/GithubActionRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class GithubActionRunner {
4040
try {
4141
const githubCore = new GithubCiCore();
4242
const ciRunner = new CiRunner(githubCore);
43-
await ciRunner.runWithTelemetry();
43+
await ciRunner.run();
4444
}
4545
catch (err) {
4646
ghAction.setFailed(err.message);

src/task.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"version": {
1111
"Major": 0,
1212
"Minor": 0,
13-
"Patch": 29
13+
"Patch": 30
1414
},
1515
"instanceNameFormat": "Android App size change - $(baseAppPath) vs $(targetAppPath)",
1616
"inputs": [
@@ -69,6 +69,14 @@
6969
"defaultValue": "",
7070
"required": false,
7171
"helpMarkDown": "A comma seperated list of thresholds for each of the metrics in bytes. If this is empty, no thresholding will apply. When this is not empty, the task will fail when any of the given thresholds are crossed."
72+
},
73+
{
74+
"name": "telemetryEnabled",
75+
"type": "string",
76+
"label": "Telemetry enabled",
77+
"defaultValue": "true",
78+
"required": false,
79+
"helpMarkDown": "Set to `false` to disable telemetry"
7280
}
7381
],
7482
"execution": {

test/adoTask/success.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ tmr.setInput('targetAppLabel', 'Target APK');
1212
tmr.setInput('metrics', 'apkSize, installSize');
1313
tmr.setInput('thresholds', '20, 50');
1414
tmr.setInput('summaryOutputPath', 'dist/test/testReport.md');
15+
tmr.setInput('telemetryEnabled', 'false');
1516

1617
tmr.run();

0 commit comments

Comments
 (0)