Skip to content

Commit

Permalink
Clear InstrumentIdenity map when meter is disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest committed Mar 4, 2022
1 parent 03a245e commit 0ff1d22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/OpenTelemetry/Metrics/MetricReaderExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using OpenTelemetry.Internal;
Expand All @@ -27,7 +28,7 @@ namespace OpenTelemetry.Metrics
public abstract partial class MetricReader
{
private readonly HashSet<string> metricStreamNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<InstrumentIdentity, Metric> instrumentIdentityToMetric = new Dictionary<InstrumentIdentity, Metric>();
private readonly ConcurrentDictionary<InstrumentIdentity, Metric> instrumentIdentityToMetric = new ConcurrentDictionary<InstrumentIdentity, Metric>();
private readonly object instrumentCreationLock = new object();
private int maxMetricStreams;
private int maxMetricPointsPerMetricStream;
Expand Down Expand Up @@ -231,6 +232,7 @@ private Batch<Metric> GetMetricsBatch()
if (metric.InstrumentDisposed)
{
metricPointSize = metric.Snapshot();
this.instrumentIdentityToMetric.TryRemove(metric.InstrumentIdentity, out var _);
this.metrics[i] = null;
}
else
Expand Down

0 comments on commit 0ff1d22

Please sign in to comment.