Skip to content

Commit

Permalink
Update MetricsTelemetryCollector.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Sep 11, 2023
1 parent c36c4c3 commit 7ac7f5b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public MetricResults GetMetrics()
List<MetricData>? metricData;
List<DistributionMetricData>? distributionData;

lock (_aggregated)
var aggregated = _aggregated.Value;
lock (aggregated)
{
var aggregated = _aggregated.Value;
metricData = GetMetricData(aggregated.PublicApiCounts, aggregated.Counts, aggregated.Gauges);
distributionData = GetDistributionData(aggregated.Distributions);
}
Expand Down Expand Up @@ -85,11 +85,11 @@ internal void AggregateMetrics()
{
var buffer = Interlocked.Exchange(ref _buffer, _reserveBuffer);

var aggregated = _aggregated.Value;
// _aggregated, containing the aggregated metrics, is not thread-safe
// and is also used when getting the metrics for serialization.
lock (_aggregated)
lock (aggregated)
{
var aggregated = _aggregated.Value;
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
AggregateMetric(buffer.PublicApiCounts, timestamp, aggregated.PublicApiCounts);
AggregateMetric(buffer.Counts, timestamp, aggregated.Counts);
Expand Down

0 comments on commit 7ac7f5b

Please sign in to comment.