Skip to content

Commit

Permalink
Modify MeterProvider to no longer maintain instrument state as it is …
Browse files Browse the repository at this point in the history
…expected to come from the API callbacks (#2134)
  • Loading branch information
cijothomas authored Jul 14, 2021
1 parent be1d13f commit 8f525df
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class MeterProviderSdk
private readonly List<Task> collectorTasks = new List<Task>();
private readonly MeterListener listener;

private readonly object lockInstrumentStates = new object();
private readonly Dictionary<Instrument, InstrumentState> instrumentStates = new Dictionary<Instrument, InstrumentState>();

internal MeterProviderSdk(
IEnumerable<string> meterSources,
MeasurementProcessor[] measurementProcessors,
Expand All @@ -66,12 +63,6 @@ internal MeterProviderSdk(
if (meterSourcesToSubscribe.ContainsKey(instrument.Meter.Name))
{
var instrumentState = new InstrumentState(this, instrument);

lock (this.lockInstrumentStates)
{
this.instrumentStates.Add(instrument, instrumentState);
}

listener.EnableMeasurementEvents(instrument, instrumentState);
}
},
Expand Down Expand Up @@ -130,17 +121,12 @@ internal void MeasurementRecorded<T>(Instrument instrument, T value, ReadOnlySpa
where T : struct
{
// Get Instrument State
var instrumentState = state as InstrumentState;

if (!(state is InstrumentState instrumentState))
if (instrument == null)
{
lock (this.lockInstrumentStates)
{
if (!this.instrumentStates.TryGetValue(instrument, out instrumentState))
{
instrumentState = new InstrumentState(this, instrument);
this.instrumentStates.Add(instrument, instrumentState);
}
}
// TODO: log
return;
}

var measurementItem = new MeasurementItem(instrument, instrumentState);
Expand Down

0 comments on commit 8f525df

Please sign in to comment.