in src/Amazon.CloudWatch.EMF.Web/ApplicationBuilderExtensions.cs [56:74]
public static void UseEmfMiddleware(this IApplicationBuilder app, Func<HttpContext, IMetricsLogger, Task> action)
{
app.Use(async (context, next) =>
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
await next.Invoke();
var config = context.RequestServices.GetRequiredService<EMF.Config.IConfiguration>();
var logger = context.RequestServices.GetRequiredService<IMetricsLogger>();
if (!String.IsNullOrEmpty(config.ServiceName)) {
logger.SetNamespace(config.ServiceName);
}
await action(context, logger);
stopWatch.Stop();
logger.PutMetric("Time", stopWatch.ElapsedMilliseconds, Model.Unit.MILLISECONDS);
});
}