Skip to content

Can't inject resource detectors after upgrading to 1.4.0-rc.3 #4139

@austindrenski

Description

@austindrenski

Bug Report

This morning I started integrating last night's release of 1.4.0-rc.3 and quickly encountered some trouble caused by the removal of ConfigureBuilder(...) in #4103.

I've looked around for alternative APIs, but it seems that the alternatives are also marked internal:

// Note: This API may be made public if there is a need for it.
internal ResourceBuilder AddDetector(Func<IServiceProvider?, IResourceDetector> resourceDetectorFactory)
{
Guard.ThrowIfNull(resourceDetectorFactory);
this.ResourceDetectors.Add(new ResolvingResourceDetector(resourceDetectorFactory));
return this;
}

Big fan of this project and all the hard work you folks are doing, so if this is user error, I'd appreciate a pointer in the right direction, but if not, would greatly appreciate seeing this functionality return soon so I can keep my projects on track with 1.4.0-rc.3.

What is the expected behavior?

Bumping from 1.4.0-rc.2 to 1.4.0-rc.3 does not break resource builder DI functionality.

What is the actual behavior?

Bumping from 1.4.0-rc.2 to 1.4.0-rc.3 breaks resource builder DI functionality.

Reproduce

With versions 1.4.0-rc.2, I can use the ConfigureBuilder(...) method to inject custom resource detectors from an IServiceProvider.

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddOpenTelemetry()
    .StartWithHost()
    .WithMetrics(static builder => builder
        .ConfigureBuilder(static (services, builder) => builder
            .SetResourceBuilder(ResourceBuilder
                .CreateDefault()
                .AddDetector(services.GetRequiredService<SomeResourceDetector>())
                .AddTelemetrySdk()))
        .ConfigureServices(static services => services
            .AddSingleton<SomeResourceDetector>())
    .WithTracing(static builder => builder
        .ConfigureBuilder(static (services, builder) => builder
            .SetResourceBuilder(ResourceBuilder
                .CreateDefault()
                .AddDetector(services.GetRequiredService<SomeResourceDetector>())
                .AddTelemetrySdk()))
        .ConfigureServices(static services => services
            .AddSingleton<SomeResourceDetector>());

var app = builder.Build();

app.Run();

In my actual use case, there are many custom resource detectors, not just SomeResourceDetector, but here's a contrived concrete example to illustrate why its being injected:

// contrived example, don't read into it
sealed class SomeResourceDetector : IResourceDetector
{
    readonly Resource _resource;

    public SomeResourceDetector(IHostEnvironment environment)
        => _resource = ResourceBuilder
            .CreateEmpty()
            .AddAttributes(new Dictionary<string, object>
            {
                ["deployment.environment"] = Check.NotNull(environment).EnvironmentName
            })
            .Build();

    public Resource Detect() => _resource;
}
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.4.0-rc.3" />
  </ItemGroup>

</Project>

Additional Context

I'm not necessarily asking for ConfigureBuilder(...) itself to be brought back (it seems like there was some rationale behind removing it from the public API in #4103), but I would like to see the functionality to inject resource detectors (and other things that might be useful when programmatically configuring a resource builder) restored.

Potentially off-topic context that might still be relevant to the team

I'm a big advocate for OTel generally, and your team's work specifically, in my organization and unfortunately breaking functionality like this (even cognizant of the pre-release status) invites FUD about overall reliability from the non-believers yet-to-be-converted.

I believe in this project, so I'm happy to keep answering those questions, but wanted to bubble some non-technical "impact" of this breakage in light of recent discussions around community impression of project stability in issues like #4083 (comment) by @CodeBlanch, @martinjt, and others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions