Skip to content

Commit f382b31

Browse files
Add more telemetry during copilot change adjustmnet (#79216)
2 parents f98c1cf + 1352df5 commit f382b31

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/EditorFeatures/Core/Copilot/RoslynProposalAdjusterProvider.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,36 @@ private async Task<ProposalBase> AdjustProposalAsync(
8080
{
8181
try
8282
{
83-
var (newProposal, adjustmentsProposed) = await AdjustProposalAsync(
83+
var newProposal = await AdjustProposalAsync(
8484
solution, proposal, cancellationToken).ConfigureAwait(false);
85-
var adjustmentsAccepted = newProposal != proposal;
8685

8786
// Report telemetry if we were or were not able to adjust the proposal.
8887
Logger.LogBlock(FunctionId.Copilot_AdjustProposal, KeyValueLogMessage.Create(static (d, args) =>
8988
{
90-
var (providerName, before, adjustmentsProposed, adjustmentsAccepted, elapsedTime) = args;
89+
var (providerName, before, proposal, newProposal, elapsedTime) = args;
90+
91+
// If we (roslyn) were able to come up with *any* edits we wanted to adjust the proposal with or not.
92+
var adjustmentsProposed = newProposal != null;
93+
94+
newProposal ??= proposal;
95+
96+
// Whether or not the Proposal system accepted the edits we proposed. It can reject them for a variety of reasons,
97+
// for example, if it thinks they would interfere with the caret, or if edits intersect other edits.
98+
var adjustmentsAccepted = newProposal != proposal;
99+
91100
SetDefaultTelemetryProperties(d, providerName, before, elapsedTime);
101+
92102
d["AdjustmentsProposed"] = adjustmentsProposed;
93103
d["AdjustmentsAccepted"] = adjustmentsAccepted;
104+
105+
// Record how many new edits were made to the proposal. Expectation is that this is commonly only 1,
106+
// but we want to see how that potentially changes over time, especially as we add more adjusters.
107+
d["AdjustmentsCount"] = newProposal.Edits.Count - proposal.Edits.Count;
94108
},
95-
args: (providerName, before, adjustmentsProposed, adjustmentsAccepted, stopwatch.Elapsed)),
109+
args: (providerName, before, proposal, newProposal, stopwatch.Elapsed)),
96110
cancellationToken).Dispose();
97111

98-
return newProposal;
112+
return newProposal ?? proposal;
99113
}
100114
catch (Exception ex) when (ReportFailureTelemetry(ex))
101115
{
@@ -133,7 +147,12 @@ bool ReportFailureTelemetry(Exception ex)
133147
}
134148
}
135149

136-
private async Task<(ProposalBase newProposal, bool adjustmentsProposed)> AdjustProposalAsync(
150+
/// <summary>
151+
/// Returns <see langword="null"/> if we didn't make any adjustments to the proposal. Otherwise, returns the attempted
152+
/// adjusted proposal based on the edits we tried to make. Note that this does not guarantee that the edits were successfully
153+
/// applied to the original edits. The <see cref="Proposal"/> system may reject them based on their own criteria.
154+
/// </summary>
155+
private async Task<ProposalBase?> AdjustProposalAsync(
137156
Solution solution, ProposalBase proposal, CancellationToken cancellationToken)
138157
{
139158
// We're potentially making multiple calls to oop here. So keep a session alive to avoid
@@ -176,11 +195,12 @@ bool ReportFailureTelemetry(Exception ex)
176195

177196
// No adjustments were made. Don't touch anything.
178197
if (!adjustmentsProposed)
179-
return (proposal, adjustmentsProposed: false);
198+
return null;
180199

181200
// We have some changes we want to to make to the proposal. See if the proposal system allows us merging
182-
// those changes in.
183-
var newProposal = Proposal.TryCreateProposal(proposal, finalEdits);
184-
return (newProposal ?? proposal, adjustmentsProposed: true);
201+
// those changes in. Note: we should generally always be producing edits that are safe to merge in. However,
202+
// as we do not control this code, we cannot guarantee this. Telemetry will let us know how often this happens
203+
// and if there's something we need to look into.
204+
return Proposal.TryCreateProposal(proposal, finalEdits);
185205
}
186206
}

0 commit comments

Comments
 (0)