public void TestPutDimension() { var dimensionName = "dim"; var dimensionValue = "dimValue"; _metricsLogger.PutDimensions(new DimensionSet(dimensionName, dimensionValue)); _metricsLogger.Flush(); Assert.Single(_sink.MetricsContext.GetAllDimensionSets()); Assert.Equal(dimensionValue, _sink.MetricsContext.GetAllDimensionSets()[0].GetDimensionValue(dimensionName)); }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public string FunctionHandler(string input, ILambdaContext context) { var envProvider = new EnvironmentProvider(EnvironmentConfigurationProvider.Config, new ResourceFetcher()); var logger = new MetricsLogger(); var dimensionSet = new DimensionSet(); dimensionSet.AddDimension("Service", "Aggregator"); dimensionSet.AddDimension("Region", "us-west-2"); logger.PutDimensions(dimensionSet); logger.SetNamespace("EMFLambda"); logger.PutMetric("ProcessingLatency", 101, Unit.MILLISECONDS); logger.PutMetric("ProcessingLatency", 100, Unit.MILLISECONDS); logger.PutMetric("ProcessingLatency", 99, Unit.MILLISECONDS); logger.PutMetric("Count", 3, Unit.COUNT); logger.PutProperty("AccountId", "123456789"); logger.PutProperty("RequestId", "422b1569-16f6-4a03-b8f0-fe3fd9b100f8"); logger.PutProperty("DeviceId", "61270781-c6ac-46f1-baf7-22c808af8162"); Dictionary <string, object> payLoad = new Dictionary <string, object> { { "sampleTime", 123456789 }, { "temperature", 273.0 }, { "pressure", 101.3 } }; logger.PutProperty("Payload", payLoad); logger.Flush(); return(input?.ToUpper()); }
private void LogMetric(String metricName) { MetricsLogger logger = new MetricsLogger(new EnvironmentProvider(EnvironmentConfigurationProvider.Config, new ResourceFetcher()), NullLoggerFactory.Instance); logger.PutDimensions(_dimensions); logger.PutMetric(metricName, 100, Unit.MILLISECONDS); logger.Flush(); }