-
Notifications
You must be signed in to change notification settings - Fork 200
Respect "telemetry.telemetryLevel" as well as "telemetry.enableTelemetry" #2824
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
Conversation
I've tried to test this by building the extension and installing it locally, but annoying my telemetry events don't seem to be showing up on the other side. I'll have another go at testing it next week. |
extensions/ql-vscode/package.json
Outdated
@@ -446,7 +446,7 @@ | |||
"type": "boolean", | |||
"default": false, | |||
"scope": "application", | |||
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent to GitHub. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code)" | |||
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the one of the global telemetry settings (`#telemetry.enableTelemetry#` or `#telemetry.telemetryLevel#`) must be enabled for telemetry to be sent to GitHub. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the docs it says
Tag your custom telemetry setting with
telemetry
andusesOnlineServices
if you have one.
But I couldn't quite work out what this means. I need to hunt down the general docs for these settings to see how to add tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what that means either. Do you have a link for where that's said?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this means that we need to add a tags
property to our telemetry configuration options in the package.json
. In this documentation for the configuration contribution points, they give this example:
{
"contributes": {
"configuration": {
"title": "Git",
"properties": {
"git.alwaysSignOff": {
"type": "boolean",
"scope": "resource",
"default": false,
"description": "%config.alwaysSignOff%"
},
"git.ignoredRepositories": {
"type": "array",
"default": [],
"scope": "window",
"description": "%config.ignoredRepositories%"
},
"git.autofetch": {
"type": ["boolean", "string"],
"enum": [true, false, "all"],
"scope": "resource",
"markdownDescription": "%config.autofetch%",
"default": false,
"tags": ["usesOnlineServices"]
}
}
}
}
}
The tags
property doesn't seem to be documented on that page though, so I'm not sure what other tags there are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what that means either. Do you have a link for where that's said?
I read it at https://code.visualstudio.com/api/extension-guides/telemetry#dos-and-donts
In this documentation for the configuration contribution points, they give this example:
Thanks for finding that example. It's a shame there isn't more documentation on this but I think there's enough we can add the tags
field. I believe it shouldn't cause any harm so we may as well add it.
@@ -297,3 +297,21 @@ export async function initializeTelemetry( | |||
ctx.subscriptions.push(telemetryListener); | |||
return telemetryListener; | |||
} | |||
|
|||
function isGlobalTelemetryEnabled(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs suggest not trying to implement this logic ourselves and instead using vscode.env.isTelemetryEnabled
. I haven't yet looked into whether we can actually do that and it does what we want, or if we do indeed have to check both config settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is complicated enough that it would be nice to use existing logic for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done some testing of how isTelemetryEnabled
behaves. The answer is:
- It does indeed take into account both
telemetry.enableTelemetry
andtelemetry.telemetryLevel
- It only returns true if telemetry is FULLY enabled. So that means
telemetryLevel
is set toall
, orenableTelemetry
is set totrue
. If the level is set toerror
thenisTelemetryEnabled
will return false.
Maybe this is fine for us and the CodeQL extension doesn't need the granularity of only sending error reports and not other telemetry. We certainly aren't losing anything with this PR because we weren't checking the level at all before.
Are people happy with this limitation that if telemetryLevel
is set to error
then we won't send any telemetry?
@@ -297,3 +297,21 @@ export async function initializeTelemetry( | |||
ctx.subscriptions.push(telemetryListener); | |||
return telemetryListener; | |||
} | |||
|
|||
function isGlobalTelemetryEnabled(): boolean { | |||
// If "enableTelemetry" is set to false, no telemetry will be sent regardless of the value of "telemetryLevel" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extensions/ql-vscode/package.json
Outdated
@@ -446,7 +446,7 @@ | |||
"type": "boolean", | |||
"default": false, | |||
"scope": "application", | |||
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent to GitHub. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code)" | |||
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the one of the global telemetry settings (`#telemetry.enableTelemetry#` or `#telemetry.telemetryLevel#`) must be enabled for telemetry to be sent to GitHub. For more information, see the [telemetry documentation](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-telemetry-in-codeql-for-visual-studio-code)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what that means either. Do you have a link for where that's said?
// If a value for "telemetry.telemetryLevel" is provided, then use that | ||
const telemetryLevel: string | undefined = GLOBAL_TELEMETRY_LEVEL.getValue(); | ||
if (telemetryLevel !== undefined) { | ||
return telemetryLevel === "error" || telemetryLevel === "on"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I was originally reading https://code.visualstudio.com/updates/v1_61#_telemetry-settings but that's a changelog entry and is apparently not outdated. In my local vscode and some other docs I also see what you see.
@@ -297,3 +297,21 @@ export async function initializeTelemetry( | |||
ctx.subscriptions.push(telemetryListener); | |||
return telemetryListener; | |||
} | |||
|
|||
function isGlobalTelemetryEnabled(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is complicated enough that it would be nice to use existing logic for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot simpler (though still not quite simple). Nice.
Fixing the tests was a little bit involved because:
|
@aeisenberg, are you still ok with this PR or would you like to take another look? All the changes since you last approved have been to test files. My plan is I'll merge this on Monday unless I see/hear reasons not to. |
Also see the update to the docs: github/codeql#14408 |
Sorry...I missed this. This looks fine to me. |
This PR tries to make our telemetry better behaved and to fully support the
telemetry.telemetryLevel
setting, as well as the legacytelemetry.enableTelemetry
setting.Unfortunately it's a bit hard to work out the intended semantics of the settings. I've been using the following as reference:
I think we were already partially supporting
telemetry.telemetryLevel
because we're using thevscode-extension-telemetry
package. This means it'll only send telemetry when the global settings are enabled. I think we weren't correctly supportingtelemetryLevel: "error"
though because we weren't callingsendTelemetryErrorEvent
for errors and we were instead usingsendTelemetryEvent
for everything.We also weren't respecting
telemetry.telemetryLevel
inrequestTelemetryPermission
when deciding whether or not to prompt the user to enable telemtry for our extension. If the user has settelemetryLevel: "off"
we should now no longer prompt the user.I also clear up a couple of small unrelated things in the
telemetry.ts
file that I noticed while doing this.Checklist
ready-for-doc-review
label there.