From 0273ef96c1aa2ce39dd849dee646b650c699543b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCsters?= Date: Fri, 12 Jan 2024 13:49:02 +0100 Subject: [PATCH] Revert "Merge pull request #61 from wemogy/feature/improve-manual-setup" This reverts commit a8845d507c9326f6765e6841eb638accf387cfac, reversing changes made to 96bccbcac4604773a18c819fdda61f19a369c027. --- .../Monitoring/MonitoringExtensions.cs | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/Wemogy.AspNet/Monitoring/MonitoringExtensions.cs b/src/Wemogy.AspNet/Monitoring/MonitoringExtensions.cs index ddd6a5b..399d585 100644 --- a/src/Wemogy.AspNet/Monitoring/MonitoringExtensions.cs +++ b/src/Wemogy.AspNet/Monitoring/MonitoringExtensions.cs @@ -21,17 +21,10 @@ public static IServiceCollection AddDefaultMonitoring( throw new ArgumentException("MonitoringEnvironment is not configured."); } - return services.AddDefaultMonitoring(options.MonitoringEnvironment); - } - - public static IServiceCollection AddDefaultMonitoring( - this IServiceCollection services, - MonitoringEnvironment monitoringEnvironment) - { // Metrics services.AddOpenTelemetry().WithMetrics(builder => { - foreach (var meterName in monitoringEnvironment.MeterNames) + foreach (var meterName in options.MonitoringEnvironment.MeterNames) { builder.AddMeter(meterName); } @@ -40,7 +33,7 @@ public static IServiceCollection AddDefaultMonitoring( builder.AddHttpClientInstrumentation(); builder.AddAspNetCoreInstrumentation(); - if (monitoringEnvironment.UsePrometheus) + if (options.MonitoringEnvironment.UsePrometheus) { builder.AddPrometheusExporter(); } @@ -52,40 +45,40 @@ public static IServiceCollection AddDefaultMonitoring( builder.ConfigureResource((resource) => { resource.AddService( - serviceName: monitoringEnvironment.ServiceName, - serviceNamespace: monitoringEnvironment.ServiceNamespace, - serviceInstanceId: monitoringEnvironment.ServiceInstanceId, - serviceVersion: monitoringEnvironment.ServiceVersion); + serviceName: options.MonitoringEnvironment.ServiceName, + serviceNamespace: options.MonitoringEnvironment.ServiceNamespace, + serviceInstanceId: options.MonitoringEnvironment.ServiceInstanceId, + serviceVersion: options.MonitoringEnvironment.ServiceVersion); }); builder.AddAspNetCoreInstrumentation(); builder.AddEntityFrameworkCoreInstrumentation(); - foreach (var activitySourceName in monitoringEnvironment.ActivitySourceNames) + foreach (var activitySourceName in options.MonitoringEnvironment.ActivitySourceNames) { builder.AddSource(activitySourceName); } - if (monitoringEnvironment.UseOtlpExporter) + if (options.MonitoringEnvironment.UseOtlpExporter) { builder.AddOtlpExporter(oltpOptions => { - oltpOptions.Endpoint = monitoringEnvironment.OtlpExportEndpoint; + oltpOptions.Endpoint = options.MonitoringEnvironment.OtlpExportEndpoint; }); } }); // Azure - if (monitoringEnvironment.UseApplicationInsights) + if (options.MonitoringEnvironment.UseApplicationInsights) { services.AddOpenTelemetry().UseAzureMonitor(azureMonitorOptions => { - azureMonitorOptions.ConnectionString = monitoringEnvironment.ApplicationInsightsConnectionString; - azureMonitorOptions.SamplingRatio = monitoringEnvironment.ApplicationInsightsSamplingRatio; + azureMonitorOptions.ConnectionString = options.MonitoringEnvironment.ApplicationInsightsConnectionString; + azureMonitorOptions.SamplingRatio = options.MonitoringEnvironment.ApplicationInsightsSamplingRatio; }); } - services.AddSingleton(monitoringEnvironment); + services.AddSingleton(options.MonitoringEnvironment); return services; } @@ -98,14 +91,7 @@ public static void UseDefaultMonitoring( throw new ArgumentException("OpenApiEnvironment is not configured."); } - applicationBuilder.UseDefaultMonitoring(options.MonitoringEnvironment); - } - - public static void UseDefaultMonitoring( - this IApplicationBuilder applicationBuilder, - MonitoringEnvironment monitoringEnvironment) - { - if (monitoringEnvironment.UsePrometheus) + if (options.MonitoringEnvironment.UsePrometheus) { applicationBuilder.UseOpenTelemetryPrometheusScrapingEndpoint(); }