diff --git a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md index 740395daa8c..d859a7da58e 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +* `JaegerExporterOptions.BatchExportProcessorOptions` is initalized with + `BatchSpanExportProcessorOptions` which supports field value overriding + using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, + `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` + envionmental variables as defined in the + [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor). + ([#2219](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2219)) + ## 1.2.0-alpha1 Released 2021-Jul-23 diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs index ed87beb5926..054c5f28555 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs @@ -18,6 +18,7 @@ using System.Diagnostics; using System.Security; using OpenTelemetry.Exporter.Jaeger.Implementation; +using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter { @@ -82,6 +83,6 @@ public JaegerExporterOptions() /// /// Gets or sets the BatchExportProcessor options. Ignored unless ExportProcessorType is BatchExporter. /// - public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchExportProcessorOptions(); + public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions(); } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index c464714f603..aa4a1b7251e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +* `OtlpExporterOptions.BatchExportProcessorOptions` is initalized with + `BatchSpanExportProcessorOptions` which supports field value overriding + using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, + `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` + envionmental variables as defined in the + [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor). + ([#2219](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2219)) + * The `OtlpExporterOptions` defaults can be overridden using `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_TIMEOUT` envionmental variables as defined in the diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs index f112e76a773..42eb21881bf 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs @@ -18,6 +18,7 @@ using System.Diagnostics; using System.Security; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; +using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter { @@ -104,7 +105,7 @@ public OtlpExporterOptions() /// /// Gets or sets the BatchExportProcessor options. Ignored unless ExportProcessorType is Batch. /// - public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchExportProcessorOptions(); + public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions(); /// /// Gets or sets the metric export interval in milliseconds. The default value is 1000 milliseconds. diff --git a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md index 1e1dac0d3ff..1f12beefa5a 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +* `ZipkinExporterOptions.BatchExportProcessorOptions` is initalized with + `BatchSpanExportProcessorOptions` which supports field value overriding + using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, + `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` + envionmental variables as defined in the + [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor). + ([#2219](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2219)) + * Enabling endpoint configuration in ZipkinExporterOptions via `OTEL_EXPORTER_ZIPKIN_ENDPOINT` environment variable. ([#1453](https://github.com/open-telemetry/opentelemetry-dotnet/issues/1453)) diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs index 21df9181fd7..76b23a92ad9 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs @@ -17,6 +17,7 @@ using System; using System.Diagnostics; using OpenTelemetry.Exporter.Zipkin.Implementation; +using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter { @@ -70,6 +71,6 @@ public ZipkinExporterOptions() /// /// Gets or sets the BatchExportProcessor options. Ignored unless ExportProcessorType is BatchExporter. /// - public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchExportProcessorOptions(); + public BatchExportProcessorOptions BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions(); } } diff --git a/src/OpenTelemetry/BatchExportProcessorOptions.cs b/src/OpenTelemetry/BatchExportProcessorOptions.cs index 75f93a3c6df..90abda8abbb 100644 --- a/src/OpenTelemetry/BatchExportProcessorOptions.cs +++ b/src/OpenTelemetry/BatchExportProcessorOptions.cs @@ -14,48 +14,11 @@ // limitations under the License. // -using System; -using System.Security; -using OpenTelemetry.Internal; - namespace OpenTelemetry { public class BatchExportProcessorOptions where T : class { - 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 BatchExportProcessorOptions() - { - 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; - } - } - /// /// Gets or sets the maximum queue size. The queue drops the data if the maximum size is reached. The default value is 2048. /// @@ -75,37 +38,5 @@ public BatchExportProcessorOptions() /// Gets or sets the maximum batch size of every export. It must be smaller or equal to MaxQueueLength. The default value is 512. /// public int MaxExportBatchSize { get; set; } = BatchExportProcessor.DefaultMaxExportBatchSize; - - 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; - } } } diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 2a3f5078d08..e792960eb2b 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -2,8 +2,8 @@ ## Unreleased -* The `BatchExportProcessorOptions` defaults can be overridden using - `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, +* Add `BatchSpanExportProcessorOptions` which supports field value overriding + using `OTEL_BSP_SCHEDULE_DELAY`, `OTEL_BSP_EXPORT_TIMEOUT`, `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` envionmental variables as defined in the [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/sdk-environment-variables.md#batch-span-processor). diff --git a/src/OpenTelemetry/README.md b/src/OpenTelemetry/README.md index 4dbd9085c6f..1d667199fa1 100644 --- a/src/OpenTelemetry/README.md +++ b/src/OpenTelemetry/README.md @@ -204,10 +204,10 @@ purposes, the SDK provides the following built-in processors: the configured exporter. The following environment variables can be used to override the default - values of the `BatchExportProcessorOptions`. + values of the `BatchSpanExportProcessorOptions`. - | Environment variable | `BatchExportProcessorOptions` property | + | Environment variable | `BatchSpanExportProcessorOptions` property | | -------------------------------- | ---------------------------------------------- | | `OTEL_BSP_SCHEDULE_DELAY` | `ScheduledDelayMilliseconds` | | `OTEL_BSP_EXPORT_TIMEOUT` | `ExporterTimeoutMilliseconds` | diff --git a/src/OpenTelemetry/Trace/BatchSpanExportProcessorOptions.cs b/src/OpenTelemetry/Trace/BatchSpanExportProcessorOptions.cs new file mode 100644 index 00000000000..1c155eda12c --- /dev/null +++ b/src/OpenTelemetry/Trace/BatchSpanExportProcessorOptions.cs @@ -0,0 +1,91 @@ +// +// 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. +// + +using System; +using System.Diagnostics; +using System.Security; +using OpenTelemetry.Internal; + +namespace OpenTelemetry.Trace +{ + public class BatchSpanExportProcessorOptions : BatchExportProcessorOptions + { + 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 BatchSpanExportProcessorOptions() + { + 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; + } + } +} diff --git a/test/OpenTelemetry.Tests/Trace/BatchExportProcessorOptionsTest.cs b/test/OpenTelemetry.Tests/Trace/BatchSpanExportProcessorOptionsTest.cs similarity index 51% rename from test/OpenTelemetry.Tests/Trace/BatchExportProcessorOptionsTest.cs rename to test/OpenTelemetry.Tests/Trace/BatchSpanExportProcessorOptionsTest.cs index d4a038783b6..073b9ca3c69 100644 --- a/test/OpenTelemetry.Tests/Trace/BatchExportProcessorOptionsTest.cs +++ b/test/OpenTelemetry.Tests/Trace/BatchSpanExportProcessorOptionsTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,11 @@ using System; using Xunit; -using Options = OpenTelemetry.BatchExportProcessorOptions; - namespace OpenTelemetry.Trace.Tests { - public class BatchExportProcessorOptionsTest : IDisposable + public class BatchSpanExportProcessorOptionsTest : IDisposable { - public BatchExportProcessorOptionsTest() + public BatchSpanExportProcessorOptionsTest() { this.ClearEnvVars(); } @@ -36,7 +34,7 @@ public void Dispose() [Fact] public void BatchExportProcessorOptions_Defaults() { - var options = new Options(); + var options = new BatchSpanExportProcessorOptions(); Assert.Equal(30000, options.ExporterTimeoutMilliseconds); Assert.Equal(512, options.MaxExportBatchSize); @@ -47,12 +45,12 @@ public void BatchExportProcessorOptions_Defaults() [Fact] public void BatchExportProcessorOptions_EnvironmentVariableOverride() { - Environment.SetEnvironmentVariable(Options.ExporterTimeoutEnvVarKey, "1"); - Environment.SetEnvironmentVariable(Options.MaxExportBatchSizeEnvVarKey, "2"); - Environment.SetEnvironmentVariable(Options.MaxQueueSizeEnvVarKey, "3"); - Environment.SetEnvironmentVariable(Options.ScheduledDelayEnvVarKey, "4"); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, "1"); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxExportBatchSizeEnvVarKey, "2"); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxQueueSizeEnvVarKey, "3"); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ScheduledDelayEnvVarKey, "4"); - var options = new BatchExportProcessorOptions(); + var options = new BatchSpanExportProcessorOptions(); Assert.Equal(1, options.ExporterTimeoutMilliseconds); Assert.Equal(2, options.MaxExportBatchSize); @@ -63,9 +61,9 @@ public void BatchExportProcessorOptions_EnvironmentVariableOverride() [Fact] public void BatchExportProcessorOptions_InvalidPortEnvironmentVariableOverride() { - Environment.SetEnvironmentVariable(BatchExportProcessorOptions.ExporterTimeoutEnvVarKey, "invalid"); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, "invalid"); - var options = new Options(); + var options = new BatchSpanExportProcessorOptions(); Assert.Equal(30000, options.ExporterTimeoutMilliseconds); // use default } @@ -73,9 +71,9 @@ public void BatchExportProcessorOptions_InvalidPortEnvironmentVariableOverride() [Fact] public void BatchExportProcessorOptions_SetterOverridesEnvironmentVariable() { - Environment.SetEnvironmentVariable(BatchExportProcessorOptions.ExporterTimeoutEnvVarKey, "123"); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, "123"); - var options = new Options + var options = new BatchSpanExportProcessorOptions { ExporterTimeoutMilliseconds = 89000, }; @@ -86,18 +84,18 @@ public void BatchExportProcessorOptions_SetterOverridesEnvironmentVariable() [Fact] public void BatchExportProcessorOptions_EnvironmentVariableNames() { - Assert.Equal("OTEL_BSP_EXPORT_TIMEOUT", Options.ExporterTimeoutEnvVarKey); - Assert.Equal("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", Options.MaxExportBatchSizeEnvVarKey); - Assert.Equal("OTEL_BSP_MAX_QUEUE_SIZE", Options.MaxQueueSizeEnvVarKey); - Assert.Equal("OTEL_BSP_SCHEDULE_DELAY", Options.ScheduledDelayEnvVarKey); + Assert.Equal("OTEL_BSP_EXPORT_TIMEOUT", BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey); + Assert.Equal("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", BatchSpanExportProcessorOptions.MaxExportBatchSizeEnvVarKey); + Assert.Equal("OTEL_BSP_MAX_QUEUE_SIZE", BatchSpanExportProcessorOptions.MaxQueueSizeEnvVarKey); + Assert.Equal("OTEL_BSP_SCHEDULE_DELAY", BatchSpanExportProcessorOptions.ScheduledDelayEnvVarKey); } private void ClearEnvVars() { - Environment.SetEnvironmentVariable(Options.ExporterTimeoutEnvVarKey, null); - Environment.SetEnvironmentVariable(Options.MaxExportBatchSizeEnvVarKey, null); - Environment.SetEnvironmentVariable(Options.MaxQueueSizeEnvVarKey, null); - Environment.SetEnvironmentVariable(Options.ScheduledDelayEnvVarKey, null); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ExporterTimeoutEnvVarKey, null); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxExportBatchSizeEnvVarKey, null); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.MaxQueueSizeEnvVarKey, null); + Environment.SetEnvironmentVariable(BatchSpanExportProcessorOptions.ScheduledDelayEnvVarKey, null); } } }