Skip to content

Reconsider ResourceDetectors namespaces and usages #1610

Description

@julealgon

Issue that does not fit into other categories

What are you trying to achieve?

Each resource detector package today has a unique namespace. This results in substantial noise when including multiple detectors in a project, a situation which is fairly common. 

Here is an example of a recent change on one of our projects:
image

This also goes against the design of other components such as instrumentations and exporters, which follow the main namespaces of their respective metric type. Eg:

namespace OpenTelemetry.Metrics;
/// <summary>
/// Extension methods to simplify registering of ASP.NET request instrumentation.
/// </summary>
public static class MeterProviderBuilderExtensions
{
/// <summary>
/// Enables the incoming requests automatic data collection for ASP.NET.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddAspNetInstrumentation(this MeterProviderBuilder builder) =>

The main difference between these 2 is that detectors don't come with custom extension methods on ResourceBuilder, while other components are usually added via extensions on TracerProviderBuilder and MeterProviderBuilder.

What do you expect to see?

I'd like to see one of 3 approaches here:

  1. Have all OpenTelemetry.ResourceDetectors.* packages have a root namespace of OpenTelemetry.ResourceDetectors
  2. Have all OpenTelemetry.ResourceDetectors.* packages have a root namespace of OpenTelemetry.Resources
  3. Have all OpenTelemetry.ResourceDetectors.* packages provide .Add{detector_name}Detector extension methods on top of ResourceBuilder and targeting namespace OpenTelemetry.Resources

From a consistency standpoint, I believe 3 would be the best as it stands today. After that, I like 2 as it doesn't introduce a new namespace, and then 3 as it at least unifies all of them in a single namespace.

The caveat with 2 and 1 is that they would potentially also apply to all other projects in a similar way, so it would make sense to apply them more broadly than just for Resource Detector packages.

Additionally, opting for 2 could prompt a different naming scheme altogether which I think would be more fitting, from "ResourceDetector" to just "Resources":

  • OpenTelemetry.ResourceDetectors.Host -> OpenTelemetry.Resources.Host

Additional context.

I believe the current approach is extremely noisy and won't scale well as even more detectors are introduced. Additionally, even without regard to the noise issue, I dislike very granular namespaces like this and am fond of the pattern of "child" assemblies NOT including the last segment of the assembly name in the final namespace. This is a common approach in many libraries, for example
Microsoft.Extensions.DependencyInjection vs Microsoft.Extensions.DependencyInjection.Abstractions, where the "Abstractions" in the assembly name does not participate in the final namespace of the classes inside:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions