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

Conversation

phil-allen-msft
Copy link
Contributor

Reduce the amount of telemetry emitted

The beginLspRequest event is removed, and the trackLspRequest event is only emitted if the amount of time is over a certain threshold. This allows analysis of cases in which the amount of taken is significantly over expectations while reducing the total telemetry significantly.

@phil-allen-msft phil-allen-msft requested a review from a team as a code owner October 25, 2024 19:18
@phil-allen-msft phil-allen-msft force-pushed the dev/phil-allen-msft/telemThreshold branch from 0958a31 to cfad35a Compare October 25, 2024 19:25
@@ -11,9 +11,9 @@ internal interface ITelemetryReporter
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, params Property[] properties);
Copy link
Member

Choose a reason for hiding this comment

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

❗ The purpose of the overloads above is to avoid allocating a params array in cases where there are zero to three properties. This change will cause any calls that now pass a TimeSpan and zero to three properties to create an extra array: one for the params array, and one for the final telemetry array of length + . I recommend adding TimeSpan to each of these overloads and then adding extension methods on ITelemetryReporter that don't have the TimeSpan parameter and just pass TimeSpan.Zero.

Also, consider turning the final overload into params ReadOnlySpan<Property> to match ReportEvent below.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think minTimeToReport seems weird on BeginBlock. Maybe it would be better to add something to TelemetryScope for this?

Copy link
Member

Choose a reason for hiding this comment

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

You're right. It does feel a bit strange on a method called BeginBlock. However, I think it would be awkward ergonomically to have some property to set on TelemetryScope. There are two reasons for this:

  1. Nothing actually uses a TelemetryScope today. It's always captured in a using statement.
  2. There's a race condition between the TelemetryScope being created and the value being set. So, passing it as a parameter so that it can be included in the TelemetryScope is probably the right thing.

Of course, the truth is that BeginBlock is kind of a weird name because since it produces a TelemetryScope. Also, TelemetryScope is currently a class. Should it become a struct with [NonCopyable] to avoid the extra allocation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing actually uses a TelemetryScope today. It's always captured in a using statement.

But they could. Scopes probably should have a cancel anyways...

I like the idea of them being a [NonCopyable] struct. I still find it odd to add a timespan to every BeginBlock when only TrackLspRequest is using it. It seems like we're taking an implementation of one part of the API surface and expanding it.

In the end it's not a huge deal though, and with the added extension methods it won't cause any real pain

Copy link
Member

@DustinCampbell DustinCampbell Oct 28, 2024

Choose a reason for hiding this comment

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

I still find it odd to add a timespan to every BeginBlock when only TrackLspRequest is using it.

The reason that there're five overloads of BeginBlock is really for performance. That can definitely be improved, and I'm happy to take a look at it. IMO, BeginBlock is the core API that an ITelemetryReporter should implement and the TimeSpan is a feature of that API, so it should go there. However, we should work out some of the ergonomic problems that you've pointed out. Although, there aren't actually any callers of BeginBlock other than TrackLspRequest and unit tests today.

Copy link
Member

@DustinCampbell DustinCampbell Oct 28, 2024

Choose a reason for hiding this comment

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

But they could. Scopes probably should have a cancel anyways...

Maybe? At the moment that's kind of YAGNI isn't it?

…or is used, _reporter is null so no "report" happens on Dispose. If the _reporter check were removed from Dispose, multiple unittests would fail.

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.

@phil-allen-msft phil-allen-msft merged commit ad74439 into main Oct 28, 2024
12 checks passed
@phil-allen-msft phil-allen-msft deleted the dev/phil-allen-msft/telemThreshold branch October 28, 2024 20:07
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 28, 2024
@phil-allen-msft phil-allen-msft modified the milestones: Next, 17.13 P1 Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants