Skip to content

Commit cf0194f

Browse files
committed
add failing test regarding #6558
1 parent 6a70665 commit cf0194f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Hosting;
7+
using Microsoft.Extensions.Options;
8+
using OpenTelemetry.Trace;
59
using Xunit;
610

711
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;
@@ -164,6 +168,44 @@ public void OtlpExporterOptions_SetterOverridesEnvironmentVariable()
164168
Assert.False(options.AppendSignalPathToEndpoint);
165169
}
166170

171+
// https://github.com/open-telemetry/opentelemetry-dotnet/issues/6558
172+
[Fact]
173+
public void OtlpExporterOptions_EnvironmentVariableAppliedBeforeIConfigurationBuilt()
174+
{
175+
var expectedEndpoint = "http://test:4317";
176+
var host = Host
177+
.CreateDefaultBuilder()
178+
.ConfigureServices((_, services) =>
179+
{
180+
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", expectedEndpoint);
181+
services
182+
.AddOpenTelemetry()
183+
.WithTracing(builder => builder.AddOtlpExporter());
184+
})
185+
.Build();
186+
187+
var options = host.Services.GetRequiredService<IOptions<OtlpExporterOptions>>().Value;
188+
189+
Assert.Equal(new Uri(expectedEndpoint), options.Endpoint);
190+
}
191+
192+
// https://github.com/open-telemetry/opentelemetry-dotnet/issues/5586
193+
[Fact]
194+
public void OtlpExporterOptions_EnvironmentVariableAppliedWhenEmptyApplication()
195+
{
196+
var expectedEndpoint = "http://test:4317";
197+
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", expectedEndpoint);
198+
var hostBuilder = Host.CreateEmptyApplicationBuilder(settings: null);
199+
hostBuilder.Services
200+
.AddOpenTelemetry()
201+
.WithTracing(builder => builder.AddOtlpExporter());
202+
var host = hostBuilder.Build();
203+
204+
var options = host.Services.GetRequiredService<IOptions<OtlpExporterOptions>>().Value;
205+
206+
Assert.Equal(new Uri(expectedEndpoint), options.Endpoint);
207+
}
208+
167209
[Fact]
168210
public void OtlpExporterOptions_EndpointGetterUsesProtocolWhenNull()
169211
{

0 commit comments

Comments
 (0)