Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private static void RegisterOtlpExporterServices(IServiceCollection services, st

services.RegisterOptionsFactory((sp, configuration, name) => new OtlpExporterBuilderOptions(
configuration,
sp.GetRequiredService<IOptionsMonitor<OtlpExporterOptions>>().Get(name),
/* Note: We don't use name for SdkLimitOptions. There should only be
one provider for a given service collection so SdkLimitOptions is
treated as a single default instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ internal sealed class OtlpExporterBuilderOptions

internal OtlpExporterBuilderOptions(
IConfiguration configuration,
OtlpExporterOptions defaultOptions,
SdkLimitOptions sdkLimitOptions,
ExperimentalOptions experimentalOptions,
LogRecordExportProcessorOptions? logRecordExportProcessorOptions,
MetricReaderOptions? metricReaderOptions,
ActivityExportProcessorOptions? activityExportProcessorOptions)
{
Debug.Assert(configuration != null, "configuration was null");
Debug.Assert(defaultOptions != null, "defaultOptions was null");
Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null");
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");

Expand All @@ -43,7 +45,7 @@ internal OtlpExporterBuilderOptions(

var defaultBatchOptions = this.ActivityExportProcessorOptions!.BatchExportProcessorOptions;

this.DefaultOptionsInstance = new OtlpExporterOptions(configuration!, OtlpExporterOptionsConfigurationType.Default, defaultBatchOptions);
this.DefaultOptionsInstance = defaultOptions!;

this.LoggingOptionsInstance = new OtlpExporterOptions(configuration!, OtlpExporterOptionsConfigurationType.Logs, defaultBatchOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Notes](../../RELEASENOTES.md).

## Unreleased

* Fixed `UseOtlpExporter` to respect options configured through
`services.Configure<OtlpExporterOptions>(...)`.
([#7540](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7540))

## 1.17.0

Released 2026-Jul-16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ public void UseOtlpExporterDefaultTest()
Assert.False(((OtlpExporterOptions)exporterOptions.TracingOptions).HasData);
}

[Fact]
public void UseOtlpExporterRespectsConfiguredOtlpExporterOptionsTest()
{
var services = new ServiceCollection();
var configuredEndpoint = new Uri("http://configured_endpoint/");

services.Configure<OtlpExporterOptions>(options => options.Endpoint = configuredEndpoint);
services.AddOpenTelemetry()
.UseOtlpExporter();

using var sp = services.BuildServiceProvider();

Assert.NotNull(sp.GetRequiredService<LoggerProvider>());
Assert.NotNull(sp.GetRequiredService<MeterProvider>());
Assert.NotNull(sp.GetRequiredService<TracerProvider>());

var exporterOptions = sp.GetRequiredService<IOptionsMonitor<OtlpExporterBuilderOptions>>().CurrentValue;

Assert.Equal(configuredEndpoint, exporterOptions.DefaultOptions.Endpoint);
Assert.Equal(configuredEndpoint, exporterOptions.LoggingOptions.Endpoint);
Assert.Equal(configuredEndpoint, exporterOptions.MetricsOptions.Endpoint);
Assert.Equal(configuredEndpoint, exporterOptions.TracingOptions.Endpoint);
}

[Theory]
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
[InlineData(OtlpExportProtocol.Grpc)]
Expand Down