Skip to content

Commit

Permalink
Merge pull request #1 from Cosifne/dev/shech/AddSimpleTelemetry
Browse files Browse the repository at this point in the history
Track the telemetry of rename
  • Loading branch information
AmadeusW authored Mar 29, 2024
2 parents b57762a + 1f49906 commit 6425ccb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
using Microsoft.CodeAnalysis.EditorFeatures.Lightup;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Telemetry;
using Microsoft.VisualStudio.PlatformUI;

namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename;

internal sealed class SmartRenameViewModel : INotifyPropertyChanged, IDisposable
internal sealed partial class SmartRenameViewModel : INotifyPropertyChanged, IDisposable
{
#pragma warning disable CS0618 // Editor team use Obsolete attribute to mark potential changing API
private readonly ISmartRenameSessionWrapper _smartRenameSession;
Expand Down Expand Up @@ -124,6 +125,7 @@ public SmartRenameViewModel(
var getSuggestionsAutomatically = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.GetSuggestionsAutomatically);
IsUsingResultPanel = getSuggestionsAutomatically;
IsUsingDropdown = !IsUsingResultPanel;
SetupTelemetry();
if (IsUsingResultPanel && IsSuggestionsPanelExpanded)
{
OnGetSuggestionsCommandExecute();
Expand All @@ -142,6 +144,11 @@ private void OnGetSuggestionsCommandExecute()
{
var listener = _listenerProvider.GetListener(FeatureAttribute.SmartRename);
var listenerToken = listener.BeginAsyncOperation(nameof(_smartRenameSession.GetSuggestionsAsync));
if (IsUsingDropdown && _suggestionsDropdownTelemetry is not null)
{
_suggestionsDropdownTelemetry.DropdownButtonClickTimes += 1;
}

_getSuggestionsTask = _smartRenameSession.GetSuggestionsAsync(_cancellationTokenSource.Token).CompletesAsyncOperation(listenerToken);
}
}
Expand Down Expand Up @@ -198,12 +205,14 @@ public void Cancel()
_cancellationTokenSource.Cancel();
// It's needed by editor-side telemetry.
_smartRenameSession.OnCancel();
PostTelemetry(isCommit: false);
}

public void Commit(string finalIdentifierName)
{
// It's needed by editor-side telemetry.
_smartRenameSession.OnSuccess(finalIdentifierName);
PostTelemetry(isCommit: true);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.InlineRename;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Telemetry;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename
{
internal partial class SmartRenameViewModel
{
private SuggestionsPanelTelemetry? _suggestionsPanelTelemetry;
private SuggestionsDropdownTelemetry? _suggestionsDropdownTelemetry;

private sealed class SuggestionsPanelTelemetry
{
public bool CollapseSuggestionsPanelWhenRenameStarts { get; set; }
}

private sealed class SuggestionsDropdownTelemetry
{
public int DropdownButtonClickTimes { get; set; }
}

private void SetupTelemetry()
{
var getSuggestionsAutomatically = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.GetSuggestionsAutomatically);
if (getSuggestionsAutomatically)
{
_suggestionsPanelTelemetry = new SuggestionsPanelTelemetry
{
CollapseSuggestionsPanelWhenRenameStarts = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel)
};
}
else
{
_suggestionsDropdownTelemetry = new SuggestionsDropdownTelemetry();
}
}

private void PostTelemetry(bool isCommit)
{
if (_suggestionsPanelTelemetry is not null)
{
RoslynDebug.Assert(_suggestionsDropdownTelemetry is null);
TelemetryLogging.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m =>
{
m[nameof(isCommit)] = isCommit;
m["UseSuggestionsPanel"] = true;
m[nameof(SuggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts)] = _suggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts;
m["CollapseSuggestionsPanelWhenRenameEnds"] = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel);
}));
}
else
{
RoslynDebug.Assert(_suggestionsDropdownTelemetry is not null);
TelemetryLogging.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m =>
{
m[nameof(isCommit)] = isCommit;
m["UseDropDown"] = true;
m[nameof(SuggestionsDropdownTelemetry.DropdownButtonClickTimes)] = _suggestionsDropdownTelemetry.DropdownButtonClickTimes;
}));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,5 @@ internal enum FunctionId

// 800-850 for Copilot performance logging.
Copilot_Suggestion_Dismissed = 800,
Copilot_Rename = 851
}

0 comments on commit 6425ccb

Please sign in to comment.