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

Fix request duration logging #11198

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -51,23 +51,24 @@ public AggregatingTelemetryLog(TelemetryReporter reporter, string name, double[]
}

/// <summary>
/// Adds aggregated information for the metric and value passed in via <paramref name="name"/>. The Name/Value properties
/// are used as the metric name and value to record.
/// Adds aggregated information for the <paramref name="histogramKey"/> and <paramref name="value"/>. Method name is tacked onto
/// to the first <paramref name="histogramKey"/> used for convenience.
/// </summary>
public void Log(string name,
public void Log(
string histogramKey,
int value,
string metricName,
string method)
{
if (!IsEnabled)
return;

(var histogram, _, var histogramLock) = ImmutableInterlocked.GetOrAdd(ref _histograms, name, name =>
(var histogram, _, var histogramLock) = ImmutableInterlocked.GetOrAdd(ref _histograms, histogramKey, histogramKey =>
{
var telemetryEvent = new TelemetryEvent(_eventName);

TelemetryReporter.AddToProperties(telemetryEvent.Properties, new Property("method", method));

var histogram = _meter.CreateHistogram<long>(metricName, _histogramConfiguration);
var histogram = _meter.CreateHistogram<long>(histogramKey, _histogramConfiguration);
var histogramLock = new object();

return (histogram, telemetryEvent, histogramLock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,13 @@ private void Flush()
public void LogRequestTelemetry(string name, string? language, TimeSpan queuedDuration, TimeSpan requestDuration, TelemetryResult result)
{
LogAggregated("LSP_TimeInQueue",
"", // All time in queue events use the same histogram, no need for separate keys
(int)queuedDuration.TotalMilliseconds,
"TimeInQueue",
name);

LogAggregated("LSP_RequestDuration",
name, // RequestDuration requests are histogrammed by their unique name
(int)requestDuration.TotalMilliseconds,
"RequestDuration",
name);

_requestCounters.GetOrAdd((name, language), (_) => new Counter()).IncrementCount(result);
Expand All @@ -503,13 +503,13 @@ private void LogRequestCounters()
}

private void LogAggregated(
string name,
string managerKey,
string histogramKey,
int value,
string metricName,
string method)
{
var aggregatingLog = _aggregatingManager?.GetLog(name);
aggregatingLog?.Log(name, value, metricName, method);
var aggregatingLog = _aggregatingManager?.GetLog(managerKey);
aggregatingLog?.Log(histogramKey, value, method);
}

private sealed class Counter
Expand Down
Loading