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

Exception is thrown on non-standard IOC container due to use of Concrete classes. #5537

Open
PeterOscarsson opened this issue Apr 15, 2024 · 4 comments
Assignees
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package

Comments

@PeterOscarsson
Copy link

OpenTelemetry.Exporter 1.8
net8.0

Upgrading from 1.7 to 1.8 without any changes to our codebase.

This code is throwing exception:

 public static void EnsureNoUseOtlpExporterRegistrations(this IServiceProvider serviceProvider)
 {
     var registrations = serviceProvider.GetServices<UseOtlpExporterRegistration>();
     if (registrations.Any())
     {
         throw new NotSupportedException("Signal-specific AddOtlpExporter methods and the cross-cutting UseOtlpExporter method being invoked on the same IServiceCollection is not supported.");
     }
 }

My guess is that as we are using a non-default ServiceProvider (IUnityContainer), we get a concrete class even though it is not registred in the service collection.
Is it possible to refactor to use interfaces instead of concrete classes?

This is the only instance in all of the codebase we are using (asp.net mvc+ blazor, redis cache, Masstransit, ..) where this is a problem.

@CodeBlanch
Copy link
Member

Hey @PeterOscarsson any chance you could give me a small repro app using Unity + 1.8 OtlpExporter I can use to debug?

@CodeBlanch CodeBlanch self-assigned this Apr 19, 2024
@PeterOscarsson
Copy link
Author

Sure, put the attached project in the OpenTelemetry catalog and put a breakpoint on
EnsureNoUseOtlpExporterRegistrations in
opentelemetry-dotnet\src\OpenTelemetry.Exporter.OpenTelemetryProtocol\Builder\OpenTelemetryBuilderServiceProviderExtensions.cs

Check with and without "UseUnityServiceProvider" in main Program.

OTelTest.zip

@CodeBlanch
Copy link
Member

Thank you @PeterOscarsson! I opened this issue over in Unity: unitycontainer/microsoft-dependency-injection#96

I'm not opposed to just switching to an interface but I figured it would be good to gather their thoughts on the differing behavior before we took action. Seems like a behavior they might want to fix to prevent other things from breaking when choosing to use Unity over the M.S.E.DI container 🤷

@PeterOscarsson
Copy link
Author

@CodeBlanch ,Thats great, but I doubt you'll get an answer. Seems like its no longer activly maintained. Else I would have taken this up with them.
We are investigating switching DI but we have a huge CodeBase that depends on UnityContainer and it will take a while to do that.

@reyang reyang added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Projects
None yet
Development

No branches or pull requests

3 participants