Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Otlp exporter when configured using builder.Services.ConfigureOpenTelemetryTracerProvider #4503

Closed
vishweshbankwar opened this issue May 18, 2023 · 0 comments · Fixed by #4508
Labels
bug Something isn't working

Comments

@vishweshbankwar
Copy link
Member

Bug Report

Tested with 1.4.0 on .NET7.0

Symptom

A clear and concise description of what the bug is.
System.NotSupportedException: 'Services cannot be configured after ServiceProvider has been created.' exception is thrown when otlp exporter is configured using builder.Services.ConfigureOpenTelemetryTracerProvider alongside services.AddOpenTelemetry().WithTracing

What is the expected behavior?
Traces are exported to both console and otlp exporter.

What is the actual behavior?
Startup error

System.NotSupportedException
  HResult=0x80131515
  Message=Services cannot be configured after ServiceProvider has been created.
  Source=OpenTelemetry
  StackTrace:
   at OpenTelemetry.Trace.TracerProviderBuilderSdk.ConfigureServices(Action`1 configure) in /_/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderSdk.cs:line 179
   at OpenTelemetry.Trace.OpenTelemetryDependencyInjectionTracerProviderBuilderExtensions.ConfigureServices(TracerProviderBuilder tracerProviderBuilder, Action`1 configure) in /_/src/OpenTelemetry.Api.ProviderBuilderExtensions/Trace/OpenTelemetryDependencyInjectionTracerProviderBuilderExtensions.cs:line 139
   at OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(TracerProviderBuilder builder, String name, Action`1 configure) in /_/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs:line 77
   at OpenTelemetry.Trace.OtlpTraceExporterHelperExtensions.AddOtlpExporter(TracerProviderBuilder builder) in /_/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs:line 37
   at Program.<>c.<<Main>$>b__0_1(IServiceProvider sp, TracerProviderBuilder builder) in C:\Users\vibankwa\source\repos\TestAzureMonitorDistro\TestAzureMonitorDistro\Program.cs:line 21
   at OpenTelemetry.Trace.OpenTelemetryDependencyInjectionTracingServiceCollectionExtensions.ConfigureTracerProviderBuilderCallbackWrapper.ConfigureBuilder(IServiceProvider serviceProvider, TracerProviderBuilder tracerProviderBuilder) in /_/src/OpenTelemetry.Api.ProviderBuilderExtensions/Trace/OpenTelemetryDependencyInjectionTracingServiceCollectionExtensions.cs:line 83
   at OpenTelemetry.Trace.TracerProviderSdk..ctor(IServiceProvider serviceProvider, Boolean ownsServiceProvider) in /_/src/OpenTelemetry/Trace/TracerProviderSdk.cs:line 296
   at OpenTelemetry.Trace.TracerProviderBuilderBase.<>c.<.ctor>b__3_0(IServiceProvider sp) in /_/src/OpenTelemetry/Trace/Builder/TracerProviderBuilderBase.cs:line 59
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) in /_/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteVisitor.cs:line 44
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) in /_/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteRuntimeResolver.cs:line 92
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) in /_/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteVisitor.cs:line 27
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) in /_/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteRuntimeResolver.cs:line 30
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) in /_/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceProvider.cs:line 172
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) in /_/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs:line 1152
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) in /_/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceProvider.cs:line 131
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) in /_/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceProviderServiceExtensions.cs:line 25
   at OpenTelemetry.Extensions.Hosting.Implementation.TelemetryHostedService.Initialize(IServiceProvider serviceProvider) in /_/src/OpenTelemetry.Extensions.Hosting/Implementation/TelemetryHostedService.cs:line 62
   at OpenTelemetry.Extensions.Hosting.Implementation.TelemetryHostedService.StartAsync(CancellationToken cancellationToken) in /_/src/OpenTelemetry.Extensions.Hosting/Implementation/TelemetryHostedService.cs:line 44
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__12.MoveNext() in /_/src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs:line 71
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext() in /_/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs:line 66
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext() in /_/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs:line 76
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) in /_/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs:line 51
   at Program.<Main>$(String[] args) in 

Reproduce

Create a new ASP.NET Core app and add following lines

builder.Services.AddOpenTelemetry()
    .WithTracing(builder => builder.AddConsoleExporter());

builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.AddOtlpExporter());

The behavior is same with
builder.Services.ConfigureOpenTelemetryMeterProvider((sp, builder) => builder.AddOtlpExporter());

Additional Context

Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant