-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add telemetry for 'bad' experiences based on tag helpers #10906
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,16 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Razor.Language; | ||
using Microsoft.AspNetCore.Razor.Language.Components; | ||
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; | ||
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; | ||
using Microsoft.AspNetCore.Razor.PooledObjects; | ||
using Microsoft.AspNetCore.Razor.ProjectSystem; | ||
using Microsoft.AspNetCore.Razor.Telemetry; | ||
using Microsoft.CodeAnalysis.Razor.ProjectSystem; | ||
using Microsoft.CodeAnalysis.Razor.Protocol; | ||
|
@@ -25,6 +29,7 @@ internal class DocumentPullDiagnosticsEndpoint : IRazorRequestHandler<VSInternal | |
private readonly IClientConnection _clientConnection; | ||
private readonly RazorTranslateDiagnosticsService _translateDiagnosticsService; | ||
private readonly ITelemetryReporter? _telemetryReporter; | ||
private ImmutableDictionary<ProjectKey, int> _lastReporedProjectTagHelperCount = ImmutableDictionary<ProjectKey, int>.Empty; | ||
|
||
public DocumentPullDiagnosticsEndpoint( | ||
LanguageServerFeatureOptions languageServerFeatureOptions, | ||
|
@@ -74,6 +79,8 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno | |
|
||
var razorDiagnostics = await GetRazorDiagnosticsAsync(documentContext, cancellationToken).ConfigureAwait(false); | ||
|
||
await ReportRZ10012TelemetryAsync(documentContext, razorDiagnostics, cancellationToken).ConfigureAwait(false); | ||
|
||
var (csharpDiagnostics, htmlDiagnostics) = await GetHtmlCSharpDiagnosticsAsync(documentContext, correlationId, cancellationToken).ConfigureAwait(false); | ||
|
||
var diagnosticCount = | ||
|
@@ -160,4 +167,59 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno | |
|
||
return (delegatedResponse.CSharpDiagnostics, delegatedResponse.HtmlDiagnostics); | ||
} | ||
|
||
/// <summary> | ||
/// Reports telemetry for RZ10012 "Found markup element with unexpected name" to help track down potential issues | ||
/// with taghelpers being discovered (or lack thereof) | ||
/// </summary> | ||
private async ValueTask ReportRZ10012TelemetryAsync(DocumentContext documentContext, VSInternalDiagnosticReport[]? razorDiagnostics, CancellationToken cancellationToken) | ||
{ | ||
if (razorDiagnostics is null) | ||
{ | ||
return; | ||
} | ||
|
||
if (_telemetryReporter is null) | ||
{ | ||
return; | ||
} | ||
|
||
var relevantDiagnosticsCount = razorDiagnostics.Sum(CountDiagnostics); | ||
if (relevantDiagnosticsCount == 0) | ||
{ | ||
return; | ||
} | ||
|
||
var tagHelpers = await documentContext.Project.GetTagHelpersAsync(cancellationToken).ConfigureAwait(false); | ||
var tagHelperCount = tagHelpers.Count(); | ||
var shouldReport = false; | ||
|
||
ImmutableInterlocked.AddOrUpdate( | ||
ref _lastReporedProjectTagHelperCount, | ||
documentContext.Project.Key, | ||
(k) => | ||
{ | ||
shouldReport = true; | ||
return tagHelperCount; | ||
}, | ||
(k, currentValue) => | ||
{ | ||
shouldReport = currentValue != tagHelperCount; | ||
return tagHelperCount; | ||
}); | ||
|
||
if (shouldReport) | ||
{ | ||
_telemetryReporter.ReportEvent( | ||
"RZ10012", | ||
Severity.Low, | ||
new("tagHelpers", tagHelperCount), | ||
new("RZ10012errors", relevantDiagnosticsCount), | ||
new("project", documentContext.Project.Key.Id)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this PII? Do have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets labeled in the server to not depend on client side labeling and ensure correct handling |
||
} | ||
|
||
static int CountDiagnostics(VSInternalDiagnosticReport report) | ||
=> report.Diagnostics?.Count(d => d.Code == ComponentDiagnosticFactory.UnexpectedMarkupElement.Id) | ||
?? 0; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
.Length