-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Move AsyncBatchingWorkQueue usage in telemetry to TelemetryLogging level #73287
Changes from all commits
a6e0ea4
af5271f
4145a2b
4a45841
37d041b
e5d98dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ public RequestTelemetryLogger(string serverTypeName) | |
_requestCounters = new(); | ||
_findDocumentResults = new(); | ||
_usedForkedSolutionCounter = new(); | ||
|
||
TelemetryLogging.Flushed += OnFlushed; | ||
} | ||
|
||
public void UpdateFindDocumentTelemetryData(bool success, string? workspaceKind) | ||
|
@@ -92,6 +94,14 @@ public void Dispose() | |
return; | ||
} | ||
|
||
// Flush all telemetry logged through TelemetryLogging | ||
TelemetryLogging.Flush(); | ||
|
||
TelemetryLogging.Flushed -= OnFlushed; | ||
} | ||
|
||
private void OnFlushed(object? sender, EventArgs e) | ||
{ | ||
foreach (var kvp in _requestCounters) | ||
{ | ||
TelemetryLogging.Log(FunctionId.LSP_RequestCounter, KeyValueLogMessage.Create(LogType.Trace, m => | ||
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. I was trying to figure out why these didn't use Wondering if we should have another variant of the LogAggregated that does a sum or something. But maybe a change for a later date. 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. Yes, that's exactly right. I considered that as part of this, but it seemed like overkill for now. Especially, as I know we have more upcoming work in this area as part of potentially moving towards OTel. |
||
|
@@ -124,9 +134,6 @@ public void Dispose() | |
} | ||
})); | ||
|
||
// Flush all telemetry logged through TelemetryLogging | ||
TelemetryLogging.Flush(); | ||
|
||
_requestCounters.Clear(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,26 +3,44 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Internal.Log; | ||
using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.Telemetry; | ||
|
||
/// <summary> | ||
/// Provides access to posting telemetry events or adding information | ||
/// to aggregated telemetry events. | ||
/// to aggregated telemetry events. Posts pending telemetry at 30 | ||
/// minute intervals. | ||
/// </summary> | ||
internal static class TelemetryLogging | ||
{ | ||
private static ITelemetryLogProvider? s_logProvider; | ||
private static AsyncBatchingWorkQueue? s_postTelemetryQueue; | ||
|
||
public const string KeyName = "Name"; | ||
public const string KeyValue = "Value"; | ||
public const string KeyLanguageName = "LanguageName"; | ||
public const string KeyMetricName = "MetricName"; | ||
|
||
public static void SetLogProvider(ITelemetryLogProvider logProvider) | ||
public static event EventHandler<EventArgs>? Flushed; | ||
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. what is the event for? 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. RequestTelemetryLogger not only uses TelemetryLogging for aggregated telemetry, but also accumulation it's own counts that it will send to telemetry itself. RequestTelemetryLogger uses Dispose to both notify this object to Flush and also handles firing the telemetry counts it is accumulating. However, Dispose isn't a reliable mechanism by which to fire telemetry, as the process might be terminated before we get the opportunity to act. To handle that, the aggregating telemetry code previously fired off telemetry every 30 minutes, using an ABWQ. This PR moves that out to the TelemetryLogging level, but it's still not hooked into the telemetry that fires due to the accounting in RequestTelemetryLogger. This event allows RequestTelemetryLogger to hook into when that ABWQ derived telemetry firing is happening, and when it does RequestTelemetryLogger can fire off the telemetry that it is accounting for. |
||
|
||
public static void SetLogProvider(ITelemetryLogProvider logProvider, IAsynchronousOperationListener asyncListener) | ||
{ | ||
s_logProvider = logProvider; | ||
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. Should this throw if there's already a log provider? 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. done! 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. undid as it caused test failures |
||
|
||
InterlockedOperations.Initialize(ref s_postTelemetryQueue, () => | ||
new AsyncBatchingWorkQueue( | ||
TimeSpan.FromMinutes(30), | ||
PostCollectedTelemetryAsync, | ||
asyncListener, | ||
CancellationToken.None)); | ||
|
||
// Add the initial item to the queue to ensure later processing. | ||
s_postTelemetryQueue?.AddWork(); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -112,5 +130,17 @@ public static void LogAggregated(FunctionId functionId, KeyValueLogMessage logMe | |
public static void Flush() | ||
{ | ||
s_logProvider?.Flush(); | ||
|
||
Flushed?.Invoke(null, EventArgs.Empty); | ||
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. not quite sure i get the point of the events. |
||
} | ||
|
||
private static ValueTask PostCollectedTelemetryAsync(CancellationToken cancellationToken) | ||
{ | ||
Flush(); | ||
|
||
// Ensure PostCollectedTelemetryAsync will get fired again after the collection period. | ||
s_postTelemetryQueue?.AddWork(); | ||
|
||
return ValueTaskFactory.CompletedTask; | ||
} | ||
} |
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.
I don't remember if the queries are resilient to multiple events for the same server for the same session. I assume they are since I don't think we drill down into the session in particular, but I can't remember.
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.
The queries that I know don't drill into the session, so they are resilient. If we find some that do use the session, it seems feasible to change them to allow multiple items from a session.