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

Commit f982853

Browse files
committed
Only use VS Telemetry in Essentials extension
Change VisualStudioUsageTracker to accept a Lazy<IConnectionManager> so that we don't need to create a live object on initialization.
1 parent a9f2f22 commit f982853

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

src/GitHub.VisualStudio.16/CompositionServices.cs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel;
43
using System.ComponentModel.Composition;
54
using System.ComponentModel.Composition.Hosting;
65
using System.ComponentModel.Composition.Primitives;
@@ -9,8 +8,6 @@
98
using System.Reflection;
109
using GitHub.Api;
1110
using GitHub.Services;
12-
using GitHub.Settings;
13-
using GitHub.VisualStudio.Settings;
1411
using GitHub.VisualStudio.Views.Dialog.Clone;
1512
using Microsoft;
1613
using Microsoft.VisualStudio.Shell;
@@ -55,10 +52,7 @@ CompositionContainer CreateCompositionContainer()
5552
static CompositionContainer CreateVisualStudioCompositionContainer(ExportProvider defaultExportProvider)
5653
{
5754
var compositionContainer = CreateCompositionContainer(defaultExportProvider);
58-
59-
var gitHubServiceProvider = compositionContainer.GetExportedValue<IGitHubServiceProvider>();
60-
var packageSettings = new PackageSettings(gitHubServiceProvider);
61-
var usageTracker = UsageTrackerFactory.CreateUsageTracker(compositionContainer, packageSettings);
55+
var usageTracker = CreateUsageTracker(compositionContainer);
6256
compositionContainer.ComposeExportedValue(usageTracker);
6357

6458
return compositionContainer;
@@ -67,23 +61,16 @@ static CompositionContainer CreateVisualStudioCompositionContainer(ExportProvide
6761
static CompositionContainer CreateOutOfProcCompositionContainer()
6862
{
6963
var compositionContainer = CreateCompositionContainer(CreateOutOfProcExports());
70-
71-
var packageSettings = new OutOfProcPackageSettings();
72-
var usageTracker = UsageTrackerFactory.CreateUsageTracker(compositionContainer, packageSettings);
64+
var usageTracker = CreateUsageTracker(compositionContainer);
7365
compositionContainer.ComposeExportedValue(usageTracker);
7466

7567
return compositionContainer;
7668
}
7769

78-
class UsageTrackerFactory
70+
static IUsageTracker CreateUsageTracker(CompositionContainer compositionContainer)
7971
{
80-
internal static IUsageTracker CreateUsageTracker(CompositionContainer compositionContainer, IPackageSettings packageSettings)
81-
{
82-
var gitHubServiceProvider = compositionContainer.GetExportedValue<IGitHubServiceProvider>();
83-
var usageService = compositionContainer.GetExportedValue<IUsageService>();
84-
var joinableTaskContext = compositionContainer.GetExportedValue<JoinableTaskContext>();
85-
return new UsageTracker(gitHubServiceProvider, usageService, packageSettings, joinableTaskContext, vsTelemetry: true);
86-
}
72+
var connectionManager = compositionContainer.GetExport<IConnectionManager>();
73+
return new VisualStudioUsageTracker(connectionManager);
8774
}
8875

8976
static CompositionContainer CreateOutOfProcExports()
@@ -270,22 +257,6 @@ public object TryGetService(string typeName)
270257
public ExportProvider ExportProvider { get; }
271258
}
272259

273-
public class OutOfProcPackageSettings : IPackageSettings
274-
{
275-
public bool CollectMetrics { get; set; } = true;
276-
public bool EnableTraceLogging { get; set; } = true;
277-
public bool EditorComments { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
278-
public UIState UIState { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
279-
public bool HideTeamExplorerWelcomeMessage { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
280-
281-
public event PropertyChangedEventHandler PropertyChanged;
282-
283-
public void Save()
284-
{
285-
throw new NotImplementedException();
286-
}
287-
}
288-
289260
class OutOfProcSVsServiceProvider : SVsServiceProvider
290261
{
291262
public object GetService(Type serviceType)

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class UsageTracker : IUsageTracker, IDisposable
2121
bool initialized;
2222
IMetricsService client;
2323
readonly IUsageService service;
24-
IConnectionManager connectionManager;
24+
Lazy<IConnectionManager> connectionManager;
2525
readonly IPackageSettings userSettings;
2626
readonly bool vsTelemetry;
2727
IVSServices vsservices;
@@ -71,10 +71,10 @@ public async Task IncrementCounter(Expression<Func<UsageModel.MeasuresModel, int
7171
}
7272

7373
bool IsEnterpriseUser =>
74-
this.connectionManager?.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()) ?? false;
74+
connectionManager.Value?.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()) ?? false;
7575

7676
bool IsGitHubUser =>
77-
this.connectionManager?.Connections.Any(x => x.HostAddress.IsGitHubDotCom()) ?? false;
77+
connectionManager.Value?.Connections.Any(x => x.HostAddress.IsGitHubDotCom()) ?? false;
7878

7979
async Task UpdateUsageMetrics(PropertyInfo propertyInfo)
8080
{
@@ -102,7 +102,7 @@ async Task Initialize()
102102
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
103103

104104
client = gitHubServiceProvider.TryGetService<IMetricsService>();
105-
connectionManager = gitHubServiceProvider.GetService<IConnectionManager>();
105+
connectionManager = new Lazy<IConnectionManager>(() => gitHubServiceProvider.GetService<IConnectionManager>());
106106
vsservices = gitHubServiceProvider.GetService<IVSServices>();
107107

108108
if (vsTelemetry)

src/GitHub.VisualStudio/Services/VisualStudioUsageTracker.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public sealed class VisualStudioUsageTracker : IUsageTracker
2121
const string EventNamePrefix = "vs/github/usagetracker/";
2222
const string PropertyPrefix = "vs.github.";
2323

24-
readonly IConnectionManager connectionManager;
24+
readonly Lazy<IConnectionManager> connectionManager;
2525

26-
public VisualStudioUsageTracker(IConnectionManager connectionManager)
26+
public VisualStudioUsageTracker(Lazy<IConnectionManager> connectionManager)
2727
{
2828
this.connectionManager = connectionManager;
2929
}
@@ -57,10 +57,10 @@ void LogTelemetryEvent(string counterName)
5757
}
5858

5959
bool IsEnterpriseUser =>
60-
connectionManager?.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()) ?? false;
60+
connectionManager.Value?.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()) ?? false;
6161

6262
bool IsGitHubUser =>
63-
connectionManager?.Connections.Any(x => x.HostAddress.IsGitHubDotCom()) ?? false;
63+
connectionManager.Value?.Connections.Any(x => x.HostAddress.IsGitHubDotCom()) ?? false;
6464

6565
static class Event
6666
{

0 commit comments

Comments
 (0)