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

Commit

Permalink
Merge pull request #12 from microsoft/option-to-disable-telemetry
Browse files Browse the repository at this point in the history
Added option to disable telemetry and notice in readme
  • Loading branch information
pkpio authored Mar 18, 2020
2 parents bf36ba5 + c8246fe commit 6e2f624
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 17 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ The API to use the GitHub action or Azure DevOps task is similar
- `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
- required: false
- default: ''
- `telemetryEnabled`: Set to `false` to disable telemetry
- required: false
- default: 'true'

# Data Collection

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.

To disable data collection when using this extension, set the `telemetryEnabled` input to `false`

# Contributing

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ inputs:
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'
required: false
default: ''
telemetryEnabled:
description: 'Set to `false` to disable telemetry'
required: false
default: 'true'
runs:
using: 'node12'
main: 'dist_gh_action/index.js'
2 changes: 1 addition & 1 deletion ado-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "android-app-size-diff-utils",
"name": "Android app size changes",
"version": "0.0.29",
"version": "0.0.30",
"publisher": "PraveenPendyala",
"targets": [
{
Expand Down
2 changes: 1 addition & 1 deletion dist_gh_action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "android-app-size-diff",
"version": "0.0.29",
"version": "0.0.30",
"description": "Azure DevOps task to measure the size in Android app size by looking at 2 given APKs and AABs",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/adoTask/adoTaskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class AdoTaskRunner {
try {
const adoCiCore = new AdoCiCore();
const ciRunner = new CiRunner(adoCiCore);
await ciRunner.runWithTelemetry();
await ciRunner.run();
}
catch (err) {
adoTask.setResult(adoTask.TaskResult.Failed, err.message);
Expand Down
36 changes: 25 additions & 11 deletions src/apkAnalyzer/CiRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,28 @@ export interface CiCore {
export default class CiRunner {
ciCore: CiCore; // either Github action core or ADO Task
thresholdChecker: ThresholdChecker;
telemetryClient: appInsights.TelemetryClient;

constructor(ciCore: CiCore) {
this.ciCore = ciCore;
this.thresholdChecker = new ThresholdChecker(ciCore);
}

/**
* Runs the ci runner with telemetry enabled if set
*/
public async run() {
const telemetryEnabled = Boolean(JSON.parse(this.ciCore.getInput('telemetryEnabled')));

if (telemetryEnabled) {
console.log("Running with usage telemetry..");
return this.runAppSizeAnalysisWithTelemetry();
} else {
console.log("Running with telemetry disabled..");
return this.runAppSizeAnalysis();
}
}

private async runAppSizeAnalysisWithTelemetry() {
// Configure and enable telemetry
appInsights.setup('0ba004b8-ff05-41fa-a241-3f026d68fc3a') // Change this to your own instrumentation key
.setAutoDependencyCorrelation(true)
Expand All @@ -59,28 +75,26 @@ export default class CiRunner {
.setUseDiskRetryCaching(true)
.setSendLiveMetrics(true)
.start();
this.telemetryClient = appInsights.defaultClient;
}
const telemetryClient = appInsights.defaultClient;

public async runWithTelemetry() {
// Send app start telemetry
const startTime = new Date().getTime();
const telemetryProperties = {
ciName: this.ciCore.getCiName()
}
this.telemetryClient.trackEvent({
telemetryClient.trackEvent({
name: 'RunStarted',
properties: telemetryProperties
});

var result: any;
try {
result = await this.run();
result = await this.runAppSizeAnalysis();

// Send success telemetry
const endTime = new Date().getTime();
const elapsedTime = endTime - startTime;
this.telemetryClient.trackEvent({
telemetryClient.trackEvent({
name: 'RunSuccess',
measurements: {
duration: elapsedTime
Expand All @@ -89,24 +103,24 @@ export default class CiRunner {
});
} catch (err) {
// Send error telemetry
this.telemetryClient.trackEvent({
telemetryClient.trackEvent({
name: 'RunFailed',
properties: telemetryProperties
});
this.telemetryClient.trackException({
telemetryClient.trackException({
exception: err,
properties: telemetryProperties
});

throw err;
} finally {
this.telemetryClient.flush();
telemetryClient.flush();
}

return result;
}

private async run() {
private async runAppSizeAnalysis() {
const baseAppPath = this.ciCore.getInput('baseAppPath');
const targetAppPath = this.ciCore.getInput('targetAppPath');
const baseAppLabel = this.ciCore.getInput('baseAppLabel');
Expand Down
2 changes: 1 addition & 1 deletion src/githubAction/GithubActionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class GithubActionRunner {
try {
const githubCore = new GithubCiCore();
const ciRunner = new CiRunner(githubCore);
await ciRunner.runWithTelemetry();
await ciRunner.run();
}
catch (err) {
ghAction.setFailed(err.message);
Expand Down
10 changes: 9 additions & 1 deletion src/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 0,
"Patch": 29
"Patch": 30
},
"instanceNameFormat": "Android App size change - $(baseAppPath) vs $(targetAppPath)",
"inputs": [
Expand Down Expand Up @@ -69,6 +69,14 @@
"defaultValue": "",
"required": false,
"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."
},
{
"name": "telemetryEnabled",
"type": "string",
"label": "Telemetry enabled",
"defaultValue": "true",
"required": false,
"helpMarkDown": "Set to `false` to disable telemetry"
}
],
"execution": {
Expand Down
1 change: 1 addition & 0 deletions test/adoTask/success.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ tmr.setInput('targetAppLabel', 'Target APK');
tmr.setInput('metrics', 'apkSize, installSize');
tmr.setInput('thresholds', '20, 50');
tmr.setInput('summaryOutputPath', 'dist/test/testReport.md');
tmr.setInput('telemetryEnabled', 'false');

tmr.run();

0 comments on commit 6e2f624

Please sign in to comment.