diff --git a/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs b/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs index 4fe656085..c1388ec0d 100644 --- a/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs +++ b/src/Digdir.Library.Utils.AspNet/AspNetUtilitiesExtensions.cs @@ -141,22 +141,26 @@ public static WebApplicationBuilder ConfigureTelemetry( .AddNpgsql() .AddFusionCacheInstrumentation(); }); - } - else - { - Console.WriteLine("[OpenTelemetry] OTLP exporter not configured - skipping"); - } - if (!string.IsNullOrEmpty(settings.AppInsightsConnectionString)) - { telemetryBuilder.WithMetrics(metrics => { metrics.AddRuntimeInstrumentation() .AddAspNetCoreInstrumentation() - .AddHttpClientInstrumentation() - .AddAzureMonitorMetricExporter(); + .AddHttpClientInstrumentation(); + + if (!string.IsNullOrEmpty(settings.AppInsightsConnectionString)) + { + metrics.AddAzureMonitorMetricExporter(options => + { + options.ConnectionString = settings.AppInsightsConnectionString; + }); + } }); } + else + { + Console.WriteLine("[OpenTelemetry] OTLP exporter not configured - skipping"); + } return builder; }