Log resource telemetry also for side-by-side views on browsers. (#208196)

* Log `resource` telemetry also for side-by-side views on browsers.

This telemetry is already logged in non-browser environments, and for the regular text editor (and other editors with a single document), but not yet for editors dealing with multiple documents, like "workbench.editors.diffEditorInput".

It is useful to have this telemetry to check how much e.g. the diff editor is used to open certain file types.

Fixes #208187

* Use URI.isUri instead of instanceof URI.
This commit is contained in:
Ole 2024-03-22 18:22:32 +01:00 committed by GitHub
parent 58368c444e
commit 385ad93dd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -660,17 +660,27 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
return true;
}
private toResourceTelemetryDescriptor(resource: URI): object | undefined {
if (!resource) {
return undefined;
}
const path = resource ? resource.scheme === Schemas.file ? resource.fsPath : resource.path : undefined;
if (!path) {
return undefined;
}
let resourceExt = extname(resource);
// Remove query parameters from the resource extension
const queryStringLocation = resourceExt.indexOf('?');
resourceExt = queryStringLocation !== -1 ? resourceExt.substr(0, queryStringLocation) : resourceExt;
return { mimeType: new TelemetryTrustedValue(getMimeTypes(resource).join(', ')), scheme: resource.scheme, ext: resourceExt, path: hash(path) };
}
private toEditorTelemetryDescriptor(editor: EditorInput): object {
const descriptor = editor.getTelemetryDescriptor();
const resource = EditorResourceAccessor.getOriginalUri(editor);
const path = resource ? resource.scheme === Schemas.file ? resource.fsPath : resource.path : undefined;
if (resource && path) {
let resourceExt = extname(resource);
// Remove query parameters from the resource extension
const queryStringLocation = resourceExt.indexOf('?');
resourceExt = queryStringLocation !== -1 ? resourceExt.substr(0, queryStringLocation) : resourceExt;
descriptor['resource'] = { mimeType: new TelemetryTrustedValue(getMimeTypes(resource).join(', ')), scheme: resource.scheme, ext: resourceExt, path: hash(path) };
const resource = EditorResourceAccessor.getOriginalUri(editor, { supportSideBySide: SideBySideEditor.BOTH });
if (URI.isUri(resource)) {
descriptor['resource'] = this.toResourceTelemetryDescriptor(resource);
/* __GDPR__FRAGMENT__
"EditorTelemetryDescriptor" : {
@ -678,6 +688,20 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}
*/
return descriptor;
} else if (resource) {
if (resource.primary) {
descriptor['resource'] = this.toResourceTelemetryDescriptor(resource.primary);
}
if (resource.secondary) {
descriptor['resourceSecondary'] = this.toResourceTelemetryDescriptor(resource.secondary);
}
/* __GDPR__FRAGMENT__
"EditorTelemetryDescriptor" : {
"resource": { "${inline}": [ "${URIDescriptor}" ] }
"resourceSecondary": { "${inline}": [ "${URIDescriptor}" ] }
}
*/
return descriptor;
}
return descriptor;