-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Diagnostics (Observability) work planned for .NET 7 #62027
Comments
Tagging subscribers to this area: @tommcdon Issue DetailsThis issue is listing the candidate features/work for .NET 7.0. This list is expected to change according to the discussions and planning. We expect this list will be filtered and possibly other items can be added.
|
@tarekgh this OpenTelemetry spec feature is really important for a lot of scenarios: I am attempting to populate queue stats like queue count, working item count and deadletter counts as 3 different observable gauges. Getting the counts requires an expensive call and, when I make that, it returns all 3 counts at the same time. The problem is since gauges are required to be observable, I have to give different callbacks for each gauge. I think there are a lot of similar use cases that would greatly benefit from this feature being implemented. |
@ejsmith thanks for the suggestion. For now, you may solve this by using the following simple workaround: public class InstrumentsValues<T1, T2, T3>
where T1 : struct
where T2 : struct
where T3 : struct
{
private T1? _value1;
private T2? _value2;
private T3? _value3;
private Func<(T1, T2, T3)> UpdateValues { get; set; }
public InstrumentsValues(Func<(T1, T2, T3)> readValues)
{
_value1 = null;
_value2 = null;
_value3 = null;
UpdateValues = readValues;
}
public T1 GetValue1()
{
if (!_value1.HasValue)
{
(_value1, _value2, _value3) = UpdateValues();
}
T1 value = _value1.Value;
_value1 = null;
return value;
}
public T2 GetValue2()
{
if (!_value2.HasValue)
{
(_value1, _value2, _value3) = UpdateValues();
}
T2 value = _value2.Value;
_value2 = null;
return value;
}
public T3 GetValue3()
{
if (!_value3.HasValue)
{
(_value1, _value2, _value3) = UpdateValues();
}
T3 value = _value3.Value;
_value3 = null;
return value;
}
} and here is an example how to use it: Random random = new Random();
using Meter meter = new Meter("My Meter");
InstrumentsValues<int, long, double> values = new InstrumentsValues<int, long, double>(() => (random.Next(), random.NextInt64(), random.NextDouble()));
ObservableCounter<int> observableCounter1 = meter.CreateObservableCounter<int>("Counter 1", () => new Measurement<int>(values.GetValue1(), new KeyValuePair<string, object?>("Counter 1", null)));
ObservableGauge<long> observableGauge = meter.CreateObservableGauge<long>("Gauge 1", () => new Measurement<long>(values.GetValue2(), new KeyValuePair<string, object?>("Gauge 1", null)));
ObservableCounter<double> observableCounter2 = meter.CreateObservableCounter<double>("Counter 2", () => new Measurement<double>(values.GetValue3(), new KeyValuePair<string, object?>("Counter 2", null))); I assume your gauges are going to be observed at the same time. But if not, it is easy to tweak this implementation to invalidate the values periodically. |
@tarekgh I'll give this method a try. I tried something similar, but it didn't work. |
@tarekgh that did work. Thank you! |
@tarekgh - how do you feel about closing this issue and we can re-open a new one once we've made plans with the OpenTelemetry folks for .NET 8? We can always refer back to this issue if we want to see the list of items we were considering - the list won't be lost. |
This issue captures the planned work for .NET 7. This list is expected to change throughout the release cycle according to ongoing planning and discussions, with possible additions and subtractions to the scope.
Planned for .NET 7
Planned for .NET 8+
The text was updated successfully, but these errors were encountered: