Question: Change namespace of extension methods?#1541
Question: Change namespace of extension methods?#1541alanwest wants to merge 1 commit intoopen-telemetry:masterfrom
Conversation
|
Cant think of the "perfect" solution here. Want to hear more opinions on this. |
Yes, I'm finding this to be true, as well. I do not have strong opinions here, but I do lean towards making extension methods as easy to discover as possible. To me, it's a bit of a usability concern when I'm learning a new library and copy and paste some sample code only to find that the code uses an extension method and I'm left wondering either what namespace I need to include or what package I'm missing. Though, I suppose we've done a pretty good job of including the appropriate usings in our sample code. Most important to me is that we have clear guidance so that we can remain consistent with whatever we decide. I've noticed we have a few different flavors for handling extension methods: Flavor #1: Extension on an OTel SDK typeAt the moment, we're mostly putting extension methods for OTel SDK types in the same namespace as the type they are extending. This make sense organizationally, though as demonstrated in this PR, it may be common that code is implicitly using an OTel type (i.e., Flavor #2: Extension on a non-OTel SDK typeI think it makes sense to follow whatever precedence already exists for extension methods on these types, and from what I can tell we are following this. For example, the extension methods on Flavor #3: Extension on an OTel SDK type, but treating it as though it was non-OTelI've found one example of this - it may have been unintentional... |
|
Closing in favor of #1576 |
I'm putting this out here to pose a question regarding the namespaces we've chosen for some of our extension methods. We may very well not want to adopt any of the changes I've made here.
Background
We have many extension methods off of
TracerBuilderProvider. Extension methods are great, but often can be a little tricky for a newcomer to a library since in some contexts they'll need to make sure they add the appropriateusingstatements.For example, in the context of an ASP.NET Core app one might write the following:
This example code requires the user to know to add both
using OpenTelemetry.Traceandusing OpenTelemetry.Metricsto expose the necessary extension methods.Question
Does it make sense to keep extension methods for OpenTelemetry types (i.e.,
TracerProviderBuilder,MeterProviderBuilder, etc) in a single namespace likeOpenTelemetryorOpenTelemetry.Extensions? Adding a using statement would still be required, but the benefit would be that a single using statement would make all extension methods available.The change here is in the context of the Zipkin and Jaeger exporters, but as shown, this question applies to our extension methods defined in instrumentation projects as well. Also, note that this would be a small breaking change.