-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for OTEL_BSP_EXPORT_* environmental variables #2219
Merged
cijothomas
merged 19 commits into
open-telemetry:main
from
pellared:support-OTEL_BSP-env-vars
Sep 3, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6b2bb13
Add support for OTEL_BSP_EXPORT_* environmental variables
pellared 2ce1898
Handle errors
pellared 29e5f22
Update docs
pellared e2932be
Fix typo
pellared 84dab4e
Merge branch 'main' into support-OTEL_BSP-env-vars
cijothomas 36bffaa
Merge branch 'main' into support-OTEL_BSP-env-vars
cijothomas f679a64
Refactor BatchExportProcessorOptions
pellared b421b3d
Refactor
pellared 4625407
Merge branch 'main' into support-OTEL_BSP-env-vars
pellared 092ddea
Introduce BatchSpanExportProcessorOptions
pellared 8315017
Fix typo
pellared 188173d
Merge branch 'main' into support-OTEL_BSP-env-vars
pellared 7dfb935
Rename to BatchExportActivityProcessorOptions
pellared 917fd8d
Rename in usages
pellared 018b6a4
Update public API
pellared 864c113
Merge branch 'main' into support-OTEL_BSP-env-vars
pellared f737915
Merge branch 'main' into support-OTEL_BSP-env-vars
cijothomas c14094a
Merge branch 'main' into support-OTEL_BSP-env-vars
cijothomas ceae91e
Merge branch 'main' into support-OTEL_BSP-env-vars
cijothomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,2 @@ | ||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions | ||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions() -> void |
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,2 @@ | ||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions | ||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions() -> void |
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
91 changes: 91 additions & 0 deletions
91
src/OpenTelemetry/Trace/BatchExportActivityProcessorOptions.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,91 @@ | ||
// <copyright file="BatchExportActivityProcessorOptions.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 System.Diagnostics; | ||
using System.Security; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
public class BatchExportActivityProcessorOptions : BatchExportProcessorOptions<Activity> | ||
pellared marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
internal const string MaxQueueSizeEnvVarKey = "OTEL_BSP_MAX_QUEUE_SIZE"; | ||
|
||
internal const string MaxExportBatchSizeEnvVarKey = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE"; | ||
|
||
internal const string ExporterTimeoutEnvVarKey = "OTEL_BSP_EXPORT_TIMEOUT"; | ||
|
||
internal const string ScheduledDelayEnvVarKey = "OTEL_BSP_SCHEDULE_DELAY"; | ||
|
||
public BatchExportActivityProcessorOptions() | ||
{ | ||
int value; | ||
|
||
if (TryLoadEnvVarInt(ExporterTimeoutEnvVarKey, out value)) | ||
{ | ||
this.ExporterTimeoutMilliseconds = value; | ||
} | ||
|
||
if (TryLoadEnvVarInt(MaxExportBatchSizeEnvVarKey, out value)) | ||
{ | ||
this.MaxExportBatchSize = value; | ||
} | ||
|
||
if (TryLoadEnvVarInt(MaxQueueSizeEnvVarKey, out value)) | ||
{ | ||
this.MaxQueueSize = value; | ||
} | ||
|
||
if (TryLoadEnvVarInt(ScheduledDelayEnvVarKey, out value)) | ||
{ | ||
this.ScheduledDelayMilliseconds = value; | ||
} | ||
} | ||
|
||
private static bool TryLoadEnvVarInt(string envVarKey, out int result) | ||
{ | ||
result = 0; | ||
|
||
string value; | ||
try | ||
{ | ||
value = Environment.GetEnvironmentVariable(envVarKey); | ||
} | ||
catch (SecurityException ex) | ||
{ | ||
// The caller does not have the required permission to | ||
// retrieve the value of an environment variable from the current process. | ||
OpenTelemetrySdkEventSource.Log.MissingPermissionsToReadEnvironmentVariable(ex); | ||
return false; | ||
} | ||
|
||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!int.TryParse(value, out var parsedValue)) | ||
{ | ||
OpenTelemetrySdkEventSource.Log.FailedToParseEnvironmentVariable(envVarKey, value); | ||
return false; | ||
} | ||
|
||
result = parsedValue; | ||
return true; | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
test/OpenTelemetry.Tests/Trace/BatchExportActivityProcessorOptionsTest.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,101 @@ | ||
// <copyright file="BatchExportActivityProcessorOptionsTest.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.Trace.Tests | ||
{ | ||
public class BatchExportActivityProcessorOptionsTest : IDisposable | ||
{ | ||
public BatchExportActivityProcessorOptionsTest() | ||
{ | ||
this.ClearEnvVars(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.ClearEnvVars(); | ||
} | ||
|
||
[Fact] | ||
public void BatchExportProcessorOptions_Defaults() | ||
{ | ||
var options = new BatchExportActivityProcessorOptions(); | ||
|
||
Assert.Equal(30000, options.ExporterTimeoutMilliseconds); | ||
Assert.Equal(512, options.MaxExportBatchSize); | ||
Assert.Equal(2048, options.MaxQueueSize); | ||
Assert.Equal(5000, options.ScheduledDelayMilliseconds); | ||
} | ||
|
||
[Fact] | ||
public void BatchExportProcessorOptions_EnvironmentVariableOverride() | ||
{ | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.ExporterTimeoutEnvVarKey, "1"); | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.MaxExportBatchSizeEnvVarKey, "2"); | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.MaxQueueSizeEnvVarKey, "3"); | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.ScheduledDelayEnvVarKey, "4"); | ||
|
||
var options = new BatchExportActivityProcessorOptions(); | ||
|
||
Assert.Equal(1, options.ExporterTimeoutMilliseconds); | ||
Assert.Equal(2, options.MaxExportBatchSize); | ||
Assert.Equal(3, options.MaxQueueSize); | ||
Assert.Equal(4, options.ScheduledDelayMilliseconds); | ||
} | ||
|
||
[Fact] | ||
public void BatchExportProcessorOptions_InvalidPortEnvironmentVariableOverride() | ||
{ | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.ExporterTimeoutEnvVarKey, "invalid"); | ||
|
||
var options = new BatchExportActivityProcessorOptions(); | ||
|
||
Assert.Equal(30000, options.ExporterTimeoutMilliseconds); // use default | ||
} | ||
|
||
[Fact] | ||
public void BatchExportProcessorOptions_SetterOverridesEnvironmentVariable() | ||
{ | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.ExporterTimeoutEnvVarKey, "123"); | ||
|
||
var options = new BatchExportActivityProcessorOptions | ||
{ | ||
ExporterTimeoutMilliseconds = 89000, | ||
}; | ||
|
||
Assert.Equal(89000, options.ExporterTimeoutMilliseconds); | ||
} | ||
|
||
[Fact] | ||
public void BatchExportProcessorOptions_EnvironmentVariableNames() | ||
{ | ||
Assert.Equal("OTEL_BSP_EXPORT_TIMEOUT", BatchExportActivityProcessorOptions.ExporterTimeoutEnvVarKey); | ||
Assert.Equal("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", BatchExportActivityProcessorOptions.MaxExportBatchSizeEnvVarKey); | ||
Assert.Equal("OTEL_BSP_MAX_QUEUE_SIZE", BatchExportActivityProcessorOptions.MaxQueueSizeEnvVarKey); | ||
Assert.Equal("OTEL_BSP_SCHEDULE_DELAY", BatchExportActivityProcessorOptions.ScheduledDelayEnvVarKey); | ||
} | ||
|
||
private void ClearEnvVars() | ||
{ | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.ExporterTimeoutEnvVarKey, null); | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.MaxExportBatchSizeEnvVarKey, null); | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.MaxQueueSizeEnvVarKey, null); | ||
Environment.SetEnvironmentVariable(BatchExportActivityProcessorOptions.ScheduledDelayEnvVarKey, null); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be a good idea to call out that this env variables affect all exporters unless individually overridden in code.