Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Only send telemetry events if not disabled in settings.json #55

Merged
merged 3 commits into from
Jul 19, 2019

Conversation

jonathanwangg
Copy link
Contributor

Description:

Using the telemetry.enableTelemetry property in the User level settings.json (which is accessed in Preferences), the user can disable telemetry and telemetry events will not be sent.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update (Update to CELA telemetry documentation)

Testing:

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Run a command (e.g Open Simulator) with telemetry enabled (you don't have to do anything since it is enabled by default) and make sure that https://portal.azure.com/ logs your telemetry event.
  • Run a command (e.g. Open Simulator) with telemetry disabled (set telemetry.enableTelemetry to false in the User level settings.json) and make sure that https://portal.azure.com/ does NOT log your telemetry event.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules


constructor(vscodeContext: vscode.ExtensionContext) {
TelemetryAI.telemetryReporter = this.createTelemetryReporter(vscodeContext);
TelemetryAI.enableTelemetry = vscode.workspace.getConfiguration().get("telemetry.enableTelemetry");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need this to be instantiated for this to work, can we make the methods not static and then just have a global telemetry reporter in extension rather than instantiating a reporter and then using static methods? Because that's pretty funky

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline, will make the telemetry reporter a global which will change the way how telemetry events are being sent.

@@ -5,7 +5,9 @@ import getPackageInfo from "./getPackageInfo";
// tslint:disable-next-line:export-name
export default class TelemetryAI {
public static trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) {
TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, eventProperties);
if (TelemetryAI.enableTelemetry) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if there as few 'if' checks on TelemetryAI.enableTelemetry as possible. Can you find a way to put the check somewhere in TelemetryAI.telemetryReporter so that it is more automatic? Or make a dummy telemetryReporter object that does nothing when telemetry is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a look into this, but will probably need your input after I re-write it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, ideally with a single point of telemetry you should only check in one place if it is enabled. Having that code all over the place duplicated makes it a maintenance challenge.

@@ -5,7 +5,9 @@ import getPackageInfo from "./getPackageInfo";
// tslint:disable-next-line:export-name
export default class TelemetryAI {
public static trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) {
TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, eventProperties);
if (TelemetryAI.enableTelemetry) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, ideally with a single point of telemetry you should only check in one place if it is enabled. Having that code all over the place duplicated makes it a maintenance challenge.

@@ -35,8 +25,25 @@ export default class TelemetryAI {
return extensionVersion;
}

public trackEventTime(eventName: string, startTime: number, endTime: number = Date.now(), eventProperties?: { [key: string]: string }) {
this.trackTimeDuration(eventName, startTime, endTime, eventProperties);
public sendTelemetryIfEnabled(eventName: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Member

@LukeSlev LukeSlev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonathanwangg jonathanwangg merged commit 1b268ff into dev Jul 19, 2019
@jonathanwangg jonathanwangg deleted the users/t-jowang/disable-telemetry branch August 7, 2019 22:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants