Closed
Description
I had this code:
class MyMetricsLogger
{
private readonly MetricsLogger _metricsLogger = new MetricsLogger();
public void LogMetric(string key, double value, DimensionSet dimensionSet = null)
{
_metricsLogger.SetDimensions(dimensionSet);
_metricsLogger.PutMetric(key, value);
_metricsLogger.Flush();
}
}
Invoking MetricsLogger.SetDimensions
with null
will break the MetricsLogger. When it next tries to log any metrics there is a NullReferenceException thrown from
at Amazon.CloudWatch.EMF.Model.MetricDirective.<>c.<get_AllDimensionKeys>b__20_0(DimensionSet s)
There is a simple workaround, avoid using null when calling SetDimensions
.
if (dimensionSet != null)
{
_metricsLogger.SetDimensions(dimensionSet);
}
else
{
_metricsLogger.SetDimensions();
}
It is a weakness of the package design for me to have to do this, the null check should be handled gracefully within the package itself.