public static HerculesSinkSettings SetupMetrics([NotNull] this HerculesSinkSettings settings, [NotNull] IMetricContext metricContext) { var oldSetup = settings.AdditionalSetup; settings.AdditionalSetup = setup => { oldSetup?.Invoke(setup); var newModule = new MetricsModule(metricContext); var oldModules = setup.Modules.Values.SelectMany(v => v.Before); var oldModule = oldModules.OfType <MetricsModule>().FirstOrDefault(); if (oldModule != null) { oldModule.AddNestedModule(newModule); } else { setup.AddRequestModule(newModule); } }; return(settings); }
public void AddNestedModule(MetricsModule module) { if (nestedModule == null) { nestedModule = module; } else { nestedModule.AddNestedModule(module); } }