Skip to content

[CONFIGURATION] Provider builder interfaces - #4426

Open
dbarker wants to merge 4 commits into
open-telemetry:mainfrom
dbarker:configured_provider_interfaces
Open

[CONFIGURATION] Provider builder interfaces#4426
dbarker wants to merge 4 commits into
open-telemetry:mainfrom
dbarker:configured_provider_interfaces

Conversation

@dbarker

@dbarker dbarker commented Aug 13, 2026

Copy link
Copy Markdown
Member

Contributes to #4352 (Step three from #4352 (comment))

This PR creates {Tracer,Logger,Meter}Provider builder interfaces and adds config Registry slots for them.

These builder interfaces are required for two main reasons:

  1. The SdkBuilder can use them and no longer require a link time dependency on the SDK trace/metrics/logs libraries. This will allow configuration_core to be a pure configuration library with no signal library dependencies.
  2. To allow users to register custom builders for SDK providers in order to use the C++ SDK specific options not available through the config schema (e.g. any option that can only be set through the provider factories or constructors).

These builder interfaces are driven by the configuration specification for the Config SDK Create method. The spec requires the create method return SDK provider types. Currently they intentionally do not support building any provider derived from the OTel C++ API, however the builders may be extended in the future to support this (through added virtual functions) if the spec changes.

Changes

  • Adds builder interfaces for the Tracer/Meter/Logger providers that create and return SDK Providers.
  • Updates the registry and test
  • Add a default constructor to MeterProvider and make the three arg constructor explicit but not default constructable. This is required to allow sdk/metrics/meter_provider.h to be included by configured_sdk.cc to support the upcast to API shared ptrs without creating a link time dependency.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@dbarker
dbarker marked this pull request as ready for review August 13, 2026 19:15
@dbarker
dbarker requested a review from a team as a code owner August 13, 2026 19:15
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.65%. Comparing base (57253cd) to head (dec84b2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4426      +/-   ##
==========================================
+ Coverage   82.61%   82.65%   +0.04%     
==========================================
  Files         511      514       +3     
  Lines       20132    20161      +29     
==========================================
+ Hits        16631    16662      +31     
+ Misses       3501     3499       -2     
Files with missing lines Coverage Δ
...e/opentelemetry/sdk/configuration/configured_sdk.h 100.00% <ø> (ø)
...emetry/sdk/configuration/logger_provider_builder.h 100.00% <100.00%> (ø)
...lemetry/sdk/configuration/meter_provider_builder.h 100.00% <100.00%> (ø)
...include/opentelemetry/sdk/configuration/registry.h 100.00% <100.00%> (ø)
...emetry/sdk/configuration/tracer_provider_builder.h 100.00% <100.00%> (ø)
sdk/src/configuration/configured_sdk.cc 85.72% <ø> (ø)
sdk/src/configuration/registry.cc 100.00% <100.00%> (ø)
sdk/src/metrics/meter_provider.cc 93.34% <100.00%> (+1.03%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread sdk/include/opentelemetry/sdk/configuration/configured_tracer_provider.h Outdated
@dbarker
dbarker marked this pull request as draft August 15, 2026 17:15
* @param meter_configurator Provides access to a function that computes the MeterConfig for
* Meters provided by this MeterProvider.
*/
MeterProvider(

@dbarker dbarker Aug 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This three arg constructor takes views, resource, and a configurator but also provides defaults for all three making the constructor default-constructible. This is generally okay, however on Windows DLL builds any TU that only includes the header and does not instantiate the MeterProvider still requires linking to the metrics library, when it is not necessary in order to avoid link errors:

error LNK2019: unresolved external symbol MeterConfig::Default(void)
  referenced in function MeterProvider::`default constructor closure'(void) (??_F...)
error LNK2019: unresolved external symbol MeterProvider::MeterProvider(unique_ptr<ViewRegistry>, ...)
  referenced in function MeterProvider::`default constructor closure'(void) (??_F...)

In configured_sdk.cc the Install method sets the global provider singletons from the configured SDK types and this requires a shared_ptr upcast to the API types. This can be done at compile time with only including the header files for the SDK providers and not require a link-time dependency on the SDK signal libraries.

This change to add a default constructor and make the three arg constructor explicit resolves the issue and Windows DLL builds can support ConfiguredSdk::Install without requiring configuration_core to link to opentelemetry_metrics

@dbarker dbarker added the pr:please-review This PR is ready for review label Aug 17, 2026
@dbarker dbarker changed the title [CONFIGURATION] Configured provider interfaces [CONFIGURATION] Provider builder interfaces Aug 21, 2026
/**
* Configuration context for building a logger provider.
*/
struct LoggerProviderBuilderContext

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale for adding these builder context structs is to support future args being passed from the root configuration node into the provider builders without requiring a change to the builder interface virtual functions.

struct MeterProviderBuilderContext
{
/** Registry is required and must not be null. */
const Registry *registry{nullptr};

@dbarker dbarker Aug 21, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in the registry allows the provider builders to take over the role of building signal specific SDK components. This means those SdkBuilder::Create* methods that are signal specific can be moved to the signal builders library (where the concrete signal provider builder will live) and the dependency between the signal library and SdkBuilder can be removed.

return sdk;
}

void ConfiguredSdk::Install()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Install method is a nice addition to the ConfiguredSdk interface and is an otel-cpp extension of the spec. We can continue to support it and break the ConfiguredSdk's dependency on signal libraries by forward declaring the SDK providers in the ConfiguredSdk header, then only including the provider headers here in this .cc.

The compiler just needs to see the declaration of the providers for the upcasts below and no link to the signal libraries are needed for this.

The only catch is with the MeterProvider (it has a default-constructible constructor with all defaulted arguments that the Windows DLL build requires a link to the metrics library for), but this can be resolved with the changes here https://github.com/open-telemetry/opentelemetry-cpp/pull/4426/changes#r3792380516.

TracerProviderBuilder &operator=(const TracerProviderBuilder &other) = default;
virtual ~TracerProviderBuilder() = default;

virtual std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> Build(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using shared_ptr for the return type allows the SDK provider to be forward declared and the SdkBuilder (which will get the provider builder from the registry and call Build when creating the ConfiguredSdk object) to not require a link to the signal libraries (metrics, trace, logs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:please-review This PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant