0

I'm working with OpenTelemetry and trying to encapsulate the logic by internal library which means prevent using OpenTelemetry public API and spread logic between the projects, means there is only one place to do the stuff. I close public usage by <PackageReference Include="OpenTelemetry" Version="1.5.1" PrivateAssets="All" /> everything is fine with regular inheritances which mean I can inherit base logic and provide ability to manipulate it by internal even if it such as marker interface

public class OtlpOptions : OtlpExporterOptions {
}

I think would be great hide the OT api and prowide such as simple common access through the extensions like

 var builder = WebApplication.CreateBuilder(args);            
 builder.Services.AddOpenTelemetryTracing().WithOtelExporter().WithConsoleExporter();
 builder.Services.AddOpenTelemetryMetrics().WithConsoleExporter();

but the problem that is too many abstraction on it like https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Api/Trace/TracerProviderBuilder.cs and I cannot create marker interface for abstraction class without reference on that abstraction which means encapsulation doesn't work and required particular reference. And I wanna know how to encapsulate the abstraction?

UPD: It's kind a weird that if I call extension tpBuilder.WithOtelExporter() it requires reference other way if I call static method MyOpenTelemetryExtension.WithOtelExporter(tpBuilder) it is not required reference

3
  • What do you mean by "it requires reference"? I don't have any experience with OpenTelemetry, but at the moment this question is really confusing... Commented Aug 14, 2023 at 13:36
  • @JonSkeet required a reference of the target abstraction library into consumer of the library which means webAPI<-MyExtensionLib<-OpenTelemetry required webAPI<-OpenTelemetry that i want to in fact encapsulate by MyExtensionLib Commented Aug 14, 2023 at 13:44
  • Okay, so you're talking about a package reference, rather than an object reference. That wasn't clear (and still isn't mentioned in the question - readers shouldn't have to read comments). I wouldn't expect it to matter whether you have an extension method or a plain static method - a minimal reproducible example showing the difference (complete code, with the error message in the failing exmaple) would make it a lot clearer what you're asking. Commented Aug 14, 2023 at 14:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.