[AspNetCore] [WorkerService] Setting the connection string throws exception when using the ConnectionString property in the appsettings json.
Applies to:
- Version: 3.0.0-beta1
- AspNetCore webapps & Worker Service
Issue: When setting the connection as below in appsettings.json, the underlying exporter will throw an exception saying that the connection string is not set.
"ApplicationInsights":
{
"ConnectionString" : "<YOUR-CONNECTION-STRING>"
}
The exception:
System.InvalidOperationException: A connection string was not found. Please set your connection string.
at Azure.Monitor.OpenTelemetry.Exporter.Internals.AzureMonitorTransmitter.InitializeConnectionVars(AzureMonitorExporterOptions options, IPlatform platform)
at Azure.Monitor.OpenTelemetry.Exporter.Internals.AzureMonitorTransmitter..ctor(AzureMonitorExporterOptions options, IPlatform platform)
at Azure.Monitor.OpenTelemetry.Exporter.Internals.TransmitterFactory.Get(AzureMonitorExporterOptions azureMonitorExporterOptions, IPlatform platform)
at Azure.Monitor.OpenTelemetry.Exporter.Internals.TransmitterFactory.Get(AzureMonitorExporterOptions azureMonitorExporterOptions)
at Azure.Monitor.OpenTelemetry.Exporter.AzureMonitorMetricExporter..ctor(AzureMonitorExporterOptions options)
at Azure.Monitor.OpenTelemetry.Exporter.OpenTelemetryBuilderExtensions.<>c__DisplayClass1_0.<UseAzureMonitorExporter>b__2(IServiceProvider serviceProvider, MeterProviderBuilder meterProviderBuilder)
at OpenTelemetry.Metrics.OpenTelemetryDependencyInjectionMetricsServiceCollectionExtensions.ConfigureMeterProviderBuilderCallbackWrapper.ConfigureBuilder(IServiceProvider serviceProvider, MeterProviderBuilder meterProviderBuilder)
at OpenTelemetry.Metrics.MeterProviderSdk..ctor(IServiceProvider serviceProvider, Boolean ownsServiceProvider)
at OpenTelemetry.Metrics.MeterProviderBuilderBase.<>c.<.ctor>b__3_0(IServiceProvider sp)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext
....
Workaround: Setting the connection string via the env var (APPLICATIONINSIGHTS_CONNECTION_STRING) or code still works.