|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 | 4 | using Microsoft.Extensions.Configuration;
|
| 5 | +using Microsoft.Extensions.DependencyInjection; |
| 6 | +using Microsoft.Extensions.Hosting; |
| 7 | +using Microsoft.Extensions.Options; |
| 8 | +using OpenTelemetry.Trace; |
5 | 9 | using Xunit;
|
6 | 10 |
|
7 | 11 | namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;
|
@@ -164,6 +168,44 @@ public void OtlpExporterOptions_SetterOverridesEnvironmentVariable()
|
164 | 168 | Assert.False(options.AppendSignalPathToEndpoint);
|
165 | 169 | }
|
166 | 170 |
|
| 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 | + |
167 | 209 | [Fact]
|
168 | 210 | public void OtlpExporterOptions_EndpointGetterUsesProtocolWhenNull()
|
169 | 211 | {
|
|
0 commit comments