Respect "telemetry.telemetryLevel" as well as "telemetry.enableTelemetry"#2824
Respect "telemetry.telemetryLevel" as well as "telemetry.enableTelemetry"#2824robertbrignull merged 17 commits intomainfrom
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
| "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.
In the docs it says
Tag your custom telemetry setting with
telemetryandusesOnlineServicesif 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.
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.
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.
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.
| return telemetryListener; | ||
| } | ||
|
|
||
| function isGlobalTelemetryEnabled(): boolean { |
There was a problem hiding this comment.
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.
This method is complicated enough that it would be nice to use existing logic for it.
There was a problem hiding this comment.
I've done some testing of how isTelemetryEnabled behaves. The answer is:
- It does indeed take into account both
telemetry.enableTelemetryandtelemetry.telemetryLevel - It only returns true if telemetry is FULLY enabled. So that means
telemetryLevelis set toall, orenableTelemetryis set totrue. If the level is set toerrorthenisTelemetryEnabledwill 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?
| } | ||
|
|
||
| function isGlobalTelemetryEnabled(): boolean { | ||
| // If "enableTelemetry" is set to false, no telemetry will be sent regardless of the value of "telemetryLevel" |
extensions/ql-vscode/package.json
Outdated
| "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.
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.
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.
| return telemetryListener; | ||
| } | ||
|
|
||
| function isGlobalTelemetryEnabled(): boolean { |
There was a problem hiding this comment.
This method is complicated enough that it would be nice to use existing logic for it.
aeisenberg
left a comment
There was a problem hiding this comment.
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.telemetryLevelsetting, as well as the legacytelemetry.enableTelemetrysetting.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.telemetryLevelbecause we're using thevscode-extension-telemetrypackage. 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 callingsendTelemetryErrorEventfor errors and we were instead usingsendTelemetryEventfor everything.We also weren't respecting
telemetry.telemetryLevelinrequestTelemetryPermissionwhen 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.tsfile that I noticed while doing this.Checklist
ready-for-doc-reviewlabel there.