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 2 commits
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 @@ -8,9 +8,18 @@ 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); }
public static TelemetryScope BeginBlock(this ITelemetryReporter reporter, string name, Severity severity)
=> reporter.BeginBlock(name, severity, minTimeToReport: TimeSpan.Zero);

public static TelemetryScope BeginBlock(this ITelemetryReporter reporter, string name, Severity severity, Property property)
=> reporter.BeginBlock(name, severity, minTimeToReport: TimeSpan.Zero, property);

public static TelemetryScope BeginBlock(this ITelemetryReporter reporter, string name, Severity severity, Property property1, Property property2)
=> reporter.BeginBlock(name, severity, minTimeToReport: TimeSpan.Zero, property1, property2);

public static TelemetryScope BeginBlock(this ITelemetryReporter reporter, string name, Severity severity, Property property1, Property property2, Property property3)
=> reporter.BeginBlock(name, severity, minTimeToReport: TimeSpan.Zero, property1, property2, property3);

public static TelemetryScope BeginBlock(this ITelemetryReporter reporter, string name, Severity severity, params ReadOnlySpan<Property> properties)
=> reporter.BeginBlock(name, severity, minTimeToReport: TimeSpan.Zero, properties);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Utilities;

namespace Microsoft.AspNetCore.Razor.Telemetry;

internal sealed class TelemetryScope : IDisposable
[NonCopyable]
internal struct TelemetryScope : IDisposable
{
public static readonly TelemetryScope Null = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that TelemetryScope is a struct, this is an unnecessary affordance. Plus, there's no such thing as "Null" for a struct. 😄 Please remove these and update all usages to just refer to default.


Expand All @@ -19,9 +21,9 @@ internal sealed class TelemetryScope : IDisposable
private readonly TimeSpan _minTimeToReport;
private bool _disposed;

private TelemetryScope()
public TelemetryScope()
{
// This constructor is only called to initialize the Null instance
// This constructor should be called only to initialize the Null instance
// above. Rather than make _name, _properties, and _stopwatch
// nullable, we use a ! to initialize them to null for this case only.
_reporter = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ async IAsyncEnumerable<ReinvocationResponse<IReadOnlyList<VSInternalCodeAction>>

var documentSynchronizer = GetDocumentSynchronizer(GetCSharpSnapshot());
var telemetryReporter = new Mock<ITelemetryReporter>(MockBehavior.Strict);
telemetryReporter.Setup(r => r.TrackLspRequest(It.IsAny<string>(), It.IsAny<string>(), TimeSpan.FromSeconds(1), It.IsAny<Guid>())).Returns(TelemetryScope.Null);
telemetryReporter.Setup(r => r.TrackLspRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TimeSpan>(), It.IsAny<Guid>()))
.Callback<string, string, TimeSpan, Guid>((s1, s2, ts, g) => Assert.NotEqual(TimeSpan.Zero, ts))
.Returns(TelemetryScope.Null);
var csharpVirtualDocumentAddListener = new CSharpVirtualDocumentAddListener(LoggerFactory);

var target = new RazorCustomMessageTarget(
Expand Down Expand Up @@ -520,8 +522,13 @@ public async Task ProvideSemanticTokensAsync_ContainsRange_ReturnsSemanticTokens
It.IsAny<CancellationToken>()))
.ReturnsAsync(new DefaultLSPDocumentSynchronizer.SynchronizedResult<CSharpVirtualDocumentSnapshot>(true, csharpVirtualDocument));
var telemetryReporter = new Mock<ITelemetryReporter>(MockBehavior.Strict);
telemetryReporter.Setup(r => r.BeginBlock(It.IsAny<string>(), It.IsAny<Severity>(), It.IsAny<TimeSpan>(), It.IsAny<Property>())).Returns(TelemetryScope.Null);
telemetryReporter.Setup(r => r.TrackLspRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TimeSpan>(), It.IsAny<Guid>())).Returns(TelemetryScope.Null);
telemetryReporter.Setup(r => r.BeginBlock(It.IsAny<string>(), It.IsAny<Severity>(), It.IsAny<TimeSpan>(), It.IsAny<Property>()))
.Callback<string, Severity, TimeSpan, Property>((s1, s2, ts, g) => Assert.NotEqual(TimeSpan.Zero, ts))
.Returns(TelemetryScope.Null);

telemetryReporter.Setup(r => r.TrackLspRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TimeSpan>(), It.IsAny<Guid>()))
.Callback<string, string, TimeSpan, Guid>((s1, s2, ts, g) => Assert.NotEqual(TimeSpan.Zero, ts))
.Returns(TelemetryScope.Null);
var csharpVirtualDocumentAddListener = new CSharpVirtualDocumentAddListener(LoggerFactory);

var target = new RazorCustomMessageTarget(
Expand Down Expand Up @@ -598,8 +605,13 @@ public async Task ProvideSemanticTokensAsync_EmptyRange_ReturnsNoSemanticTokens(
It.IsAny<CancellationToken>()))
.ReturnsAsync(new DefaultLSPDocumentSynchronizer.SynchronizedResult<CSharpVirtualDocumentSnapshot>(true, csharpVirtualDocument));
var telemetryReporter = new Mock<ITelemetryReporter>(MockBehavior.Strict);
telemetryReporter.Setup(r => r.BeginBlock(It.IsAny<string>(), It.IsAny<Severity>(), It.IsAny<TimeSpan>(), It.IsAny<Property>())).Returns(TelemetryScope.Null);
telemetryReporter.Setup(r => r.TrackLspRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TimeSpan>(), It.IsAny<Guid>())).Returns(TelemetryScope.Null);
telemetryReporter.Setup(r => r.BeginBlock(It.IsAny<string>(), It.IsAny<Severity>(), It.IsAny<TimeSpan>(), It.IsAny<Property>()))
.Callback<string, Severity, TimeSpan, Property>((s, sev, ts, p) => Assert.NotEqual(TimeSpan.Zero, ts))
.Returns(TelemetryScope.Null);

telemetryReporter.Setup(r => r.TrackLspRequest(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TimeSpan>(), It.IsAny<Guid>()))
.Callback<string, string, TimeSpan, Guid>((s1, s2, ts, g) => Assert.NotEqual(TimeSpan.Zero, ts))
.Returns(TelemetryScope.Null);
var csharpVirtualDocumentAddListener = new CSharpVirtualDocumentAddListener(LoggerFactory);

var target = new RazorCustomMessageTarget(
Expand Down
Loading