-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADE…
…RS and OTEL_EXPORTER_OTLP_TIMEOUT env vars (#2188)
- Loading branch information
1 parent
89a0bce
commit 334689e
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// <copyright file="OtlpExporterOptionsTests.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using Xunit; | ||
|
||
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests | ||
{ | ||
public class OtlpExporterOptionsTests : IDisposable | ||
{ | ||
public OtlpExporterOptionsTests() | ||
{ | ||
ClearEnvVars(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
ClearEnvVars(); | ||
} | ||
|
||
[Fact] | ||
public void OtlpExporterOptions_Defaults() | ||
{ | ||
var options = new OtlpExporterOptions(); | ||
|
||
Assert.Equal(new Uri("http://localhost:4317"), options.Endpoint); | ||
Assert.Null(options.Headers); | ||
Assert.Equal(10000, options.TimeoutMilliseconds); | ||
} | ||
|
||
[Fact] | ||
public void OtlpExporterOptions_EnvironmentVariableOverride() | ||
{ | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.EndpointEnvVarName, "http://test:8888"); | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.HeadersEnvVarName, "A=2,B=3"); | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.TimeoutEnvVarName, "2000"); | ||
|
||
var options = new OtlpExporterOptions(); | ||
|
||
Assert.Equal(new Uri("http://test:8888"), options.Endpoint); | ||
Assert.Equal("A=2,B=3", options.Headers); | ||
Assert.Equal(2000, options.TimeoutMilliseconds); | ||
} | ||
|
||
[Fact] | ||
public void OtlpExporterOptions_InvalidEndpointVariableOverride() | ||
{ | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.EndpointEnvVarName, "invalid"); | ||
|
||
var options = new OtlpExporterOptions(); | ||
|
||
Assert.Equal(new Uri("http://localhost:4317"), options.Endpoint); // use default | ||
} | ||
|
||
[Fact] | ||
public void OtlpExporterOptions_InvalidTimeoutVariableOverride() | ||
{ | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.TimeoutEnvVarName, "invalid"); | ||
|
||
var options = new OtlpExporterOptions(); | ||
|
||
Assert.Equal(10000, options.TimeoutMilliseconds); // use default | ||
} | ||
|
||
[Fact] | ||
public void OtlpExporterOptions_SetterOverridesEnvironmentVariable() | ||
{ | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.EndpointEnvVarName, "http://test:8888"); | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.HeadersEnvVarName, "A=2,B=3"); | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.TimeoutEnvVarName, "2000"); | ||
|
||
var options = new OtlpExporterOptions | ||
{ | ||
Endpoint = new Uri("http://localhost:200"), | ||
Headers = "C=3", | ||
TimeoutMilliseconds = 40000, | ||
}; | ||
|
||
Assert.Equal(new Uri("http://localhost:200"), options.Endpoint); | ||
Assert.Equal("C=3", options.Headers); | ||
Assert.Equal(40000, options.TimeoutMilliseconds); | ||
} | ||
|
||
[Fact] | ||
public void OtlpExporterOptions_EnvironmentVariableNames() | ||
{ | ||
Assert.Equal("OTEL_EXPORTER_OTLP_ENDPOINT", OtlpExporterOptions.EndpointEnvVarName); | ||
Assert.Equal("OTEL_EXPORTER_OTLP_HEADERS", OtlpExporterOptions.HeadersEnvVarName); | ||
Assert.Equal("OTEL_EXPORTER_OTLP_TIMEOUT", OtlpExporterOptions.TimeoutEnvVarName); | ||
} | ||
|
||
private static void ClearEnvVars() | ||
{ | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.EndpointEnvVarName, null); | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.HeadersEnvVarName, null); | ||
Environment.SetEnvironmentVariable(OtlpExporterOptions.TimeoutEnvVarName, null); | ||
} | ||
} | ||
} |