Skip to content

Commit

Permalink
feature: Add ApplicationInsights telemetry (gitextensions#6522)
Browse files Browse the repository at this point in the history
feature: Add ApplicationInsights telemetry
  • Loading branch information
RussKie authored Jul 5, 2019
2 parents 869be49 + 5f807aa commit 98b3915
Show file tree
Hide file tree
Showing 31 changed files with 648 additions and 27 deletions.
37 changes: 37 additions & 0 deletions Bin/set-telemetry.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[CmdletBinding()]
Param(
[string] $Enabled = ''
)

[bool]$telemetryEnabled = -not [string]::IsNullOrWhiteSpace($Enabled);

[string]$userAppDataPath = Join-Path -Path $env:APPDATA -ChildPath 'GitExtensions\GitExtensions\GitExtensions.settings'
if (-not (Test-Path -Path $userAppDataPath)) {
'<?xml version="1.0" encoding="utf-8"?><dictionary />' | Out-File $userAppDataPath -Encoding utf8
}

[xml]$doc = Get-Content $userAppDataPath
if (!$doc) {
$doc = '<?xml version="1.0" encoding="utf-8"?>';
}

$node = $doc.SelectSingleNode("/dictionary/item/key/string[text()='TelemetryEnabled']")
if ($node -ne $null) {
$node.ParentNode.ParentNode.value.string = "$telemetryEnabled";
$doc.Save($userAppDataPath)
exit 0
}

$topNode = $doc.SelectSingleNode("/dictionary");
if ($topNode -eq $null) {
$topNode = $doc.CreateElement('dictionary');
$_ = $doc.AppendChild($topNode);
}

$node = $doc.CreateElement('item');
$node.InnerXml = "<key><string>TelemetryEnabled</string></key><value><string>$telemetryEnabled</string></value>";
$_ = $topNode.AppendChild($node);
$doc.Save($userAppDataPath)

# this script now deletes itself
Remove-Item $MyINvocation.InvocationName
6 changes: 6 additions & 0 deletions GitCommands/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ static AppSettings()
}
}

public static bool? TelemetryEnabled
{
get => GetBool("TelemetryEnabled");
set => SetBool("TelemetryEnabled", value);
}

public static bool AutoNormaliseBranchName
{
get => GetBool("AutoNormaliseBranchName", true);
Expand Down
2 changes: 2 additions & 0 deletions GitExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
GitExtensions.ruleset = GitExtensions.ruleset
GitExtensionsTest.ruleset = GitExtensionsTest.ruleset
LICENSE.md = LICENSE.md
PrivacyPolicy.rtf = PrivacyPolicy.rtf
PrivacyPolicy.md = PrivacyPolicy.md
README.md = README.md
EndProjectSection
EndProject
Expand Down
12 changes: 12 additions & 0 deletions GitExtensions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
using GitUI;
using GitUI.CommandsDialogs.SettingsDialog;
using GitUI.CommandsDialogs.SettingsDialog.Pages;
using GitUI.Infrastructure.Telemetry;
using JetBrains.Annotations;
using Microsoft.VisualStudio.Threading;
using ResourceManager;

namespace GitExtensions
{
Expand All @@ -29,6 +31,8 @@ private static void Main()

try
{
DiagnosticsClient.Initialize(ThisAssembly.Git.IsDirty);

if (!Debugger.IsAttached)
{
AppDomain.CurrentDomain.UnhandledException += (s, e) => ReportBug((Exception)e.ExceptionObject);
Expand Down Expand Up @@ -67,6 +71,7 @@ private static void RunApplication()
}

AppSettings.LoadSettings();

if (EnvUtils.RunningOnWindows())
{
WebBrowserEmulationMode.SetBrowserFeatureControl();
Expand All @@ -81,6 +86,13 @@ private static void RunApplication()
}
}

if (!AppSettings.TelemetryEnabled.HasValue)
{
AppSettings.TelemetryEnabled = MessageBox.Show(null, Strings.TelemetryPermissionMessage,
Strings.TelemetryPermissionCaption, MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes;
}

try
{
// Ensure we can find the git command to execute,
Expand Down
19 changes: 19 additions & 0 deletions GitUI/ApplicationInsights.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<InstrumentationKey>3d09f612-9640-4682-829c-3f6ac1ed3e86</InstrumentationKey>
<TelemetryInitializers>
<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.DeviceTelemetryInitializer, AppInsights.WindowsDesktop"/>
<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.SessionTelemetryInitializer, AppInsights.WindowsDesktop"/>
<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.VersionTelemetryInitializer, AppInsights.WindowsDesktop"/>
</TelemetryInitializers>
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.DeveloperModeWithDebuggerAttachedTelemetryModule, AppInsights.WindowsDesktop"/>
<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.UnhandledExceptionTelemetryModule, AppInsights.WindowsDesktop"/>
<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.UnobservedExceptionTelemetryModule, AppInsights.WindowsDesktop" />
<!--<Add Type="Microsoft.ApplicationInsights.WindowsDesktop.FirstChanceExceptionStatisticsTelemetryModule, AppInsights.WindowsDesktop" />-->
</TelemetryModules>
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.Extensibility.AutocollectedMetricsExtractor, Microsoft.ApplicationInsights"/>
</TelemetryProcessors>
<TelemetryChannel Type="Microsoft.ApplicationInsights.Channel.PersistenceChannel, AppInsights.WindowsDesktop"/>
</ApplicationInsights>
25 changes: 23 additions & 2 deletions GitUI/CommandsDialogs/FormBrowse.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 33 additions & 7 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using GitUI.CommandsDialogs.BrowseDialog.DashboardControl;
using GitUI.CommandsDialogs.WorktreeDialog;
using GitUI.Hotkey;
using GitUI.Infrastructure.Telemetry;
using GitUI.Properties;
using GitUI.Script;
using GitUI.UserControls;
Expand Down Expand Up @@ -85,6 +86,7 @@ public sealed partial class FormBrowse : GitModuleForm, IBrowseRepo

private readonly TranslationString _undoLastCommitText = new TranslationString("You will still be able to find all the commit's changes in the staging area\n\nDo you want to continue?");
private readonly TranslationString _undoLastCommitCaption = new TranslationString("Undo last commit");

#endregion

private readonly SplitterManager _splitterManager = new SplitterManager(new AppSettingsPath("FormBrowse"));
Expand All @@ -99,7 +101,7 @@ public sealed partial class FormBrowse : GitModuleForm, IBrowseRepo
[CanBeNull] private readonly IAheadBehindDataProvider _aheadBehindDataProvider;
private readonly WindowsJumpListManager _windowsJumpListManager;
private readonly SubmoduleStatusProvider _submoduleStatusProvider;

private readonly FormBrowseDiagnosticsReporter _formBrowseDiagnosticsReporter;
[CanBeNull] private BuildReportTabPageExtension _buildReportTabPageExtension;
private ConEmuControl _terminal;
private Dashboard _dashboard;
Expand Down Expand Up @@ -137,6 +139,8 @@ public FormBrowse([NotNull] GitUICommands commands, string filter, ObjectId sele
recoverLostObjectsToolStripMenuItem.Image = light ? Images.RecoverLostObjects : Images.RecoverLostObjects_inv;
branchSelect.Image = light ? Resources.branch : Resources.branch_inv;

_formBrowseDiagnosticsReporter = new FormBrowseDiagnosticsReporter(this);

commandsToolStripMenuItem.DropDownOpening += CommandsToolStripMenuItem_DropDownOpening;

MainSplitContainer.Visible = false;
Expand Down Expand Up @@ -522,6 +526,8 @@ protected override void OnLoad(EventArgs e)
toolStripButtonPush.Initialize(_aheadBehindDataProvider);
toolStripButtonPush.DisplayAheadBehindInformation(Module.GetSelectedBranch());

_formBrowseDiagnosticsReporter.Report();

base.OnLoad(e);
}

Expand Down Expand Up @@ -656,6 +662,8 @@ private void ShowDashboard()
_dashboard.RefreshContent();
_dashboard.Visible = true;
_dashboard.BringToFront();

DiagnosticsClient.TrackPageView("Dashboard");
}

private void HideDashboard()
Expand All @@ -673,6 +681,8 @@ private void HideDashboard()
toolPanel.LeftToolStripPanelVisible = true;
toolPanel.RightToolStripPanelVisible = true;
toolPanel.ResumeLayout();

DiagnosticsClient.TrackPageView("Revision graph");
}

private void UpdatePluginMenu(bool validWorkingDir)
Expand Down Expand Up @@ -1320,12 +1330,6 @@ private void PushToolStripMenuItemClick(object sender, EventArgs e)
UICommands.StartPushDialog(this, pushOnShow: ModifierKeys.HasFlag(Keys.Shift));
}

private void RefreshStatus()
{
UpdateSubmodulesStructure();
UpdateStashCount();
}

private void RefreshToolStripMenuItemClick(object sender, EventArgs e)
{
// Broadcast RepoChanged in case repo was changed outside of GE
Expand Down Expand Up @@ -3023,12 +3027,18 @@ private void toolStripMenuItemReflog_Click(object sender, EventArgs e)
private void toggleSplitViewLayout_Click(object sender, EventArgs e)
{
AppSettings.ShowSplitViewLayout = !AppSettings.ShowSplitViewLayout;
DiagnosticsClient.TrackEvent("Layout change",
new Dictionary<string, string> { { nameof(AppSettings.ShowSplitViewLayout), AppSettings.ShowSplitViewLayout.ToString() } });

RefreshSplitViewLayout();
}

private void toggleBranchTreePanel_Click(object sender, EventArgs e)
{
MainSplitContainer.Panel1Collapsed = !MainSplitContainer.Panel1Collapsed;
DiagnosticsClient.TrackEvent("Layout change",
new Dictionary<string, string> { { "ShowLeftPanel", MainSplitContainer.Panel1Collapsed.ToString() } });

RefreshLayoutToggleButtonStates();
}

Expand All @@ -3054,13 +3064,19 @@ private void CommitInfoRightwardClick(object sender, EventArgs e) =>
private void SetCommitInfoPosition(CommitInfoPosition position)
{
AppSettings.CommitInfoPosition = position;
DiagnosticsClient.TrackEvent("Layout change",
new Dictionary<string, string> { { nameof(AppSettings.CommitInfoPosition), AppSettings.CommitInfoPosition.ToString() } });

LayoutRevisionInfo();
RefreshLayoutToggleButtonStates();
}

private void RefreshSplitViewLayout()
{
RightSplitContainer.Panel2Collapsed = !AppSettings.ShowSplitViewLayout;
DiagnosticsClient.TrackEvent("Layout change",
new Dictionary<string, string> { { nameof(AppSettings.ShowSplitViewLayout), AppSettings.ShowSplitViewLayout.ToString() } });

RefreshLayoutToggleButtonStates();
}

Expand Down Expand Up @@ -3232,5 +3248,15 @@ private void FormBrowse_DragEnter(object sender, DragEventArgs e)
e.Effect = DragDropEffects.Move;
}
}

private void TsmiTelemetryEnabled_Click(object sender, EventArgs e)
{
UICommands.StartGeneralSettingsDialog(this);
}

private void HelpToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
tsmiTelemetryEnabled.Checked = AppSettings.TelemetryEnabled ?? false;
}
}
}
9 changes: 6 additions & 3 deletions GitUI/CommandsDialogs/FormBrowse.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@
<metadata name="toolStripSeparator14.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="ToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>251, 17</value>
</metadata>
<metadata name="toolStripSeparator11.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolStripMenuItem3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="ToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>251, 17</value>
</metadata>
<metadata name="FilterToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
Expand Down
Loading

0 comments on commit 98b3915

Please sign in to comment.