Skip to content
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

Reduce the amount of telemetry emitted #11094

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSCodeActionParams reque
}

var correlationId = Guid.NewGuid();
using var __ = _telemetryReporter.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.CodeActionRazorTelemetryThresholdMS), correlationId);
using var __ = _telemetryReporter.TrackLspRequest(LspEndpointName, LanguageServerConstants.RazorLanguageServerName, TelemetryThresholds.CodeActionRazorTelemetryThreshold, correlationId);
cancellationToken.ThrowIfCancellationRequested();

return await _codeActionsService.GetCodeActionsAsync(request, documentContext, _supportsCodeActionResolve, correlationId, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(CompletionParams request
}

var correlationId = Guid.NewGuid();
using var _ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentCompletionName, LanguageServerConstants.RazorLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.CompletionRazorTelemetryThresholdMS), correlationId);
using var _ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentCompletionName, LanguageServerConstants.RazorLanguageServerName, TelemetryThresholds.CompletionRazorTelemetryThreshold, correlationId);
var completionList = await _completionListProvider.GetCompletionListAsync(
hostDocumentIndex,
completionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(VSInternalDocumentDiagno
}

var correlationId = Guid.NewGuid();
using var __ = _telemetryReporter?.TrackLspRequest(VSInternalMethods.DocumentPullDiagnosticName, LanguageServerConstants.RazorLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.DiagnosticsRazorTelemetryThresholdMS), correlationId);
using var __ = _telemetryReporter?.TrackLspRequest(VSInternalMethods.DocumentPullDiagnosticName, LanguageServerConstants.RazorLanguageServerName, TelemetryThresholds.DiagnosticsRazorTelemetryThreshold, correlationId);
var documentContext = context.DocumentContext;
if (documentContext is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V
}

var mapCodeCorrelationId = mapperParams.MapCodeCorrelationId ?? Guid.NewGuid();
using var ts = _telemetryReporter.TrackLspRequest(VSInternalMethods.WorkspaceMapCodeName, LanguageServerConstants.RazorLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.MapCodeRazorTelemetryThresholdMS), mapCodeCorrelationId);
using var ts = _telemetryReporter.TrackLspRequest(VSInternalMethods.WorkspaceMapCodeName, LanguageServerConstants.RazorLanguageServerName, TelemetryThresholds.MapCodeRazorTelemetryThreshold, mapCodeCorrelationId);

return await HandleMappingsAsync(mapperParams.Mappings, mapCodeCorrelationId, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(SemanticTokensRangeParam
var colorBackground = _razorLSPOptionsMonitor.CurrentValue.ColorBackground;

var correlationId = Guid.NewGuid();
using var _ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentSemanticTokensRangeName, LanguageServerConstants.RazorLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.SemanticTokensRazorTelemetryThresholdMS), correlationId);
using var _ = _telemetryReporter?.TrackLspRequest(Methods.TextDocumentSemanticTokensRangeName, LanguageServerConstants.RazorLanguageServerName, TelemetryThresholds.SemanticTokensRazorTelemetryThreshold, correlationId);

var data = await _semanticTokensInfoService.GetSemanticTokensAsync(documentContext, request.Range.ToLinePositionSpan(), colorBackground, correlationId, cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Microsoft.AspNetCore.Razor.Telemetry;

internal interface ITelemetryReporter
{
TelemetryScope BeginBlock(string name, Severity severity);
TelemetryScope BeginBlock(string name, Severity severity, Property property);
TelemetryScope BeginBlock(string name, Severity severity, Property property1, Property property2);
TelemetryScope BeginBlock(string name, Severity severity, Property property1, Property property2, Property property3);
TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, params Property[] properties);
TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport);
TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property);
TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2);
TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2, Property property3);
TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, params ReadOnlySpan<Property> properties);

TelemetryScope TrackLspRequest(string lspMethodName, string lspServerName, TimeSpan minTimeToReport, Guid correlationId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;

namespace Microsoft.AspNetCore.Razor.Telemetry;

internal static class ITelemetryReporterExtensions
{
// These extensions effectively make TimeSpan an optional parameter on BeginBlock
internal static TelemetryScope BeginBlock(this ITelemetryReporter self, string name, Severity severity) { return self.BeginBlock(name, severity, TimeSpan.Zero); }
internal static TelemetryScope BeginBlock(this ITelemetryReporter self, string name, Severity severity, Property property) { return self.BeginBlock(name, severity, TimeSpan.Zero, property); }
internal static TelemetryScope BeginBlock(this ITelemetryReporter self, string name, Severity severity, Property property1, Property property2) { return self.BeginBlock(name, severity, TimeSpan.Zero, property1, property2); }
internal static TelemetryScope BeginBlock(this ITelemetryReporter self, string name, Severity severity, Property property1, Property property2, Property property3) { return self.BeginBlock(name, severity, TimeSpan.Zero, property1, property2 , property3); }
internal static TelemetryScope BeginBlock(this ITelemetryReporter self, string name, Severity severity, params ReadOnlySpan<Property> properties) { return self.BeginBlock(name, severity, TimeSpan.Zero, properties); }
phil-allen-msft marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ private NoOpTelemetryReporter()
{
}

public TelemetryScope BeginBlock(string name, Severity severity)
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport)
=> TelemetryScope.Null;

public TelemetryScope BeginBlock(string name, Severity severity, Property property)
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property)
=> TelemetryScope.Null;

public TelemetryScope BeginBlock(string name, Severity severity, Property property1, Property property2)
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2)
=> TelemetryScope.Null;

public TelemetryScope BeginBlock(string name, Severity severity, Property property1, Property property2, Property property3)
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2, Property property3)
=> TelemetryScope.Null;

public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, params Property[] properties)
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, params ReadOnlySpan<Property> properties)
=> TelemetryScope.Null;

public void ReportEvent(string name, Severity severity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,46 +74,45 @@ public void Dispose()
StopwatchPool.Default.Return(_stopwatch);
}

public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity)
public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, TimeSpan minTimeToReport)
{
var array = new Property[1];

return new(reporter, name, TimeSpan.Zero, severity, array);
return new(reporter, name, minTimeToReport, severity, array);
}

public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, Property property)
public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, TimeSpan minTimeToReport, Property property)
{
var array = new Property[2];
array[0] = property;

return new(reporter, name, TimeSpan.Zero, severity, array);
return new(reporter, name, minTimeToReport, severity, array);
}

public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, Property property1, Property property2)
public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2)
{
var array = new Property[3];
array[0] = property1;
array[1] = property2;

return new(reporter, name, TimeSpan.Zero, severity, array);
return new(reporter, name, minTimeToReport, severity, array);
}

public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, Property property1, Property property2, Property property3)
public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2, Property property3)
{
var array = new Property[4];
array[0] = property1;
array[1] = property2;
array[2] = property3;

return new(reporter, name, TimeSpan.Zero, severity, array);
return new(reporter, name, minTimeToReport, severity, array);
}

public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, TimeSpan minTimeToReport, Property[] properties)
public static TelemetryScope Create(ITelemetryReporter reporter, string name, Severity severity, TimeSpan minTimeToReport, ReadOnlySpan<Property> properties)
{
var array = new Property[properties.Length + 1];

Array.Copy(properties, array, properties.Length);

properties.CopyTo(array);

return new(reporter, name, minTimeToReport, severity, array);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;

namespace Microsoft.CodeAnalysis.Razor.Workspaces.Telemetry;

/// <summary>
/// A set of constants used to reduce the telemetry emitted to the set that help us understand
/// which LSP is taking the most time in the case that the overall call is lengthy.
/// </summary>
internal class TelemetryThresholds
internal static class TelemetryThresholds
{
internal const int CodeActionRazorTelemetryThresholdMS = 2000;
internal const int CodeActionSubLSPTelemetryThresholdMS = 1000;
internal static readonly TimeSpan CodeActionRazorTelemetryThreshold = TimeSpan.FromMilliseconds(2000);
internal static readonly TimeSpan CodeActionSubLSPTelemetryThreshold = TimeSpan.FromMilliseconds(1000);

internal const int CompletionRazorTelemetryThresholdMS = 4000;
internal const int CompletionSubLSPTelemetryThresholdMS = 2000;
internal static readonly TimeSpan CompletionRazorTelemetryThreshold = TimeSpan.FromMilliseconds(4000);
internal static readonly TimeSpan CompletionSubLSPTelemetryThreshold = TimeSpan.FromMilliseconds(2000);

internal const int DiagnosticsRazorTelemetryThresholdMS = 4000;
internal const int DiagnosticsSubLSPTelemetryThresholdMS = 2000;
internal static readonly TimeSpan DiagnosticsRazorTelemetryThreshold = TimeSpan.FromMilliseconds(4000);
internal static readonly TimeSpan DiagnosticsSubLSPTelemetryThreshold = TimeSpan.FromMilliseconds(2000);

internal const int MapCodeRazorTelemetryThresholdMS = 2000;
internal const int MapCodeSubLSPTelemetryThresholdMS = 1000;
internal static readonly TimeSpan MapCodeRazorTelemetryThreshold = TimeSpan.FromMilliseconds(2000);
internal static readonly TimeSpan MapCodeSubLSPTelemetryThreshold = TimeSpan.FromMilliseconds(1000);

internal const int SemanticTokensRazorTelemetryThresholdMS = 2000;
internal const int SemanticTokensSubLSPTelemetryThresholdMS = 1000;
internal static readonly TimeSpan SemanticTokensRazorTelemetryThreshold = TimeSpan.FromMilliseconds(2000);
internal static readonly TimeSpan SemanticTokensSubLSPTelemetryThreshold = TimeSpan.FromMilliseconds(1000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class RemoteCSharpSemanticTokensProvider(IFilePathService filePathServi
{
using var _ = _telemetryReporter.TrackLspRequest(nameof(SemanticTokensRange.GetSemanticTokensAsync),
Constants.ExternalAccessServerName,
TimeSpan.FromMilliseconds(TelemetryThresholds.SemanticTokensRazorTelemetryThresholdMS),
TelemetryThresholds.SemanticTokensRazorTelemetryThreshold,
correlationId);

// We have a razor document, lets find the generated C# document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ImmutableArray<Registration> GetRegistrations(VSInternalClientCapabilitie
var colorBackground = _clientSettingsManager.GetClientSettings().AdvancedSettings.ColorBackground;

var correlationId = Guid.NewGuid();
using var _ = _telemetryReporter.TrackLspRequest(Methods.TextDocumentSemanticTokensRangeName, RazorLSPConstants.CohostLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.SemanticTokensRazorTelemetryThresholdMS), correlationId);
using var _ = _telemetryReporter.TrackLspRequest(Methods.TextDocumentSemanticTokensRangeName, RazorLSPConstants.CohostLanguageServerName, TelemetryThresholds.SemanticTokensRazorTelemetryThreshold, correlationId);

var tokens = await _remoteServiceInvoker.TryInvokeAsync<IRemoteSemanticTokensService, int[]?>(
razorDocument.Project.Solution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal partial class RazorCustomMessageTarget

var textBuffer = virtualDocumentSnapshot.Snapshot.TextBuffer;
var lspMethodName = Methods.TextDocumentCodeActionName;
using var _ = _telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.CodeActionSubLSPTelemetryThresholdMS), codeActionParams.CorrelationId);
using var _ = _telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TelemetryThresholds.CodeActionSubLSPTelemetryThreshold, codeActionParams.CorrelationId);
var requests = _requestInvoker.ReinvokeRequestOnMultipleServersAsync<VSCodeActionParams, IReadOnlyList<VSInternalCodeAction>>(
textBuffer,
lspMethodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal partial class RazorCustomMessageTarget
var textBuffer = virtualDocumentSnapshot.Snapshot.TextBuffer;
var lspMethodName = Methods.TextDocumentCompletion.Name;
ReinvocationResponse<VSInternalCompletionList?>? response;
using (_telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.CompletionSubLSPTelemetryThresholdMS), request.CorrelationId))
using (_telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TelemetryThresholds.CompletionSubLSPTelemetryThreshold, request.CorrelationId))
{
response = await _requestInvoker.ReinvokeRequestOnServerAsync<CompletionParams, VSInternalCompletionList?>(
textBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal partial class RazorCustomMessageTarget
};

var lspMethodName = VSInternalMethods.DocumentPullDiagnosticName;
using var _ = _telemetryReporter.TrackLspRequest(lspMethodName, delegatedLanguageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.DiagnosticsSubLSPTelemetryThresholdMS), correlationId);
using var _ = _telemetryReporter.TrackLspRequest(lspMethodName, delegatedLanguageServerName, TelemetryThresholds.DiagnosticsSubLSPTelemetryThreshold, correlationId);
var response = await _requestInvoker.ReinvokeRequestOnServerAsync<VSInternalDocumentDiagnosticsParams, VSInternalDiagnosticReport[]?>(
virtualDocument.Snapshot.TextBuffer,
lspMethodName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor.Protocol;
Expand Down Expand Up @@ -41,7 +40,7 @@ internal partial class RazorCustomMessageTarget
var textBuffer = delegationDetails.Value.TextBuffer;
var lspMethodName = VSInternalMethods.WorkspaceMapCodeName;
var languageServerName = delegationDetails.Value.LanguageServerName;
using var _ = _telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.MapCodeSubLSPTelemetryThresholdMS), request.MapCodeCorrelationId);
using var _ = _telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TelemetryThresholds.MapCodeSubLSPTelemetryThreshold, request.MapCodeCorrelationId);

var response = await _requestInvoker.ReinvokeRequestOnServerAsync<VSInternalMapCodeParams, WorkspaceEdit?>(
textBuffer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -86,7 +85,7 @@ internal partial class RazorCustomMessageTarget
var languageServerName = RazorLSPConstants.RazorCSharpLanguageServerName;

SemanticTokens? response;
using (var disposable = _telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TimeSpan.FromMilliseconds(TelemetryThresholds.SemanticTokensSubLSPTelemetryThresholdMS), semanticTokensParams.CorrelationId))
using (var disposable = _telemetryReporter.TrackLspRequest(lspMethodName, languageServerName, TelemetryThresholds.SemanticTokensSubLSPTelemetryThreshold, semanticTokensParams.CorrelationId))
{
try
{
Expand Down
Loading
Loading