Skip to content

Commit

Permalink
Update Copilot rename telemetry (#76045)
Browse files Browse the repository at this point in the history
Update Copilot rename telemetry with the following information:
- CorrelationID for correlation with Editor and Copilot telemetry.
Defaults to empty GUID if not available (it will be available in 17.13
preview 2)
- Time it took to get context
- Whether context was used and whether there were any errors

![image](https://github.com/user-attachments/assets/c37b57eb-0fda-4c9b-bdd5-698686064b25)
  • Loading branch information
Cosifne authored Dec 3, 2024
2 parents df02af6 + 9684446 commit 64aa047
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename;

Expand All @@ -37,6 +38,9 @@ internal sealed partial class SmartRenameViewModel : INotifyPropertyChanged, IDi
private bool _isDisposed;
private TimeSpan AutomaticFetchDelay => _smartRenameSession.AutomaticFetchDelay;
private Task _getSuggestionsTask = Task.CompletedTask;
private TimeSpan _semanticContextDelay;
private bool _semanticContextError;
private bool _semanticContextUsed;

public event PropertyChangedEventHandler? PropertyChanged;

Expand Down Expand Up @@ -176,6 +180,8 @@ await Task.Delay(_smartRenameSession.AutomaticFetchDelay, cancellationToken)

if (IsUsingSemanticContext)
{
var stopwatch = SharedStopwatch.StartNew();
_semanticContextUsed = true;
var document = this.BaseViewModel.Session.TriggerDocument;
var smartRenameContext = ImmutableDictionary<string, ImmutableArray<(string filePath, string content)>>.Empty;
try
Expand All @@ -188,9 +194,11 @@ await Task.Delay(_smartRenameSession.AutomaticFetchDelay, cancellationToken)
smartRenameContext = ImmutableDictionary.CreateRange<string, ImmutableArray<(string filePath, string content)>>(
context
.Select(n => new KeyValuePair<string, ImmutableArray<(string filePath, string content)>>(n.Key, n.Value)));
_semanticContextDelay = stopwatch.Elapsed;
}
catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Diagnostic))
{
_semanticContextError = true;
// use empty smartRenameContext
}
_ = await _smartRenameSession.GetSuggestionsAsync(smartRenameContext, cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ private void PostTelemetry(bool isCommit)
m[nameof(SuggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts)] = _suggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts;
m["CollapseSuggestionsPanelWhenRenameEnds"] = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel);
m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress;
m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId;
m["smartRenameSemanticContextUsed"] = _semanticContextUsed;
m["smartRenameSemanticContextDelay"] = _semanticContextDelay;
m["smartRenameSemanticContextError"] = _semanticContextError;
}));
}
else
Expand All @@ -63,6 +67,10 @@ private void PostTelemetry(bool isCommit)
m["UseDropDown"] = true;
m[nameof(SuggestionsDropdownTelemetry.DropdownButtonClickTimes)] = _suggestionsDropdownTelemetry.DropdownButtonClickTimes;
m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress;
m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId;
m["smartRenameSemanticContextUsed"] = _semanticContextUsed;
m["smartRenameSemanticContextDelay"] = _semanticContextDelay;
m["smartRenameSemanticContextError"] = _semanticContextError;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Microsoft.CodeAnalysis.EditorFeatures.Lightup;
private static readonly Func<object, string> s_statusMessageAccessor;
private static readonly Func<object, bool> s_statusMessageVisibilityAccessor;
private static readonly Func<object, IReadOnlyList<string>> s_suggestedNamesAccessor;
private static readonly Func<object, Guid> s_correlationIdAccessor;
private static readonly Func<object?, object?>? s_renameContextImmutableListCreateBuilderAccessor;
private static readonly Action<object, object>? s_renameContextImmutableListBuilderAddAccessor;
private static readonly Func<object, object>? s_renameContextImmutableListBuilderToArrayAccessor;
Expand All @@ -52,6 +53,7 @@ static ISmartRenameSessionWrapper()
s_statusMessageAccessor = LightupHelpers.CreatePropertyAccessor<object, string>(s_wrappedType, nameof(StatusMessage), "");
s_statusMessageVisibilityAccessor = LightupHelpers.CreatePropertyAccessor<object, bool>(s_wrappedType, nameof(StatusMessageVisibility), false);
s_suggestedNamesAccessor = LightupHelpers.CreatePropertyAccessor<object, IReadOnlyList<string>>(s_wrappedType, nameof(SuggestedNames), []);
s_correlationIdAccessor = LightupHelpers.CreatePropertyAccessor<object, Guid>(s_wrappedType, nameof(CorrelationId), Guid.Empty);

if (s_wrappedRenameContextType is not null)
{
Expand Down Expand Up @@ -93,6 +95,7 @@ private ISmartRenameSessionWrapper(object instance)
public string StatusMessage => s_statusMessageAccessor(_instance);
public bool StatusMessageVisibility => s_statusMessageVisibilityAccessor(_instance);
public IReadOnlyList<string> SuggestedNames => s_suggestedNamesAccessor(_instance);
public Guid CorrelationId => s_correlationIdAccessor(_instance);

public event PropertyChangedEventHandler PropertyChanged
{
Expand Down

0 comments on commit 64aa047

Please sign in to comment.