public static IServiceCollection AddMetrics(this IServiceCollection services, Action <MetricsBuilder> configure)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddOptions();

            services.AddSingleton <IMetricsBuilder, MetricsBuilder>(r =>
            {
                var builder = new MetricsBuilder(services, services.AddHealthChecks());
                configure(builder);
                return(builder);
            });

            services.TryAddSingleton <IMetricsStore, MemoryMetricsStore>();
            services.TryAddSingleton <IMetricsHost>(r =>
            {
                var host = new MetricsHost(r.GetRequiredService <IMetricsStore>());
                return(host);
            });
            services.TryAddSingleton <IMetricsRegistry>(r =>
            {
                var registry = new MemoryMetricsRegistry
                {
                    r.GetRequiredService <IMetricsHost>()
                };
                return(registry);
            });

            services.TryAdd(ServiceDescriptor.Singleton(typeof(IMetricsHost <>), typeof(MetricsHost <>)));
            services.TryAddEnumerable(ServiceDescriptor.Singleton <IHostedService, EventSourceHostedService>());

            return(services);
        }