Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit ab65b6e

Browse files
committed
Refactor telemetry logger
Refactor telemetry logger only to post one usage tracker event `vs/github/usagetracker/increment-counter'. The new event will simplify data classification for GDPR purposes. Counter name and additional attributes are attached as event properties.
1 parent 7262890 commit ab65b6e

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public sealed class UsageTracker : IUsageTracker, IDisposable
1919
{
2020
private const int TelemetryVersion = 1; // Please update the version every time you want to indicate a change in telemetry logic when the extension itself is updated
2121

22-
private const string EventNamePrefix = "vs/github/";
22+
private const string EventNamePrefix = "vs/github/usagetracker/";
2323
private const string PropertyPrefix = "vs.github.";
2424

2525
static class Event
2626
{
27-
public const string UsageTracker = EventNamePrefix + nameof(UsageTracker);
27+
public const string UsageTracker = EventNamePrefix + "increment-counter";
2828
}
2929

3030
static class Property
@@ -41,9 +41,9 @@ static class Property
4141

4242
bool initialized;
4343
IMetricsService client;
44-
IUsageService service;
44+
readonly IUsageService service;
4545
IConnectionManager connectionManager;
46-
IPackageSettings userSettings;
46+
readonly IPackageSettings userSettings;
4747
IVSServices vsservices;
4848
IDisposable timer;
4949
bool firstTick = true;
@@ -75,7 +75,7 @@ public async Task IncrementCounter(Expression<Func<UsageModel.MeasuresModel, int
7575
var counterName = propertyInfo.Name;
7676
log.Verbose("Increment counter {Name}", counterName);
7777

78-
var updateTask = UpdateUsageMetrics(propertyInfo, counterName);
78+
var updateTask = UpdateUsageMetrics(propertyInfo);
7979

8080
LogTelemetryEvent(counterName);
8181

@@ -94,13 +94,19 @@ void LogTelemetryEvent(string counterName)
9494
operation.Properties[Property.TelemetryVersion] = TelemetryVersion;
9595
operation.Properties[Property.CounterName] = counterName;
9696
operation.Properties[Property.ExtensionVersion] = AssemblyVersionInformation.Version;
97-
operation.Properties[Property.IsGitHubUser] = connectionManager.Connections.Any(x => x.HostAddress.IsGitHubDotCom());
98-
operation.Properties[Property.IsEnterpriseUser] = connectionManager.Connections.Any(x => !x.HostAddress.IsGitHubDotCom());
97+
operation.Properties[Property.IsGitHubUser] = IsGitHubUser;
98+
operation.Properties[Property.IsEnterpriseUser] = IsEnterpriseUser;
9999

100100
TelemetryService.DefaultSession.PostEvent(operation);
101101
}
102102

103-
async Task UpdateUsageMetrics(PropertyInfo propertyInfo, string eventName)
103+
bool IsEnterpriseUser =>
104+
this.connectionManager?.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()) ?? false;
105+
106+
bool IsGitHubUser =>
107+
this.connectionManager?.Connections.Any(x => x.HostAddress.IsGitHubDotCom()) ?? false;
108+
109+
async Task UpdateUsageMetrics(PropertyInfo propertyInfo)
104110
{
105111
var data = await service.ReadLocalData();
106112
var usage = await GetCurrentReport(data);
@@ -191,8 +197,8 @@ async Task<UsageModel> GetCurrentReport(UsageData data)
191197
current.Dimensions.AppVersion = AssemblyVersionInformation.Version;
192198
current.Dimensions.VSVersion = vsservices.VSVersion;
193199

194-
current.Dimensions.IsGitHubUser = connectionManager.Connections.Any(x => x.HostAddress.IsGitHubDotCom());
195-
current.Dimensions.IsEnterpriseUser = connectionManager.Connections.Any(x => !x.HostAddress.IsGitHubDotCom());
200+
current.Dimensions.IsGitHubUser = IsGitHubUser;
201+
current.Dimensions.IsEnterpriseUser = IsEnterpriseUser;
196202
return current;
197203
}
198204

0 commit comments

Comments
 (0)