Component
OpenTelemetry.Extensions
Is your feature request related to a problem?
Applications using the OpenTelemetry .NET SDK must register custom tracing sources and metric meters programmatically:
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddSource("MyCompany.Orders")
.AddSource("Npgsql"))
.WithMetrics(metrics => metrics
.AddMeter("MyCompany.Orders"));
In applications where instrumentation is selected at deployment time, the source and meter names need to come from IConfiguration. Every application currently has to implement the same binding code:
var tracingSources = builder.Configuration
.GetSection("OpenTelemetry:Tracing:Sources")
.Get<string[]>() ?? [];
var metricMeters = builder.Configuration
.GetSection("OpenTelemetry:Metrics:Meters")
.Get<string[]>() ?? [];
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing.AddSource(tracingSources))
.WithMetrics(metrics => metrics.AddMeter(metricMeters));
This is small but repeated infrastructure code. Implementations can also differ in how they handle missing sections, invalid values, configuration-provider compatibility, and diagnostics.
The zero-code instrumentation project offers OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES and OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES, but those settings do not configure applications using the OpenTelemetry SDK directly.
What is the expected behavior?
Add configuration-oriented extensions to OpenTelemetry.Extensions for registering ActivitySource and Meter names.
A possible API is:
namespace OpenTelemetry.Trace;
public static class TracerProviderBuilderConfigurationExtensions
{
public static TracerProviderBuilder AddSourcesFromConfiguration(
this TracerProviderBuilder builder,
IConfigurationSection section);
}
namespace OpenTelemetry.Metrics;
public static class MeterProviderBuilderConfigurationExtensions
{
public static MeterProviderBuilder AddMetersFromConfiguration(
this MeterProviderBuilder builder,
IConfigurationSection section);
}
The methods would read string-array configuration sections and delegate to the existing AddSource(params string[]) and AddMeter(params string[]) APIs.
Example configuration:
{
"OpenTelemetry": {
"Tracing": {
"Sources": [
"MyCompany.Orders",
"Npgsql"
]
},
"Metrics": {
"Meters": [
"MyCompany.Orders"
]
}
}
}
Example usage:
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing.AddSourcesFromConfiguration(
builder.Configuration.GetSection("OpenTelemetry:Tracing:Sources")))
.WithMetrics(metrics => metrics.AddMetersFromConfiguration(
builder.Configuration.GetSection("OpenTelemetry:Metrics:Meters")));
Because the caller supplies an IConfigurationSection, the extensions would not impose a fixed configuration hierarchy. Values could come from any standard configuration provider, including appsettings.json, environment variables, command-line arguments, Azure App Configuration, or a secrets provider.
Suggested behavior:
- A missing or empty section is a no-op.
- Null, empty, or whitespace-only entries fail during provider construction with an error that identifies the configuration path.
- Names are passed unchanged to the existing SDK APIs, retaining their matching and wildcard behavior.
- Duplicate handling remains consistent with the existing SDK APIs.
- Configuration is read when the provider is constructed.
- Configuration reload does not dynamically replace subscriptions, because
TracerProvider and MeterProvider subscriptions are established at startup.
- XML documentation should state the expected array shape and startup-only behavior.
For example, environment-variable configuration would continue to work through normal .NET configuration mapping:
OpenTelemetry__Tracing__Sources__0=MyCompany.Orders
OpenTelemetry__Tracing__Sources__1=Npgsql
OpenTelemetry__Metrics__Meters__0=MyCompany.Orders
Which alternative solutions or features have you considered?
-
Bind the arrays in every application
tracing.AddSource(
configuration.GetSection("OpenTelemetry:Tracing:Sources")
.Get<string[]>() ?? []);
This works, but requires repeated infrastructure code and each application must define its own validation and missing-section behavior.
-
Create an application-specific extension
Applications can implement AddSourcesFromConfiguration and AddMetersFromConfiguration themselves. This duplicates the same behavior across services and organizations.
-
Use zero-code auto-instrumentation environment variables
OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES and OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES provide similar functionality, but only for .NET automatic instrumentation. They do not configure an explicitly constructed OpenTelemetry SDK pipeline.
-
Use OpenTelemetry declarative configuration
OpenTelemetry.Configuration.Declarative is currently experimental and does not yet apply tracing-provider or metrics-provider configuration. Applications still need to call AddSource and AddMeter in code.
-
Use a third-party configuration package
Some third-party packages provide complete configuration-driven OpenTelemetry setup, but adopting an opinionated telemetry distribution is excessive when an application only needs to register source and meter names.
Additional context
This appears to fit OpenTelemetry.Extensions because it is a .NET-specific convenience around IConfiguration, rather than a new cross-language OpenTelemetry capability.
Passing an explicit IConfigurationSection also avoids defining configuration keys that could conflict with future OpenTelemetry declarative-configuration conventions.
The proposed names are intended to distinguish these startup configuration helpers from the existing AddSource and AddMeter methods, but alternative naming consistent with repository conventions would be welcome.
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Component
OpenTelemetry.Extensions
Is your feature request related to a problem?
Applications using the OpenTelemetry .NET SDK must register custom tracing sources and metric meters programmatically:
In applications where instrumentation is selected at deployment time, the source and meter names need to come from
IConfiguration. Every application currently has to implement the same binding code:This is small but repeated infrastructure code. Implementations can also differ in how they handle missing sections, invalid values, configuration-provider compatibility, and diagnostics.
The zero-code instrumentation project offers
OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCESandOTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES, but those settings do not configure applications using the OpenTelemetry SDK directly.What is the expected behavior?
Add configuration-oriented extensions to
OpenTelemetry.Extensionsfor registeringActivitySourceandMeternames.A possible API is:
The methods would read string-array configuration sections and delegate to the existing
AddSource(params string[])andAddMeter(params string[])APIs.Example configuration:
{ "OpenTelemetry": { "Tracing": { "Sources": [ "MyCompany.Orders", "Npgsql" ] }, "Metrics": { "Meters": [ "MyCompany.Orders" ] } } }Example usage:
Because the caller supplies an
IConfigurationSection, the extensions would not impose a fixed configuration hierarchy. Values could come from any standard configuration provider, includingappsettings.json, environment variables, command-line arguments, Azure App Configuration, or a secrets provider.Suggested behavior:
TracerProviderandMeterProvidersubscriptions are established at startup.For example, environment-variable configuration would continue to work through normal .NET configuration mapping:
Which alternative solutions or features have you considered?
Bind the arrays in every application
This works, but requires repeated infrastructure code and each application must define its own validation and missing-section behavior.
Create an application-specific extension
Applications can implement
AddSourcesFromConfigurationandAddMetersFromConfigurationthemselves. This duplicates the same behavior across services and organizations.Use zero-code auto-instrumentation environment variables
OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCESandOTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCESprovide similar functionality, but only for .NET automatic instrumentation. They do not configure an explicitly constructed OpenTelemetry SDK pipeline.Use OpenTelemetry declarative configuration
OpenTelemetry.Configuration.Declarativeis currently experimental and does not yet apply tracing-provider or metrics-provider configuration. Applications still need to callAddSourceandAddMeterin code.Use a third-party configuration package
Some third-party packages provide complete configuration-driven OpenTelemetry setup, but adopting an opinionated telemetry distribution is excessive when an application only needs to register source and meter names.
Additional context
This appears to fit
OpenTelemetry.Extensionsbecause it is a .NET-specific convenience aroundIConfiguration, rather than a new cross-language OpenTelemetry capability.Passing an explicit
IConfigurationSectionalso avoids defining configuration keys that could conflict with future OpenTelemetry declarative-configuration conventions.The proposed names are intended to distinguish these startup configuration helpers from the existing
AddSourceandAddMetermethods, but alternative naming consistent with repository conventions would be welcome.Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it. Learn more here.