Skip to content

Commit

Permalink
Add telemetry for subscription information (#761)
Browse files Browse the repository at this point in the history
* Add telemetry for subscription information

* Make method not-async
  • Loading branch information
alexweininger authored Nov 9, 2023
1 parent d32f940 commit f1d332d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/tree/azure/AzureResourceTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { AzureSubscription, getUnauthenticatedTenants } from '@microsoft/vscode-azext-azureauth';
import { IActionContext, registerEvent } from '@microsoft/vscode-azext-utils';
import { IActionContext, callWithTelemetryAndErrorHandling, registerEvent } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { ResourceModelBase } from '../../../api/src/index';
import { AzureResourceProviderManager } from '../../api/ResourceProviderManagers';
Expand Down Expand Up @@ -78,6 +78,7 @@ export class AzureResourceTreeDataProvider extends AzureResourceTreeDataProvider
}
)];
} else if (await subscriptionProvider.isSignedIn()) {
this.sendSubscriptionTelemetryIfNeeded();
let subscriptions: AzureSubscription[];
if ((subscriptions = await subscriptionProvider.getSubscriptions(true)).length === 0) {
if (
Expand Down Expand Up @@ -135,4 +136,34 @@ export class AzureResourceTreeDataProvider extends AzureResourceTreeDataProvider

return undefined;
}

private hasSentSubscriptionTelemetry = false;
private sendSubscriptionTelemetryIfNeeded(): void {
if (this.hasSentSubscriptionTelemetry) {
return;
}
this.hasSentSubscriptionTelemetry = true;

// This event is relied upon by the DevDiv Analytics and Growth Team
void callWithTelemetryAndErrorHandling('updateSubscriptionsAndTenants', async (context: IActionContext) => {
context.telemetry.properties.isActivationEvent = 'true';
context.errorHandling.suppressDisplay = true;

const subscriptionProvider = await this.getAzureSubscriptionProvider();
const subscriptions = await subscriptionProvider.getSubscriptions(false);

const tenantSet = new Set<string>();
const subscriptionSet = new Set<string>();
subscriptions.forEach(sub => {
tenantSet.add(sub.tenantId);
subscriptionSet.add(sub.subscriptionId);
});

// Number of tenants and subscriptions really belong in Measurements but for backwards compatibility
// they will be put into Properties instead.
context.telemetry.properties.numtenants = tenantSet.size.toString();
context.telemetry.properties.numsubscriptions = subscriptionSet.size.toString();
context.telemetry.properties.subscriptions = JSON.stringify(Array.from(subscriptionSet));
});
}
}

0 comments on commit f1d332d

Please sign in to comment.