Add option to enable VS Telemetry on UsageTracker

Make GitHubPackage responsible for enabling VS Telemetry on VS 2017 and
above.
This commit is contained in:
Jamie Cansdale 2019-09-30 13:06:08 +01:00
Родитель 40c2635d6a
Коммит 607bec23f9
4 изменённых файлов: 22 добавлений и 11 удалений

Просмотреть файл

@ -82,7 +82,7 @@ namespace GitHub.VisualStudio
var gitHubServiceProvider = compositionContainer.GetExportedValue<IGitHubServiceProvider>();
var usageService = compositionContainer.GetExportedValue<IUsageService>();
var joinableTaskContext = compositionContainer.GetExportedValue<JoinableTaskContext>();
return new UsageTracker(gitHubServiceProvider, usageService, packageSettings, joinableTaskContext);
return new UsageTracker(gitHubServiceProvider, usageService, packageSettings, joinableTaskContext, vsTelemetry: true);
}
}

Просмотреть файл

@ -393,7 +393,13 @@ namespace GitHub.VisualStudio
Assumes.Present(serviceProvider);
Assumes.Present(settings);
return new UsageTracker(serviceProvider, usageService, settings, ThreadHelper.JoinableTaskContext);
// Only use Visual Studio Telemetry on VS 2017 and above
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
Assumes.Present(dte);
var vsTelemetry = new Version(dte.Version) >= new Version(15, 0);
return new UsageTracker(serviceProvider, usageService, settings, ThreadHelper.JoinableTaskContext, vsTelemetry);
}
else if (serviceType == typeof(IVSGitExt))
{

Просмотреть файл

@ -23,6 +23,7 @@ namespace GitHub.Services
readonly IUsageService service;
IConnectionManager connectionManager;
readonly IPackageSettings userSettings;
readonly bool vsTelemetry;
IVSServices vsservices;
IUsageTracker visualStudioUsageTracker;
IDisposable timer;
@ -32,12 +33,15 @@ namespace GitHub.Services
IGitHubServiceProvider gitHubServiceProvider,
IUsageService service,
IPackageSettings settings,
JoinableTaskContext joinableTaskContext)
JoinableTaskContext joinableTaskContext,
bool vsTelemetry)
{
this.gitHubServiceProvider = gitHubServiceProvider;
this.service = service;
this.userSettings = settings;
JoinableTaskContext = joinableTaskContext;
this.vsTelemetry = vsTelemetry;
timer = StartTimer();
}
@ -101,9 +105,7 @@ namespace GitHub.Services
connectionManager = gitHubServiceProvider.GetService<IConnectionManager>();
vsservices = gitHubServiceProvider.GetService<IVSServices>();
// Only create VisualStudioUsageTracker on Visual Studio 2017 and above
var dte = gitHubServiceProvider.GetService<EnvDTE.DTE>();
if (new Version(dte.Version) >= new Version(15, 0))
if (vsTelemetry)
{
log.Verbose("Creating VisualStudioUsageTracker");
visualStudioUsageTracker = new VisualStudioUsageTracker(connectionManager);

Просмотреть файл

@ -24,7 +24,7 @@ namespace MetricsTests
public void ShouldStartTimer()
{
var service = Substitute.For<IUsageService>();
var target = new UsageTracker(CreateServiceProvider(), service, CreatePackageSettings(), new JoinableTaskContext());
var target = new UsageTracker(CreateServiceProvider(), service, CreatePackageSettings(), new JoinableTaskContext(), vsTelemetry: false);
service.Received(1).StartTimer(Arg.Any<Func<Task>>(), TimeSpan.FromMinutes(3), TimeSpan.FromDays(1));
}
@ -111,7 +111,8 @@ namespace MetricsTests
CreateServiceProvider(),
usageService,
CreatePackageSettings(),
new JoinableTaskContext());
new JoinableTaskContext(),
vsTelemetry: false);
await target.IncrementCounter(x => x.NumberOfClones);
UsageData result = usageService.ReceivedCalls().First(x => x.GetMethodInfo().Name == "WriteLocalData").GetArguments()[0] as UsageData;
@ -128,7 +129,8 @@ namespace MetricsTests
CreateServiceProvider(),
service,
CreatePackageSettings(),
new JoinableTaskContext());
new JoinableTaskContext(),
vsTelemetry: false);
await target.IncrementCounter(x => x.NumberOfClones);
await service.Received(1).WriteLocalData(Arg.Is<UsageData>(data =>
@ -155,7 +157,8 @@ namespace MetricsTests
CreateServiceProvider(),
service,
CreatePackageSettings(),
new JoinableTaskContext());
new JoinableTaskContext(),
vsTelemetry: false);
await target.IncrementCounter(x => x.NumberOfClones);
await service.Received(1).WriteLocalData(Arg.Is<UsageData>(data =>
@ -177,7 +180,7 @@ namespace MetricsTests
service.WhenForAnyArgs(x => x.StartTimer(null, new TimeSpan(), new TimeSpan()))
.Do(x => tick = x.ArgAt<Func<Task>>(0));
var target = new UsageTracker(serviceProvider, service, CreatePackageSettings(), new JoinableTaskContext());
var target = new UsageTracker(serviceProvider, service, CreatePackageSettings(), new JoinableTaskContext(), vsTelemetry: false);
return Tuple.Create(target, tick);
}