public void TestPutProperty()
        {
            var propertyName  = "Property";
            var propertyValue = "PropValue";

            _metricsLogger.PutProperty(propertyName, propertyValue);
            _metricsLogger.Flush();
            Assert.Equal(propertyValue, _sink.MetricsContext.GetProperty(propertyName));
        }
        /// <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());
        }
Exemplo n.º 3
0
        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();
        }
        public void TestFlushWithDefaultDimensionDefined()
        {
            MetricsContext metricsContext = new MetricsContext();

            metricsContext.DefaultDimensions.Dimensions.Add("foo", "bar");
            _metricsLogger = new MetricsLogger(_environment, metricsContext, _logger);
            string logGroup = "TestLogGroup";

            _environment.LogGroupName.Returns(logGroup);
            _metricsLogger.Flush();

            ExpectDimension("foo", "bar");
            ExpectDimension("LogGroup", null);
        }
        public void TestOverrideDefaultDimensions()
        {
            var dimensionName   = "dim";
            var dimensionValue  = "dimValue";
            var defaultDimName  = "defaultDim";
            var defaultDimValue = "defaultDimValue";

            MetricsContext metricsContext = new MetricsContext();

            metricsContext.DefaultDimensions.AddDimension(defaultDimName, defaultDimValue);
            metricsContext.SetDimensions(new DimensionSet(defaultDimName, defaultDimValue));

            _metricsLogger = new MetricsLogger(_environment, metricsContext, _logger);
            _metricsLogger.SetDimensions(new DimensionSet(dimensionName, dimensionValue));
            _metricsLogger.Flush();

            Assert.Single(_sink.MetricsContext.GetAllDimensionSets());
            Assert.Null(_sink.MetricsContext.GetAllDimensionSets()[0].GetDimensionValue(defaultDimName));
        }